@gemdoq/codi 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +61 -19
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4251,6 +4251,7 @@ var OpenAIProvider = class {
|
|
|
4251
4251
|
model;
|
|
4252
4252
|
client;
|
|
4253
4253
|
maxTokens;
|
|
4254
|
+
isGemini;
|
|
4254
4255
|
constructor(config) {
|
|
4255
4256
|
this.client = new OpenAI({
|
|
4256
4257
|
apiKey: config.apiKey || process.env["OPENAI_API_KEY"],
|
|
@@ -4258,6 +4259,7 @@ var OpenAIProvider = class {
|
|
|
4258
4259
|
});
|
|
4259
4260
|
this.model = config.model || "gpt-4o";
|
|
4260
4261
|
this.maxTokens = config.maxTokens || 8192;
|
|
4262
|
+
this.isGemini = !!(config.baseUrl && config.baseUrl.includes("generativelanguage.googleapis.com"));
|
|
4261
4263
|
}
|
|
4262
4264
|
setModel(model) {
|
|
4263
4265
|
this.model = model;
|
|
@@ -4277,30 +4279,45 @@ var OpenAIProvider = class {
|
|
|
4277
4279
|
function: {
|
|
4278
4280
|
name: t.name,
|
|
4279
4281
|
description: t.description,
|
|
4280
|
-
parameters: t.input_schema
|
|
4282
|
+
parameters: this.cleanSchema(t.input_schema)
|
|
4281
4283
|
}
|
|
4282
4284
|
}));
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
+
try {
|
|
4286
|
+
if (options.stream && options.callbacks) {
|
|
4287
|
+
return await this.streamChat(messages, tools, options);
|
|
4288
|
+
}
|
|
4289
|
+
const response = await this.client.chat.completions.create({
|
|
4290
|
+
model: this.model,
|
|
4291
|
+
messages,
|
|
4292
|
+
max_tokens: options.maxTokens || this.maxTokens,
|
|
4293
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : {},
|
|
4294
|
+
...tools && tools.length > 0 ? { tools } : {}
|
|
4295
|
+
});
|
|
4296
|
+
return this.parseResponse(response);
|
|
4297
|
+
} catch (err) {
|
|
4298
|
+
const status = err.status || err.statusCode || "";
|
|
4299
|
+
const body = err.error || err.body || err.response?.body || "";
|
|
4300
|
+
const detail = body ? JSON.stringify(body) : err.message || String(err);
|
|
4301
|
+
throw new Error(`${status} ${detail}`.trim());
|
|
4285
4302
|
}
|
|
4286
|
-
const response = await this.client.chat.completions.create({
|
|
4287
|
-
model: this.model,
|
|
4288
|
-
messages,
|
|
4289
|
-
max_tokens: options.maxTokens || this.maxTokens,
|
|
4290
|
-
...options.temperature !== void 0 ? { temperature: options.temperature } : {},
|
|
4291
|
-
...tools && tools.length > 0 ? { tools } : {}
|
|
4292
|
-
});
|
|
4293
|
-
return this.parseResponse(response);
|
|
4294
4303
|
}
|
|
4295
4304
|
async streamChat(messages, tools, options) {
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4305
|
+
let stream;
|
|
4306
|
+
try {
|
|
4307
|
+
stream = await this.client.chat.completions.create({
|
|
4308
|
+
model: this.model,
|
|
4309
|
+
messages,
|
|
4310
|
+
max_tokens: options.maxTokens || this.maxTokens,
|
|
4311
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : {},
|
|
4312
|
+
...tools && tools.length > 0 ? { tools } : {},
|
|
4313
|
+
stream: true
|
|
4314
|
+
});
|
|
4315
|
+
} catch (err) {
|
|
4316
|
+
const status = err.status || err.statusCode || "";
|
|
4317
|
+
const body = err.error || err.body || err.response?.body || "";
|
|
4318
|
+
const detail = body ? JSON.stringify(body) : err.message || String(err);
|
|
4319
|
+
throw new Error(`${status} ${detail}`.trim());
|
|
4320
|
+
}
|
|
4304
4321
|
const content = [];
|
|
4305
4322
|
const toolCalls = [];
|
|
4306
4323
|
let text = "";
|
|
@@ -4345,6 +4362,31 @@ var OpenAIProvider = class {
|
|
|
4345
4362
|
stopReason: toolCalls.length > 0 ? "tool_use" : "end_turn"
|
|
4346
4363
|
};
|
|
4347
4364
|
}
|
|
4365
|
+
/**
|
|
4366
|
+
* Clean JSON Schema for Gemini compatibility.
|
|
4367
|
+
* Gemini's OpenAI-compatible API rejects some valid JSON Schema features:
|
|
4368
|
+
* - Empty `required` arrays
|
|
4369
|
+
* - `default` values in properties
|
|
4370
|
+
* - `additionalProperties` at top level
|
|
4371
|
+
*/
|
|
4372
|
+
cleanSchema(schema) {
|
|
4373
|
+
const cleaned = { ...schema };
|
|
4374
|
+
if (Array.isArray(cleaned["required"]) && cleaned["required"].length === 0) {
|
|
4375
|
+
delete cleaned["required"];
|
|
4376
|
+
}
|
|
4377
|
+
if (cleaned["properties"] && typeof cleaned["properties"] === "object") {
|
|
4378
|
+
const props = { ...cleaned["properties"] };
|
|
4379
|
+
for (const [key, val] of Object.entries(props)) {
|
|
4380
|
+
if (val && typeof val === "object") {
|
|
4381
|
+
const prop = { ...val };
|
|
4382
|
+
delete prop["default"];
|
|
4383
|
+
props[key] = prop;
|
|
4384
|
+
}
|
|
4385
|
+
}
|
|
4386
|
+
cleaned["properties"] = props;
|
|
4387
|
+
}
|
|
4388
|
+
return cleaned;
|
|
4389
|
+
}
|
|
4348
4390
|
convertMessages(messages, systemPrompt) {
|
|
4349
4391
|
const result = [];
|
|
4350
4392
|
if (systemPrompt) {
|