Skip to content

UseChat

katanakit-js / 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.

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.

Promise<AiResult<string>>

An AiResult with the assistant text.

import { useChat } from "katanakit-js";
const result = await useChat([{ role: "user", content: "Hello" }]);
if (result.ok) console.log(result.data);