Skip to content
0

katanakit-js / useChat

Function: useChat() ​

ts
function useChat(messages, options?): Promise<AiResult<string>>;

Defined in: src/core/services/agent.service.ts:537

Sends a single chat completion and returns the assistant text as a Safe Result.

Parameters ​

ParameterTypeDescription
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).
optionsAiChatOptionsOptional completion options.

Returns ​

Promise<AiResult<string>>

An AiResult with the assistant text.

Example ​

ts
import { useChat } from "katanakit-js";

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

Released under the MIT License.