Unified AI
Chat Completion
Build a Piece
- Overview
- Start Building
- Fork Repository
- Development Environment
- Create Piece Definition
- Add Piece Authentication
- Create Action
- Create Trigger
- Sharing Pieces
Piece Reference
Unified AI
Chat Completion
Learn how to use chat completion AI in actions
The following snippet shows how to use chat completion to get a response from an AI model.
const ai = AI({ provider: context.propsValue.provider, server: context.server });
const response = await ai.chat.text({
model: context.propsValue.model,
messages: [
{
role: AIChatRole.USER,
content: "Can you provide examples of TypeScript code formatting?",
},
],
/**
* Controls the creativity of the AI response.
* A higher value will make the AI more creative and a lower value will make it more deterministic.
*/
creativity: 0.7,
/**
* The maximum number of tokens to generate in the completion.
*/
maxTokens: 100,
});