MCPcopy Create free account
hub / github.com/TanStack/ai / createChatStream

Function createChatStream

examples/ts-react-native-chat/src/server/app.ts:353–376  ·  view source on GitHub ↗
(
  body: unknown,
)

Source from the content-addressed store, hash-verified

351]
352
353async function createChatStream(
354 body: unknown,
355): Promise<AsyncIterable<StreamChunk>> {
356 const params = await chatParamsFromRequestBody(body)
357 const recipePrompt = createRecipePrompt(params.messages)
358 requireOpenAIApiKey()
359 const model = getOpenAIModel()
360 const tools = mergeAgentTools(serverTools, params.tools)
361 const modelOptions = getOpenAIModelOptions(model)
362
363 return chat({
364 adapter: openaiText(model),
365 tools,
366 messages: recipePrompt.messages,
367 systemPrompts: recipePrompt.systemPrompts,
368 threadId: params.threadId,
369 runId: params.runId,
370 parentRunId: params.parentRunId,
371 agentLoopStrategy: maxIterations(6),
372 outputSchema: recipeOutputSchema,
373 stream: true,
374 ...(modelOptions ? { modelOptions: modelOptions as never } : {}),
375 }) as AsyncIterable<StreamChunk>
376}
377
378function getErrorMessage(error: unknown): string {
379 return error instanceof Error ? error.message : 'Bad request'

Callers 1

app.tsFile · 0.85

Calls 9

mergeAgentToolsFunction · 0.90
chatFunction · 0.90
openaiTextFunction · 0.90
maxIterationsFunction · 0.90
createRecipePromptFunction · 0.85
requireOpenAIApiKeyFunction · 0.85
getOpenAIModelFunction · 0.85
getOpenAIModelOptionsFunction · 0.85

Tested by

no test coverage detected