-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-disable-thinking.mjs
More file actions
61 lines (53 loc) · 1.87 KB
/
test-disable-thinking.mjs
File metadata and controls
61 lines (53 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Quick test: does reasoning_effort='none' or thinking_budget=0 disable thinking in Google compat API?
import { createOpenAI } from '@ai-sdk/openai';
import { streamText, tool } from 'ai';
import { z } from 'zod';
const apiKey = process.env.GEMINI_API_KEY;
async function testWithParam(paramName, paramValue) {
process.stdout.write(`\nTesting ${paramName}=${JSON.stringify(paramValue)} ...\n`);
const interceptingFetch = async (input, init) => {
if (init?.body && typeof init.body === 'string') {
try {
const body = JSON.parse(init.body);
body[paramName] = paramValue;
return await fetch(input, { ...init, body: JSON.stringify(body) });
} catch {
return fetch(input, init);
}
}
return fetch(input, init);
};
const providerClient = createOpenAI({
apiKey,
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai',
name: 'google',
compatibility: 'compatible',
fetch: interceptingFetch,
});
const model = providerClient('gemini-3-flash-preview');
try {
const result = streamText({
model,
system: 'You are a helpful assistant.',
messages: [{ role: 'user', content: 'List some files' }],
tools: {
listFiles: tool({
description: 'List files',
parameters: z.object({ dir: z.string().describe('directory') }),
execute: async ({ dir }) => `Found files in ${dir}: file1.ts, file2.ts`,
}),
},
maxSteps: 2,
});
let text = '';
for await (const chunk of result.textStream) {
text += chunk;
}
const steps = await result.steps;
process.stdout.write(`SUCCESS: ${steps.length} steps, text: ${text.slice(0, 100)}\n`);
} catch(e) {
process.stdout.write(`FAIL: ${e.message?.slice(0, 200)}\n`);
}
}
await testWithParam('reasoning_effort', 'none');
await testWithParam('thinking_budget', 0);