( choices: ChatCompletion.Choice[], )
| 1209 | |
| 1210 | // Transforms a single OpenAI-style inbound response message into normalized form |
| 1211 | function transformOpenAIResponseChoice( |
| 1212 | choices: ChatCompletion.Choice[], |
| 1213 | ): NormalizedMessage[] { |
| 1214 | // Maps each choice to a separate assistant message. |
| 1215 | // This is clearly wrong, since choices are meant to be alternatives (from which the client |
| 1216 | // should pick one). However CAPI frequently returns collections of tool calls as separate choices, |
| 1217 | // and our chat-completion-client.ts logic handles this by treating them as sequential messages. |
| 1218 | // So, we have to do the same thing here. |
| 1219 | return choices.map((choice) => { |
| 1220 | const tool_calls = |
| 1221 | choice.message.tool_calls?.map(transformOpenAIToolCall) ?? []; |
| 1222 | const msg: NormalizedMessage = { role: "assistant" }; |
| 1223 | msg.content = choice.message.content ?? undefined; |
| 1224 | msg.refusal = choice.message.refusal ?? undefined; |
| 1225 | if (tool_calls.length) msg.tool_calls = tool_calls; |
| 1226 | return msg; |
| 1227 | }); |
| 1228 | } |
| 1229 | |
| 1230 | function transformOpenAIToolCall(tc: { |
| 1231 | id: string; |
no outgoing calls
no test coverage detected
searching dependent graphs…