Skip to content

Commit a56331d

Browse files
fix: accept Cerebras tool calls without content (#88)
1 parent 5105ae5 commit a56331d

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/__tests__/tool-call-validation.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,40 @@ describe('Tool call validation at provider boundary', () => {
361361
provider = new CerebrasProvider({ apiKey: 'test-key' });
362362
});
363363

364+
it('should pass Cerebras tool calls when message.content is omitted', async () => {
365+
mockFetch.mockResolvedValueOnce({
366+
ok: true,
367+
json: async () => ({
368+
id: 'chatcmpl-1',
369+
model: 'zai-glm-4.7',
370+
choices: [{
371+
index: 0,
372+
message: {
373+
role: 'assistant',
374+
tool_calls: [{
375+
id: 'call_ok',
376+
type: 'function',
377+
function: { name: 'lookup', arguments: '{}' }
378+
}]
379+
},
380+
finish_reason: 'tool_calls'
381+
}],
382+
usage: baseUsage
383+
}),
384+
headers: new Headers({ 'content-type': 'application/json' })
385+
});
386+
387+
const res = await provider.generateResponse({
388+
messages: [{ role: 'user', content: 'hi' }],
389+
model: 'zai-glm-4.7'
390+
});
391+
392+
expect(res.content).toBe('');
393+
expect(res.toolCalls).toHaveLength(1);
394+
expect(res.toolCalls![0].id).toBe('call_ok');
395+
expect(res.toolCalls![0].function.name).toBe('lookup');
396+
});
397+
364398
it('should drop Cerebras tool call with empty function.name', async () => {
365399
mockFetch.mockResolvedValueOnce({
366400
ok: true,

src/providers/cerebras.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const CEREBRAS_RESPONSE_SCHEMA: SchemaField[] = [
2727
items: {
2828
shape: [
2929
{ path: 'message', type: 'object' },
30-
{ path: 'message.content', type: 'string-or-null' },
30+
{ path: 'message.content', type: 'string-or-null', optional: true },
3131
{ path: 'finish_reason', type: 'string' },
3232
{
3333
path: 'message.tool_calls',
@@ -101,7 +101,7 @@ interface CerebrasResponse {
101101
index: number;
102102
message: {
103103
role: string;
104-
content: string | null;
104+
content?: string | null;
105105
tool_calls?: Array<{
106106
id: string;
107107
type: 'function';

0 commit comments

Comments
 (0)