From 3c524b0f988648e79ee72e88c96569641acf3c38 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Sat, 6 Dec 2025 15:25:48 +0530 Subject: [PATCH] feat(openai-llm): process assistant message with tool calls --- src/lib/models/providers/openai/openaiLLM.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib/models/providers/openai/openaiLLM.ts b/src/lib/models/providers/openai/openaiLLM.ts index e1dc531..a40714e 100644 --- a/src/lib/models/providers/openai/openaiLLM.ts +++ b/src/lib/models/providers/openai/openaiLLM.ts @@ -12,6 +12,7 @@ import { import { parse } from 'partial-json'; import z from 'zod'; import { + ChatCompletionAssistantMessageParam, ChatCompletionMessageParam, ChatCompletionTool, ChatCompletionToolMessageParam, @@ -45,6 +46,22 @@ class OpenAILLM extends BaseLLM { tool_call_id: msg.id, content: msg.content, } as ChatCompletionToolMessageParam; + } else if (msg.role === 'assistant') { + return { + role: 'assistant', + content: msg.content, + ...(msg.tool_calls && + msg.tool_calls.length > 0 && { + tool_calls: msg.tool_calls?.map((tc) => ({ + id: tc.id, + type: 'function', + function: { + name: tc.name, + arguments: JSON.stringify(tc.arguments), + }, + })), + }), + } as ChatCompletionAssistantMessageParam; } return msg; @@ -178,7 +195,7 @@ class OpenAILLM extends BaseLLM { async generateObject(input: GenerateObjectInput): Promise { const response = await this.openAIClient.chat.completions.parse({ - messages: input.messages, + messages: this.convertToOpenAIMessages(input.messages), model: this.config.model, temperature: input.options?.temperature ?? this.config.options?.temperature ?? 1.0,