Loading...
Skip to main content

Module: core/completion

This module provides the core completion components for AI.JSX.

Interfaces

References

AssistantMessage

Re-exports AssistantMessage


ConversationHistory

Re-exports ConversationHistory


FunctionCall

Re-exports FunctionCall


FunctionResponse

Re-exports FunctionResponse


SystemMessage

Re-exports SystemMessage


UserMessage

Re-exports UserMessage

Type Aliases

FunctionParameters

Ƭ FunctionParameters: Record<string, PlainFunctionParameter> | z.ZodObject<any>

Represents parameters to a FunctionDefinition.

This type allows two ways for specifying parameters:

  • For simple use cases, a record of parameter names to PlainFunctionParameter objects.
  • For more complex use cases, a z.ZodObject schema object (zod is a standard runtime type definition & checking library).

Note

If using a Zod schema, the top-level schema must be an object as per OpenAI specifications: https://platform.openai.com/docs/api-reference/chat/create#chat/create-parameters

For example, to describe a list of strings, the following is not accepted: const schema: z.Schema = z.array(z.string())

Instead, you can wrap it in an object like so: const schema: z.ZodObject = z.object({ arr: z.array(z.string()) })

Defined in

ai-jsx/src/core/completion.tsx:121


ModelComponent

Ƭ ModelComponent<T>: Component<T>

A Component that invokes a Large Language Model.

Type parameters

NameType
Textends ModelPropsWithChildren

Defined in

ai-jsx/src/core/completion.tsx:54


ModelPropsWithChildren

Ƭ ModelPropsWithChildren: ModelProps & { children: Node }

Represents a ModelProps with child @{link Node}s.

Defined in

ai-jsx/src/core/completion.tsx:47

Functions

ChatCompletion

ChatCompletion(«destructured», «destructured»): Element

Perform a Large Language Model call to do chat completion.

Every child of ChatCompletion must something that renders to a SystemMessage, UserMessage, or AssistantMessage.

Example

   function MyUserMessage() {
return <UserMessage>Hi, I'm a user message.</UserMessage>;
}

<ChatCompletion>
<SystemMessage>You are a nice person.</SystemMessage>
<MyUserMessage />
</ChatCompletion>

Parameters

NameType
«destructured»ModelProps & { children: Node } & Record<string, unknown>
«destructured»RenderContext

Returns

Element

Defined in

ai-jsx/src/core/completion.tsx:274


ChatProvider

ChatProvider<T>(«destructured», «destructured»): Element

A ChatProvider is used by ChatCompletion to access an underlying Large Language Model.

Type parameters

NameType
Textends ModelPropsWithChildren

Parameters

NameType
«destructured»{ component?: ModelComponent<T> } & T
«destructured»RenderContext

Returns

Element

Defined in

ai-jsx/src/core/completion.tsx:214


Completion

Completion(«destructured», «destructured»): Element

Perform a Large Language Mokdel call to do a completion.

In general, you should prefer to use ChatCompletion instead of Completion, because ChatCompletion uses better models.

Example

   <Completion>
Here's a list of three dog names:
</Completion>

==> 'Dottie, Murphy, Lucy'

Parameters

NameType
«destructured»ModelProps & { children: Node } & Record<string, unknown>
«destructured»RenderContext

Returns

Element

Defined in

ai-jsx/src/core/completion.tsx:245


CompletionProvider

CompletionProvider<T>(«destructured», «destructured»): Element

A CompletionProvider is used by ChatCompletion to access an underlying Large Language Model.

Type parameters

NameType
Textends ModelPropsWithChildren

Parameters

NameType
«destructured»{ component?: ModelComponent<T> } & T
«destructured»RenderContext

Returns

Element

Defined in

ai-jsx/src/core/completion.tsx:191


getParametersSchema

getParametersSchema(parameters): JsonSchema7Meta & {} | { properties: {} ; required: string[] ; type: string = 'object' }

This function creates a JSON Schema object to describe parameters for a FunctionDefinition.

See FunctionParameters for more information on what parameters are supported.

Parameters

NameType
parametersFunctionParameters

Returns

JsonSchema7Meta & {} | { properties: {} ; required: string[] ; type: string = 'object' }

Defined in

ai-jsx/src/core/completion.tsx:70