MCPcopy Create free account
hub / github.com/github/copilot-sdk / transformOpenAIResponseChoice

Function transformOpenAIResponseChoice

test/harness/replayingCapiProxy.ts:1211–1228  ·  view source on GitHub ↗
(
  choices: ChatCompletion.Choice[],
)

Source from the content-addressed store, hash-verified

1209
1210// Transforms a single OpenAI-style inbound response message into normalized form
1211function 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
1230function transformOpenAIToolCall(tc: {
1231 id: string;

Callers 1

transformHttpExchangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…