提供强制json输出的选项
This commit is contained in:
@@ -376,6 +376,9 @@ class BaseWorkflowParams(BaseModel):
|
||||
None,
|
||||
description="用于术语表生成的Agent的配置。如果 `glossary_generate_enable` 为 `True`,此项必填。",
|
||||
)
|
||||
force_json: bool = Field(
|
||||
default=False, description="应输出json格式时强制ai输出json"
|
||||
)
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
@@ -907,6 +910,7 @@ async def _perform_translation(
|
||||
"timeout",
|
||||
"retry",
|
||||
"system_proxy_enable",
|
||||
"force_json",
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -969,6 +973,7 @@ async def _perform_translation(
|
||||
"timeout",
|
||||
"retry",
|
||||
"system_proxy_enable",
|
||||
"force_json",
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -1005,6 +1010,7 @@ async def _perform_translation(
|
||||
"timeout",
|
||||
"retry",
|
||||
"system_proxy_enable",
|
||||
"force_json",
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -1043,6 +1049,7 @@ async def _perform_translation(
|
||||
"timeout",
|
||||
"retry",
|
||||
"system_proxy_enable",
|
||||
"force_json",
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -1080,6 +1087,7 @@ async def _perform_translation(
|
||||
"timeout",
|
||||
"retry",
|
||||
"system_proxy_enable",
|
||||
"force_json",
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -1117,6 +1125,7 @@ async def _perform_translation(
|
||||
"timeout",
|
||||
"retry",
|
||||
"system_proxy_enable",
|
||||
"force_json",
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -1154,6 +1163,7 @@ async def _perform_translation(
|
||||
"timeout",
|
||||
"retry",
|
||||
"system_proxy_enable",
|
||||
"force_json",
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -1192,6 +1202,7 @@ async def _perform_translation(
|
||||
"timeout",
|
||||
"retry",
|
||||
"system_proxy_enable",
|
||||
"force_json",
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
@@ -1228,6 +1239,7 @@ async def _perform_translation(
|
||||
"timeout",
|
||||
"retry",
|
||||
"system_proxy_enable",
|
||||
"force_json",
|
||||
},
|
||||
exclude_none=True,
|
||||
)
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -39,7 +39,8 @@ class AssTranslator(AiTranslator):
|
||||
logger=self.logger,
|
||||
glossary_dict=config.glossary_dict,
|
||||
retry=config.retry,
|
||||
system_proxy_enable=config.system_proxy_enable
|
||||
system_proxy_enable=config.system_proxy_enable,
|
||||
json_format=config.force_json
|
||||
)
|
||||
self.translate_agent = SegmentsTranslateAgent(agent_config)
|
||||
self.insert_mode = config.insert_mode
|
||||
|
||||
@@ -26,7 +26,7 @@ class AiTranslatorConfig(TranslatorConfig, AgentConfig):
|
||||
glossary_generate_enable: bool = False
|
||||
glossary_agent_config: GlossaryAgentConfig | None = None
|
||||
skip_translate: bool = False # 当skip_translate为False时base_url、model_id为必填项
|
||||
|
||||
force_json:bool=False # 应输出json格式时强制ai输出json
|
||||
|
||||
T = TypeVar("T", bound=Document)
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ class DocxTranslator(AiTranslator):
|
||||
api_key=config.api_key, model_id=config.model_id, temperature=config.temperature,
|
||||
thinking=config.thinking, concurrent=config.concurrent, timeout=config.timeout,
|
||||
logger=self.logger, glossary_dict=config.glossary_dict, retry=config.retry,
|
||||
system_proxy_enable=config.system_proxy_enable
|
||||
system_proxy_enable=config.system_proxy_enable,json_format=config.force_json
|
||||
)
|
||||
self.translate_agent = SegmentsTranslateAgent(agent_config)
|
||||
self.insert_mode = config.insert_mode
|
||||
|
||||
@@ -50,7 +50,8 @@ class EpubTranslator(AiTranslator):
|
||||
logger=self.logger,
|
||||
glossary_dict=config.glossary_dict,
|
||||
retry=config.retry,
|
||||
system_proxy_enable=config.system_proxy_enable
|
||||
system_proxy_enable=config.system_proxy_enable,
|
||||
json_format=config.force_json
|
||||
)
|
||||
self.translate_agent = SegmentsTranslateAgent(agent_config)
|
||||
self.insert_mode = config.insert_mode
|
||||
|
||||
@@ -68,7 +68,8 @@ class HtmlTranslator(AiTranslator):
|
||||
logger=self.logger,
|
||||
glossary_dict=config.glossary_dict,
|
||||
retry=config.retry,
|
||||
system_proxy_enable=config.system_proxy_enable
|
||||
system_proxy_enable=config.system_proxy_enable,
|
||||
json_format=config.force_json
|
||||
)
|
||||
self.translate_agent = SegmentsTranslateAgent(agent_config)
|
||||
self.insert_mode = config.insert_mode
|
||||
|
||||
@@ -36,7 +36,8 @@ class JsonTranslator(AiTranslator):
|
||||
logger=self.logger,
|
||||
glossary_dict=config.glossary_dict,
|
||||
retry=config.retry,
|
||||
system_proxy_enable=config.system_proxy_enable
|
||||
system_proxy_enable=config.system_proxy_enable,
|
||||
json_format=config.force_json
|
||||
)
|
||||
self.translate_agent = SegmentsTranslateAgent(agent_config)
|
||||
self.json_paths = config.json_paths
|
||||
|
||||
@@ -41,7 +41,8 @@ class SrtTranslator(AiTranslator):
|
||||
logger=self.logger,
|
||||
glossary_dict=config.glossary_dict,
|
||||
retry=config.retry,
|
||||
system_proxy_enable=config.system_proxy_enable
|
||||
system_proxy_enable=config.system_proxy_enable,
|
||||
json_format=config.force_json
|
||||
)
|
||||
self.translate_agent = SegmentsTranslateAgent(agent_config)
|
||||
self.insert_mode = config.insert_mode
|
||||
|
||||
@@ -66,7 +66,8 @@ class TXTTranslator(AiTranslator):
|
||||
logger=self.logger,
|
||||
glossary_dict=config.glossary_dict,
|
||||
retry=config.retry,
|
||||
system_proxy_enable=config.system_proxy_enable
|
||||
system_proxy_enable=config.system_proxy_enable,
|
||||
json_format=config.force_json
|
||||
)
|
||||
self.translate_agent = SegmentsTranslateAgent(agent_config)
|
||||
self.insert_mode = config.insert_mode
|
||||
|
||||
@@ -45,7 +45,8 @@ class XlsxTranslator(AiTranslator):
|
||||
logger=self.logger,
|
||||
glossary_dict=config.glossary_dict,
|
||||
retry=config.retry,
|
||||
system_proxy_enable=config.system_proxy_enable
|
||||
system_proxy_enable=config.system_proxy_enable,
|
||||
json_format=config.force_json
|
||||
)
|
||||
self.translate_agent = SegmentsTranslateAgent(agent_config)
|
||||
self.insert_mode = config.insert_mode
|
||||
|
||||
Reference in New Issue
Block a user