diff --git a/memento-note/lib/ai/providers/custom-openai.ts b/memento-note/lib/ai/providers/custom-openai.ts index 63914c9..9f6d550 100644 --- a/memento-note/lib/ai/providers/custom-openai.ts +++ b/memento-note/lib/ai/providers/custom-openai.ts @@ -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 }); } }); diff --git a/memento-note/lib/ai/providers/deepseek.ts b/memento-note/lib/ai/providers/deepseek.ts index b59897b..ea411b3 100644 --- a/memento-note/lib/ai/providers/deepseek.ts +++ b/memento-note/lib/ai/providers/deepseek.ts @@ -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);