Skip to content

Commit f2ae26e

Browse files
authored
Fix tool calls property normalization and stream options handling for non-streaming responses (#1732)
* add log * try streaming false * try undefined * correct fix * correct fix 2 * fixxxx * consume resp just once * fix message * no replacement of content * clean up but need to make stream configurable for byok * update * update
1 parent ab9522c commit f2ae26e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/extension/byok/node/openAIEndpoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export class OpenAIEndpoint extends ChatEndpoint {
296296
}
297297
// Removing max tokens defaults to the maximum which is what we want for BYOK
298298
delete body.max_tokens;
299-
if (!this.useResponsesApi) {
299+
if (!this.useResponsesApi && body.stream) {
300300
body['stream_options'] = { 'include_usage': true };
301301
}
302302
}

src/platform/endpoint/node/chatEndpoint.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ export async function defaultNonStreamChatResponseProcessor(response: Response,
6464
const completions: ChatCompletion[] = [];
6565
for (let i = 0; i < (jsonResponse?.choices?.length || 0); i++) {
6666
const choice = jsonResponse.choices[i];
67-
const message: Raw.AssistantChatMessage = choice.message;
67+
const message: Raw.AssistantChatMessage = {
68+
role: choice.message.role,
69+
content: choice.message.content,
70+
name: choice.message.name,
71+
// Normalize property name: OpenAI API uses snake_case (tool_calls) but our types expect camelCase (toolCalls)
72+
// See: https://platform.openai.com/docs/api-reference/chat/object#chat-object-choices-message-tool_calls
73+
toolCalls: choice.message.toolCalls ?? choice.message.tool_calls,
74+
};
6875
const messageText = getTextPart(message.content);
6976
const requestId = response.headers.get('X-Request-ID') ?? generateUuid();
7077
const ghRequestId = response.headers.get('x-github-request-id') ?? '';

0 commit comments

Comments
 (0)