fix: reasoning_content DeepSeek — retry avec maxSteps=1 si erreur thinking mode
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:
@@ -119,25 +119,40 @@ export class CustomOpenAIProvider implements AIProvider {
|
|||||||
|
|
||||||
async generateWithTools(options: ToolUseOptions): Promise<ToolCallResult> {
|
async generateWithTools(options: ToolUseOptions): Promise<ToolCallResult> {
|
||||||
const { tools, maxSteps = 10, systemPrompt, messages, prompt } = options
|
const { tools, maxSteps = 10, systemPrompt, messages, prompt } = options
|
||||||
const opts: Record<string, any> = {
|
|
||||||
model: this.model,
|
|
||||||
tools,
|
|
||||||
stopWhen: stepCountIs(maxSteps),
|
|
||||||
}
|
|
||||||
if (systemPrompt) opts.system = systemPrompt
|
|
||||||
if (messages) opts.messages = messages
|
|
||||||
else if (prompt) opts.prompt = prompt
|
|
||||||
|
|
||||||
const result = await aiGenerateText(opts as any)
|
const buildOpts = (steps: number): Record<string, any> => {
|
||||||
return {
|
const opts: Record<string, any> = { model: this.model, tools, stopWhen: stepCountIs(steps) }
|
||||||
toolCalls: result.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
|
if (systemPrompt) opts.system = systemPrompt
|
||||||
toolResults: result.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
|
if (messages) opts.messages = messages
|
||||||
text: result.text,
|
else if (prompt) opts.prompt = prompt
|
||||||
steps: result.steps?.map((step: any) => ({
|
return opts
|
||||||
|
}
|
||||||
|
|
||||||
|
const toResult = (r: any): ToolCallResult => ({
|
||||||
|
toolCalls: r.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
|
||||||
|
toolResults: r.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
|
||||||
|
text: r.text,
|
||||||
|
steps: r.steps?.map((step: any) => ({
|
||||||
text: step.text,
|
text: step.text,
|
||||||
toolCalls: step.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
|
toolCalls: step.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
|
||||||
toolResults: step.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || []
|
toolResults: step.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
|
||||||
})) || []
|
})) || [],
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await aiGenerateText(buildOpts(maxSteps) as any)
|
||||||
|
return toResult(result)
|
||||||
|
} catch (err: any) {
|
||||||
|
// DeepSeek reasoning/thinking models require reasoning_content to be passed back
|
||||||
|
// between multi-step calls, which the AI SDK doesn't handle via the OpenAI-compat layer.
|
||||||
|
// Retry with a single step so the model calls the tool directly.
|
||||||
|
const msg: string = err?.message || String(err)
|
||||||
|
if (msg.includes('reasoning_content') || msg.includes('thinking mode')) {
|
||||||
|
console.warn('[CustomOpenAI] Reasoning model detected — retrying with maxSteps=1')
|
||||||
|
const result = await aiGenerateText(buildOpts(1) as any)
|
||||||
|
return toResult(result)
|
||||||
|
}
|
||||||
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,25 +103,40 @@ export class DeepSeekProvider implements AIProvider {
|
|||||||
|
|
||||||
async generateWithTools(options: ToolUseOptions): Promise<ToolCallResult> {
|
async generateWithTools(options: ToolUseOptions): Promise<ToolCallResult> {
|
||||||
const { tools, maxSteps = 10, systemPrompt, messages, prompt } = options
|
const { tools, maxSteps = 10, systemPrompt, messages, prompt } = options
|
||||||
const opts: Record<string, any> = {
|
|
||||||
model: this.model,
|
|
||||||
tools,
|
|
||||||
stopWhen: stepCountIs(maxSteps),
|
|
||||||
}
|
|
||||||
if (systemPrompt) opts.system = systemPrompt
|
|
||||||
if (messages) opts.messages = messages
|
|
||||||
else if (prompt) opts.prompt = prompt
|
|
||||||
|
|
||||||
const result = await aiGenerateText(opts as any)
|
const buildOpts = (steps: number): Record<string, any> => {
|
||||||
return {
|
const opts: Record<string, any> = { model: this.model, tools, stopWhen: stepCountIs(steps) }
|
||||||
toolCalls: result.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
|
if (systemPrompt) opts.system = systemPrompt
|
||||||
toolResults: result.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
|
if (messages) opts.messages = messages
|
||||||
text: result.text,
|
else if (prompt) opts.prompt = prompt
|
||||||
steps: result.steps?.map((step: any) => ({
|
return opts
|
||||||
|
}
|
||||||
|
|
||||||
|
const toResult = (r: any): ToolCallResult => ({
|
||||||
|
toolCalls: r.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
|
||||||
|
toolResults: r.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
|
||||||
|
text: r.text,
|
||||||
|
steps: r.steps?.map((step: any) => ({
|
||||||
text: step.text,
|
text: step.text,
|
||||||
toolCalls: step.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
|
toolCalls: step.toolCalls?.map((tc: any) => ({ toolName: tc.toolName, input: tc.input })) || [],
|
||||||
toolResults: step.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || []
|
toolResults: step.toolResults?.map((tr: any) => ({ toolName: tr.toolName, input: tr.input, output: tr.output })) || [],
|
||||||
})) || []
|
})) || [],
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await aiGenerateText(buildOpts(maxSteps) as any)
|
||||||
|
return toResult(result)
|
||||||
|
} catch (err: any) {
|
||||||
|
// DeepSeek reasoning/thinking models require reasoning_content to be passed back
|
||||||
|
// between multi-step calls, which the AI SDK doesn't handle automatically.
|
||||||
|
// Retry with a single step so the model calls the tool directly without multi-turn.
|
||||||
|
const msg: string = err?.message || String(err)
|
||||||
|
if (msg.includes('reasoning_content') || msg.includes('thinking mode')) {
|
||||||
|
console.warn('[DeepSeek] Reasoning model detected — retrying with maxSteps=1')
|
||||||
|
const result = await aiGenerateText(buildOpts(1) as any)
|
||||||
|
return toResult(result)
|
||||||
|
}
|
||||||
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user