diff --git a/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts b/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts index 71a1ead6b4..fc2d724342 100644 --- a/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts +++ b/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts @@ -3173,9 +3173,9 @@ describe('LobeOpenAICompatibleFactory', () => { { headers: undefined, signal: undefined }, ); - expect(result).toEqual([ - { arguments: { age: 28, name: 'Alice' }, name: 'person_extractor' }, - ]); + // The fallback returns the parsed schema object, same shape as the + // json_schema path + expect(result).toEqual({ age: 28, name: 'Alice' }); }); it('should not forward internal thinking to generic OpenAI-compatible generateObject requests', async () => { @@ -3255,7 +3255,10 @@ describe('LobeOpenAICompatibleFactory', () => { const result = await instanceWithToolCalling.generateObject(payload); - expect(consoleSpy).toHaveBeenCalledWith('parse tool call arguments error:', undefined); + expect(consoleSpy).toHaveBeenCalledWith( + 'no tool call found in structured output response:', + mockResponse.choices[0].message, + ); expect(result).toBeUndefined(); consoleSpy.mockRestore(); @@ -3298,7 +3301,7 @@ describe('LobeOpenAICompatibleFactory', () => { expect(consoleSpy).toHaveBeenCalledWith( 'parse tool call arguments error:', - mockResponse.choices[0].message.tool_calls, + mockResponse.choices[0].message.tool_calls[0], ); expect(result).toBeUndefined(); @@ -3350,7 +3353,7 @@ describe('LobeOpenAICompatibleFactory', () => { { headers: options.headers, signal: options.signal }, ); - expect(result).toEqual([{ arguments: { data: 'test' }, name: 'data_extractor' }]); + expect(result).toEqual({ data: 'test' }); }); }); }); diff --git a/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts b/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts index 31d768bef2..5e9aadaf49 100644 --- a/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts +++ b/packages/model-runtime/src/core/openaiCompatibleFactory/index.ts @@ -898,7 +898,9 @@ export const createOpenAICompatibleRuntime = = an toolCalls?.find((item) => item.function?.name === tool.function.name) ?? toolCalls?.[0]; if (!toolCall?.function) { - log('no tool call found in structured output response'); + // tool_choice forces this function, so a missing tool call means the + // provider misbehaved — surface it instead of silently returning undefined + console.error('no tool call found in structured output response:', res.choices[0]?.message); return undefined; }