Module: core/completion
This module provides the core completion components for AI.JSX.
Interfaces
Type Aliases
ModelComponent
Ƭ ModelComponent<T
>: Component
<T
>
A Component that invokes a Large Language Model.
Type parameters
Name | Type |
---|---|
T | extends ModelPropsWithChildren |
Defined in
packages/ai-jsx/src/core/completion.tsx:36
ModelPropsWithChildren
Ƭ ModelPropsWithChildren: ModelProps
& { children
: Node
}
Represents a ModelProps with child @{link Node}s.
Defined in
packages/ai-jsx/src/core/completion.tsx:29
Functions
AssistantMessage
▸ AssistantMessage(«destructured»
): Node
Provide an Assistant Message to the LLM, for use within a ChatCompletion.
The assistant message tells the model what it has previously said. See https://platform.openai.com/docs/guides/gpt/chat-completions-api for more detail.
Example
<ChatCompletion>
<UserMessage>I'd like to cancel my account.</UserMessage>
<AssistantMessage>Sorry to hear that. Can you tell me why?</AssistantMessage>
<UserMessage>It's too expensive.</UserMessage>
</ChatCompletion>
==> "Ok, thanks for that feedback. I'll cancel your account."
Parameters
Name | Type |
---|---|
«destructured» | Object |
› children | Node |
Returns
Defined in
packages/ai-jsx/src/core/completion.tsx:213
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
Name | Type |
---|---|
«destructured» | ModelProps & { children : Node } & Record <string , unknown > |
«destructured» | RenderContext |
Returns
Element
Defined in
packages/ai-jsx/src/core/completion.tsx:322
ChatProvider
▸ ChatProvider<T
>(«destructured»
, «destructured»
): Element
A ChatProvider is used by ChatCompletion to access an underlying Large Language Model.
Type parameters
Name | Type |
---|---|
T | extends ModelPropsWithChildren |
Parameters
Name | Type |
---|---|
«destructured» | { component? : ModelComponent <T > } & T |
«destructured» | RenderContext |
Returns
Element
Defined in
packages/ai-jsx/src/core/completion.tsx:146
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
Name | Type |
---|---|
«destructured» | ModelProps & { children : Node } & Record <string , unknown > |
«destructured» | RenderContext |
Returns
Element
Defined in
packages/ai-jsx/src/core/completion.tsx:293
CompletionProvider
▸ CompletionProvider<T
>(«destructured»
, «destructured»
): Element
A CompletionProvider is used by ChatCompletion to access an underlying Large Language Model.
Type parameters
Name | Type |
---|---|
T | extends ModelPropsWithChildren |
Parameters
Name | Type |
---|---|
«destructured» | { component? : ModelComponent <T > } & T |
«destructured» | RenderContext |
Returns
Element
Defined in
packages/ai-jsx/src/core/completion.tsx:123
ConversationHistory
▸ ConversationHistory(«destructured»
): Element
[]
Parameters
Name | Type |
---|---|
«destructured» | Object |
› messages | ChatCompletionResponseMessage [] |
Returns
Element
[]
Defined in
packages/ai-jsx/src/core/completion.tsx:217
FunctionCall
▸ FunctionCall(«destructured»
): string
Provide a function call to the LLM, for use within a ChatCompletion.
The function call tells the model that a function was previously invoked by the model. See https://platform.openai.com/docs/guides/gpt/chat-completions-api for more detail. When the model returns a function call, @{link ChatCompletion} returns a @{link FunctionCall} component.
Example
<ChatCompletion>
<UserMessage>What is 258 * 322?</UserMessage>
<FunctionCall name="evaluate_math" args={expression: "258 * 322"} />
<FunctionResponse name="evaluate_math">83076</FunctionResponse>
</ChatCompletion>
==> "That would be 83,076."
Parameters
Name | Type |
---|---|
«destructured» | Object |
› args | Record <string , null | string | number | boolean > |
› name | string |
Returns
string
Defined in
packages/ai-jsx/src/core/completion.tsx:251
FunctionResponse
▸ FunctionResponse(«destructured»
, «destructured»
): Promise
<string
>
Renders to the output of a previous FunctionCall component, for use within a ChatCompletion.
See https://platform.openai.com/docs/guides/gpt/chat-completions-api for more detail.
Example
<ChatCompletion>
<UserMessage>What is 258 * 322?</UserMessage>
<FunctionCall name="evaluate_math" args={expression: "258 * 322"} />
<FunctionResponse name="evaluate_math">83076</FunctionResponse>
</ChatCompletion>
==> "That would be 83,076."
Parameters
Name | Type |
---|---|
«destructured» | Object |
› children | Node |
› name | string |
«destructured» | ComponentContext |
Returns
Promise
<string
>
Defined in
packages/ai-jsx/src/core/completion.tsx:271
SystemMessage
▸ SystemMessage(«destructured»
): Node
Provide a System Message to the LLM, for use within a ChatCompletion.
The system message can be used to put the model in character. See https://platform.openai.com/docs/guides/gpt/chat-completions-api for more detail.
Example
<ChatCompletion>
<SystemMessage>You are a helpful customer service agent.</SystemMessage>
</ChatCompletion>
Parameters
Name | Type |
---|---|
«destructured» | Object |
› children | Node |
Returns
Defined in
packages/ai-jsx/src/core/completion.tsx:175
UserMessage
▸ UserMessage(«destructured»
): Node
Provide a User Message to the LLM, for use within a ChatCompletion.
The user message tells the model what the user has said. See https://platform.openai.com/docs/guides/gpt/chat-completions-api for more detail.
Example
<ChatCompletion>
<UserMessage>I'd like to cancel my account.</UserMessage>
</ChatCompletion>
==> 'Sorry to hear that. Can you tell me why?
Parameters
Name | Type |
---|---|
«destructured» | Object |
› children | Node |
› name? | string |