Skip to content

Commit a161c0d

Browse files
committed
update openai-compatible to add a generated id if missing
1 parent 669b925 commit a161c0d

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/internal/src/openai-compatible/chat/openai-compatible-chat-language-model.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -512,28 +512,24 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV2 {
512512
const index = toolCallDelta.index;
513513

514514
if (toolCalls[index] == null) {
515-
if (toolCallDelta.id == null) {
516-
throw new InvalidResponseDataError({
517-
data: toolCallDelta,
518-
message: `Expected 'id' to be a string.`,
519-
});
520-
}
521-
522515
if (toolCallDelta.function?.name == null) {
523516
throw new InvalidResponseDataError({
524517
data: toolCallDelta,
525518
message: `Expected 'function.name' to be a string.`,
526519
});
527520
}
528521

522+
// UPDATED (James): Generate an ID if the provider doesn't include one (e.g., GLM models)
523+
const toolCallId = toolCallDelta.id ?? generateId();
524+
529525
controller.enqueue({
530526
type: 'tool-input-start',
531-
id: toolCallDelta.id,
527+
id: toolCallId,
532528
toolName: toolCallDelta.function.name,
533529
});
534530

535531
toolCalls[index] = {
536-
id: toolCallDelta.id,
532+
id: toolCallId,
537533
type: 'function',
538534
function: {
539535
name: toolCallDelta.function.name,

0 commit comments

Comments
 (0)