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

Function processLlmResponse

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

Source from the content-addressed store, hash-verified

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

Callers 1

handleRunFunction · 0.70

Calls 2

loggerFunction · 0.90
handleStreamingResponseFunction · 0.90

Tested by

no test coverage detected