UseChat
katanakit-js / useChat
Function: useChat()
Section titled “Function: useChat()”function useChat(messages, options?): Promise<AiResult<string>>;Defined in: core/services/agent.service.ts:537
Sends a single chat completion and returns the assistant text as a Safe Result.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
messages |
{ content: string | null; name?: string; role: "system" | "user" | "assistant" | "tool"; tool_call_id?: string; tool_calls?: { function: { arguments: string; name: string; }; id: string; type: "function"; }[]; }[] |
Conversation messages (a system prompt is prepended if absent). |
options? |
AiChatOptions |
Optional completion options. |
Returns
Section titled “Returns”Promise<AiResult<string>>
An AiResult with the assistant text.
Example
Section titled “Example”import { useChat } from "katanakit-js";
const result = await useChat([{ role: "user", content: "Hello" }]);if (result.ok) console.log(result.data);