Saltar al contenido principal

Function: useChat()

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

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

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

Use this for review / questioning (single-shot). For autonomous multi-step work with tools, use useRunAgent.

Parameters

messages

AiMessage[]

Conversation messages (a system prompt is prepended if absent).

options?

AiChatOptions = {}

Optional completion options.

Returns

Promise<AiResult<string>>

A AiResult with the assistant text.

Example

import { useChat } from "katanakit-js";

const result = await useChat([
{ role: "user", content: "Summarize the benefits of solar energy in three bullet points." },
]);
if (result.ok) console.log(result.data);