MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / processLlmResponse

Function processLlmResponse

packages/baseai/src/dev/routes/beta/pipes/run.ts:65–92  ·  view source on GitHub ↗
(c: any, body: RequestBody, rawLlmResponse: any)

Source from the content-addressed store, hash-verified

63};
64
65const processLlmResponse = (c: any, body: RequestBody, rawLlmResponse: any) => {
66 const isStreaming = body.stream;
67
68 // Non-streaming
69 if (!isStreaming && rawLlmResponse?.choices?.length > 0) {
70 const completion = rawLlmResponse.choices[0]?.message?.content ?? '';
71 const toolCalls = rawLlmResponse.choices[0]?.message?.tool_calls ?? [];
72 const isToolCall = toolCalls.length > 0;
73
74 logger('tool', isToolCall, 'Tool calls found');
75 logger('tool.calls', toolCalls);
76 logger('pipe.completion', completion, 'Pipe completion');
77 logger('pipe.response', rawLlmResponse, 'type: (non-streaming)');
78
79 return c.json({ completion, ...rawLlmResponse });
80 }
81
82 // Streaming
83 if (isStreaming) {
84 logger('pipe.response', rawLlmResponse, 'type: (streaming)');
85 return handleStreamingResponse({
86 response: rawLlmResponse,
87 headers: {},
88 c
89 });
90 }
91 return c.json({ body });
92};
93
94const handleGenerateError = (c: any, error: unknown) => {
95 if (error instanceof ApiErrorZod) {

Callers 1

handleRunFunction · 0.70

Calls 2

loggerFunction · 0.90
handleStreamingResponseFunction · 0.90

Tested by

no test coverage detected