Przejdź do głównej zawartości

Streaming

Streaming pozwala agentowi wysylac odpowiedzi token po tokenie.

interface StreamSession {
delta(chunk: string): Promise<void>;
done(finalPayload: SendPayload): Promise<void>;
abort(): void;
}

Uzycie z OpenAI

agent.onMessage(async (msg) => {
const session = agent.stream(msg.conversation_id);
const stream = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: msg.content }],
stream: true,
});
let fullText = "";
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta?.content ?? "";
if (delta) { fullText += delta; await session.delta(delta); }
}
await session.done({ type: "text", content: fullText });
});

Limity

OgraniczenieWartosc
Maks. czas trwania5 minut
Timeout orphan30 sekund
Duze grupy (201-500)Streaming wylaczony

Nastepne kroki