fix: désactiver thinking mode DeepSeek pour fiabiliser le tool calling
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 23s
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 23s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,6 +26,19 @@ export class CustomOpenAIProvider implements AIProvider {
|
||||
const headers = new Headers(options?.headers);
|
||||
headers.set('HTTP-Referer', 'https://localhost:3000');
|
||||
headers.set('X-Title', 'Memento AI');
|
||||
// Disable DeepSeek extended thinking for reliable tool/function calling
|
||||
if (options?.body) {
|
||||
try {
|
||||
const body = JSON.parse(options.body as string)
|
||||
if (
|
||||
typeof body.model === 'string' &&
|
||||
(body.model.includes('deepseek') || body.model.includes('thinking') || body.model.includes('reasoner'))
|
||||
) {
|
||||
body.thinking = { type: 'disabled' }
|
||||
}
|
||||
return fetch(url, { ...options, headers, body: JSON.stringify(body) })
|
||||
} catch { /* ignore parse errors */ }
|
||||
}
|
||||
return fetch(url, { ...options, headers });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -9,9 +9,21 @@ export class DeepSeekProvider implements AIProvider {
|
||||
|
||||
constructor(apiKey: string, modelName: string = 'deepseek-chat', embeddingModelName: string = 'deepseek-embedding') {
|
||||
// Create OpenAI-compatible client for DeepSeek
|
||||
// Disable extended thinking to ensure reliable tool/function calling
|
||||
const deepseek = createOpenAI({
|
||||
baseURL: 'https://api.deepseek.com/v1',
|
||||
apiKey: apiKey,
|
||||
fetch: async (url, options) => {
|
||||
if (options?.body) {
|
||||
try {
|
||||
const body = JSON.parse(options.body as string)
|
||||
// Disable thinking mode — tool calling is unreliable with it enabled
|
||||
body.thinking = { type: 'disabled' }
|
||||
return fetch(url, { ...options, body: JSON.stringify(body) })
|
||||
} catch { /* ignore parse errors */ }
|
||||
}
|
||||
return fetch(url, options)
|
||||
},
|
||||
});
|
||||
|
||||
this.model = deepseek.chat(modelName);
|
||||
|
||||
Reference in New Issue
Block a user