Skip to content

@ralphschuler.ai function caller.index.AIFunctionCaller

github-actions edited this page Nov 26, 2023 · 1 revision

Class: AIFunctionCaller

@ralphschuler/ai-function-caller.index.AIFunctionCaller

A class for calling AI functions and managing interactions.

Example

import { AIFunctionCaller } from "@withorbit/ai-function-caller";
import { AIFunction } from "@withorbit/ai-function-caller";

const functions: AIFunction<any>[] = [
 {
  name: "add",
  method: async (args: any) => {
  return args.a + args.b;
 }
];

const aiFunctionCaller = new AIFunctionCaller(functions);
const response = await aiFunctionCaller.query("What is 2 + 2?");
console.log(response); // 4

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new AIFunctionCaller(functions, initialMessages?): AIFunctionCaller

Constructs an AIFunctionCaller instance.

Parameters

Name Type Default value Description
functions AIFunction<any>[] undefined Array of AI functions.
initialMessages Message[] [] Initial set of messages, defaults to an empty array.

Returns

AIFunctionCaller

Defined in

packages/ai-function-caller/src/index.ts:40

Properties

functions

functions: AIFunction<any>[]

Defined in

packages/ai-function-caller/src/index.ts:32


messages

messages: Message[] = []

Defined in

packages/ai-function-caller/src/index.ts:31


openai

Private openai: OpenAI

Defined in

packages/ai-function-caller/src/index.ts:33

Methods

executeAIModel

executeAIModel(): Promise<string | AIFunctionCall>

Executes the AI model and returns the response.

Returns

Promise<string | AIFunctionCall>

A Promise resolving to MessageContent or AIFunctionCall.

Defined in

packages/ai-function-caller/src/index.ts:59


logMessage

logMessage(message): void

Logs a message to the message array.

Parameters

Name Type Description
message Message The message to log.

Returns

void

Example

Defined in

packages/ai-function-caller/src/index.ts:51


processAiFunctionCall

processAiFunctionCall(aiFunctionCall): Promise<string | AIFunctionCall>

Processes an AI function call and returns the response.

Parameters

Name Type Description
aiFunctionCall AIFunctionCall The AI function call to process.

Returns

Promise<string | AIFunctionCall>

A Promise resolving to MessageContent or AIFunctionCall.

Defined in

packages/ai-function-caller/src/index.ts:74


processMessage

processMessage(sender, role, content): Promise<string | AIFunctionCall>

Processes a message, logs it, and returns the AI model's response.

Parameters

Name Type Description
sender string The sender of the message.
role MessageRole The role of the message sender.
content string | AIFunctionCall The content of the message.

Returns

Promise<string | AIFunctionCall>

A Promise resolving to MessageContent or AIFunctionCall.

Defined in

packages/ai-function-caller/src/index.ts:96


query

query(userMessage): Promise<any>

Processes a user query and returns the response.

Parameters

Name Type Description
userMessage string The user message to process.

Returns

Promise<any>

A Promise resolving to the response.

Example

const response = await aiFunctionCaller.query("What is 2 + 2?");
console.log(response); // 4

Defined in

packages/ai-function-caller/src/index.ts:121

Typescript Libraries

Modules

Namespaces

Clone this wiki locally