function chat<TAdapter, TSchema, TStream>(options): TextActivityResult<TSchema, TStream>;
Defined in: activities/chat/index.ts:1196
Text activity - handles agentic text generation, one-shot text generation, and agentic structured output.
This activity supports four modes:
TAdapter extends AnyTextAdapter
TSchema extends SchemaInput | undefined = undefined
TStream extends boolean = true
TextActivityOptions<TAdapter, TSchema, TStream>
TextActivityResult<TSchema, TStream>
import { chat } from '@tanstack/ai'
import { openaiText } from '@tanstack/ai-openai'
for await (const chunk of chat({
adapter: openaiText('gpt-4o'),
messages: [{ role: 'user', content: 'What is the weather?' }],
tools: [weatherTool]
})) {
if (chunk.type === 'content') {
console.log(chunk.delta)
}
}
for await (const chunk of chat({
adapter: openaiText('gpt-4o'),
messages: [{ role: 'user', content: 'Hello!' }]
})) {
console.log(chunk)
}
const text = await chat({
adapter: openaiText('gpt-4o'),
messages: [{ role: 'user', content: 'Hello!' }],
stream: false
})
// text is a string with the full response
import { z } from 'zod'
const result = await chat({
adapter: openaiText('gpt-4o'),
messages: [{ role: 'user', content: 'Research and summarize the topic' }],
tools: [researchTool, analyzeTool],
outputSchema: z.object({
summary: z.string(),
keyPoints: z.array(z.string())
})
})
// result is { summary: string, keyPoints: string[] }