Skip to content

Commit 381ec66

Browse files
committed
fix(openai): improve error handling and tool choice configuration
- Change tool_choice to "auto" to allow model flexibility in tool usage - Add error handling for API responses with status and msg fields - Add logging for invalid API response format to aid debugging
1 parent d5581bb commit 381ec66

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opencode-mem",
3-
"version": "2.11.0",
3+
"version": "2.11.1",
44
"description": "OpenCode plugin that gives coding agents persistent memory using local vector database",
55
"type": "module",
66
"main": "dist/plugin.js",

src/services/ai/providers/openai-chat-completion.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class OpenAIChatCompletionProvider extends BaseAIProvider {
168168
model: this.config.model,
169169
messages,
170170
tools: [toolSchema],
171-
tool_choice: { type: "function", function: { name: toolSchema.function.name } },
171+
tool_choice: "auto",
172172
};
173173

174174
if (this.config.memoryTemperature !== false) {
@@ -218,9 +218,26 @@ export class OpenAIChatCompletionProvider extends BaseAIProvider {
218218
};
219219
}
220220

221-
const data = (await response.json()) as ToolCallResponse;
221+
const data = (await response.json()) as any;
222+
223+
if (data.status && data.msg) {
224+
log("API returned error in response body", {
225+
status: data.status,
226+
msg: data.msg,
227+
});
228+
return {
229+
success: false,
230+
error: `API error: ${data.status} - ${data.msg}`,
231+
iterations,
232+
};
233+
}
222234

223235
if (!data.choices || !data.choices[0]) {
236+
log("Invalid API response format", {
237+
response: JSON.stringify(data).slice(0, 1000),
238+
hasChoices: !!data.choices,
239+
choicesLength: data.choices?.length,
240+
});
224241
return {
225242
success: false,
226243
error: "Invalid API response format",

0 commit comments

Comments
 (0)