Merge pull request #102 from lethanhson9901/feature/openai-structured-output-support

feat: Add structured output support for OpenAI to Gemini conversion
This commit is contained in:
何夕2077 2025-12-10 12:04:26 +08:00 committed by GitHub
commit 8239f165cf

View file

@ -711,13 +711,25 @@ export class OpenAIConverter extends BaseConverter {
/**
* 构建Gemini生成配置
*/
buildGeminiGenerationConfig({ temperature, max_tokens, top_p, stop, tools }, model) {
buildGeminiGenerationConfig({ temperature, max_tokens, top_p, stop, tools, response_format }, model) {
const config = {};
config.temperature = checkAndAssignOrDefault(temperature, 1);
config.maxOutputTokens = checkAndAssignOrDefault(max_tokens, 65535);
config.topP = checkAndAssignOrDefault(top_p, 0.95);
if (stop !== undefined) config.stopSequences = Array.isArray(stop) ? stop : [stop];
// Handle response_format
if (response_format) {
if (response_format.type === 'json_object') {
config.responseMimeType = 'application/json';
} else if (response_format.type === 'json_schema' && response_format.json_schema) {
config.responseMimeType = 'application/json';
if (response_format.json_schema.schema) {
config.responseSchema = response_format.json_schema.schema;
}
}
}
// Gemini 2.5 and thinking models require responseModalities: ["TEXT"]
// But this parameter cannot be added when using tools (causes 400 error)
const hasTools = tools && Array.isArray(tools) && tools.length > 0;