mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-19 05:12:16 +03:00
fix(translator): map Claude stop_sequences and stop to Gemini stopSequences (#12785)
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import { register } from "../registry.ts";
|
||||
import { FORMATS } from "../formats.ts";
|
||||
import {
|
||||
DEFAULT_SAFETY_SETTINGS,
|
||||
cleanJSONSchemaForAntigravity,
|
||||
} from "../helpers/geminiHelper.ts";
|
||||
import { DEFAULT_SAFETY_SETTINGS, cleanJSONSchemaForAntigravity } from "../helpers/geminiHelper.ts";
|
||||
import { buildGeminiTools, sanitizeGeminiToolName } from "../helpers/geminiToolsSanitizer.ts";
|
||||
import {
|
||||
buildGeminiThoughtSignatureKey,
|
||||
@@ -83,6 +80,10 @@ export function claudeToGeminiRequest(model, body, stream, credentials = null) {
|
||||
result.generationConfig.maxOutputTokens = maxOutputTokens;
|
||||
}
|
||||
}
|
||||
if (body.stop_sequences !== undefined || body.stop !== undefined) {
|
||||
const rawStop = body.stop_sequences ?? body.stop;
|
||||
result.generationConfig.stopSequences = Array.isArray(rawStop) ? rawStop : [rawStop];
|
||||
}
|
||||
|
||||
// ── System instruction ─────────────────────────────────────────
|
||||
if (body.system) {
|
||||
|
||||
@@ -486,3 +486,34 @@ test("Claude -> Gemini non-numeric budget_tokens falls through to effort path",
|
||||
includeThoughts: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("Claude -> Gemini maps stop_sequences and stop to generationConfig.stopSequences", () => {
|
||||
const result1 = claudeToGeminiRequest(
|
||||
"gemini-2.5-pro",
|
||||
{
|
||||
messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
|
||||
stop_sequences: ["STOP", "\nHuman:"],
|
||||
},
|
||||
false
|
||||
);
|
||||
assert.deepEqual(result1.generationConfig.stopSequences, ["STOP", "\nHuman:"]);
|
||||
|
||||
const result2 = claudeToGeminiRequest(
|
||||
"gemini-2.5-pro",
|
||||
{
|
||||
messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
|
||||
stop: "SINGLE_STOP",
|
||||
},
|
||||
false
|
||||
);
|
||||
assert.deepEqual(result2.generationConfig.stopSequences, ["SINGLE_STOP"]);
|
||||
|
||||
const result3 = claudeToGeminiRequest(
|
||||
"gemini-2.5-pro",
|
||||
{
|
||||
messages: [{ role: "user", content: [{ type: "text", text: "hi" }] }],
|
||||
},
|
||||
false
|
||||
);
|
||||
assert.strictEqual(result3.generationConfig.stopSequences, undefined);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user