Skip to main content
Conversation manages a running message history so you don’t have to track prior turns yourself. Create one via client.conversation() and call send() or stream() for each user turn. Both methods append the user message and the assistant response to messages automatically.
See GatelitClient.conversation() for the constructor details.

Options

string
required
Model in "provider/model-name" format. For example: "openai/gpt-4o".
string
Optional system prompt prepended to every request. Useful for setting a persona or task scope that persists across all turns.
number
Maximum output tokens per request.
number
Sampling temperature applied to every request in the conversation.

Properties

messages

The accumulated message history for this conversation. Each entry has a role ("system", "user", or "assistant") and a content string. Read-only — do not mutate this array directly. Use reset() to clear it.

Methods

send(content, signal?)

Sends a user message and returns the assistant’s full response. Appends both turns to messages.
string
required
The user’s message text.
AbortSignal
An optional AbortSignal to cancel the in-flight request.
Returns a ChatResponse — the same type returned by client.chat().

stream(content, signal?)

Sends a user message and streams the response. Appends the user turn immediately; the completed assistant turn is appended once the stream finishes.
string
required
The user’s message text.
AbortSignal
An optional AbortSignal to cancel the stream.
Yields StreamChunk values — the same type produced by client.stream().

reset()

Clears the conversation history. The next call to send() or stream() starts a fresh conversation.

Examples

Multi-turn conversation

Streaming conversation

Using a system prompt

Resetting between sessions

reset() clears messages entirely. If you want to preserve context across resets, copy conv.messages before calling reset().