@@ -11,6 +11,7 @@ import {
1111 TRANSLATION_RETRY_BASE_DELAY_MS ,
1212 TRANSLATION_CHUNK_MAX_CHARS ,
1313 OPENAI_BASE_URL ,
14+ IS_CUSTOM_OPENAI_API ,
1415} from "../constants.js" ;
1516
1617// Load environment variables
@@ -467,6 +468,26 @@ async function translateTextSingleCall(
467468 // For GPT-5.2, use reasoning_effort="none" to allow custom temperature
468469 const modelParams = getModelParams ( model , { useReasoningNone : true } ) ;
469470
471+ // Use json_schema for OpenAI (strict), json_object for custom APIs (like DeepSeek)
472+ const responseFormat = IS_CUSTOM_OPENAI_API
473+ ? { type : "json_object" as const }
474+ : {
475+ type : "json_schema" as const ,
476+ json_schema : {
477+ name : "translation" ,
478+ schema : {
479+ type : "object" ,
480+ properties : {
481+ markdown : { type : "string" } ,
482+ title : { type : "string" } ,
483+ } ,
484+ required : [ "markdown" , "title" ] ,
485+ additionalProperties : false ,
486+ } ,
487+ strict : true ,
488+ } ,
489+ } ;
490+
470491 for ( let attempt = 0 ; attempt < MAX_RETRIES ; attempt ++ ) {
471492 try {
472493 const response = await openai . chat . completions . create ( {
@@ -475,22 +496,7 @@ async function translateTextSingleCall(
475496 { role : "system" , content : prompt } ,
476497 { role : "user" , content : textWithTitle } ,
477498 ] ,
478- response_format : {
479- type : "json_schema" ,
480- json_schema : {
481- name : "translation" ,
482- schema : {
483- type : "object" ,
484- properties : {
485- markdown : { type : "string" } ,
486- title : { type : "string" } ,
487- } ,
488- required : [ "markdown" , "title" ] ,
489- additionalProperties : false ,
490- } ,
491- strict : true ,
492- } ,
493- } ,
499+ response_format : responseFormat ,
494500 ...modelParams ,
495501 } ) ;
496502
0 commit comments