修复术语表自定义配置to_lang不生效的问题
This commit is contained in:
@@ -18,6 +18,7 @@ class GlossaryAgentConfig(AgentConfig):
|
|||||||
class GlossaryAgent(Agent):
|
class GlossaryAgent(Agent):
|
||||||
def __init__(self, config: GlossaryAgentConfig):
|
def __init__(self, config: GlossaryAgentConfig):
|
||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
|
self.to_lang=config.to_lang
|
||||||
self.system_prompt = f"""
|
self.system_prompt = f"""
|
||||||
# Role
|
# Role
|
||||||
You are a professional machine translation engine.
|
You are a professional machine translation engine.
|
||||||
@@ -26,12 +27,12 @@ You are a professional machine translation engine.
|
|||||||
|
|
||||||
# Task
|
# Task
|
||||||
你会收到一个json格式的段落表,其中键是段落的序号,值是段落的内容。
|
你会收到一个json格式的段落表,其中键是段落的序号,值是段落的内容。
|
||||||
你需要从这些段落中提取**人名**和**地名**,并翻译这些名词为{config.to_lang}语言。
|
你需要从这些段落中提取**人名**和**地名**,并翻译这些名词为{self.to_lang}语言。
|
||||||
最终输出一个名词原文:名词译文的术语表
|
最终输出一个名词原文:名词译文的术语表
|
||||||
|
|
||||||
# Requirements
|
# Requirements
|
||||||
- 特殊标签、形如`<ph-xxxxxx>`的标签不要添加到术语表
|
- 特殊标签、形如`<ph-xxxxxx>`的标签不要添加到术语表
|
||||||
- 输出术语表的src必须与名词原文完全一致,dst是该名词的{config.to_lang}的译文
|
- 输出术语表的src必须与名词原文完全一致,dst是该名词的{self.to_lang}的译文
|
||||||
- 相同的src仅在术语表中添加一次,不能重复
|
- 相同的src仅在术语表中添加一次,不能重复
|
||||||
|
|
||||||
# Output
|
# Output
|
||||||
@@ -67,7 +68,7 @@ You are a professional machine translation engine.
|
|||||||
return origin_prompt
|
return origin_prompt
|
||||||
|
|
||||||
def send_segments(self, segments: list[str], chunk_size: int):
|
def send_segments(self, segments: list[str], chunk_size: int):
|
||||||
self.logger.info("开始提取术语表")
|
self.logger.info(f"开始提取术语表,to_lang:{self.to_lang}")
|
||||||
result = {}
|
result = {}
|
||||||
indexed_originals, chunks, merged_indices_list = segments2json_chunks(segments, chunk_size)
|
indexed_originals, chunks, merged_indices_list = segments2json_chunks(segments, chunk_size)
|
||||||
prompts = [json.dumps(chunk, ensure_ascii=False) for chunk in chunks]
|
prompts = [json.dumps(chunk, ensure_ascii=False) for chunk in chunks]
|
||||||
@@ -87,7 +88,7 @@ You are a professional machine translation engine.
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
async def send_segments_async(self, segments: list[str], chunk_size: int):
|
async def send_segments_async(self, segments: list[str], chunk_size: int):
|
||||||
self.logger.info("开始术语表提取")
|
self.logger.info(f"开始提取术语表,to_lang:{self.to_lang}")
|
||||||
result = {}
|
result = {}
|
||||||
indexed_originals, chunks, merged_indices_list = await asyncio.to_thread(segments2json_chunks, segments,
|
indexed_originals, chunks, merged_indices_list = await asyncio.to_thread(segments2json_chunks, segments,
|
||||||
chunk_size)
|
chunk_size)
|
||||||
|
|||||||
@@ -227,6 +227,7 @@ class GlossaryAgentConfigPayload(BaseModel):
|
|||||||
baseurl: str = Field(..., description="用于术语表生成的Agent的LLM API基础URL。", examples=["https://api.openai.com/v1"])
|
baseurl: str = Field(..., description="用于术语表生成的Agent的LLM API基础URL。", examples=["https://api.openai.com/v1"])
|
||||||
key: str = Field(..., description="用于术语表生成的Agent的LLM API密钥。", examples=["sk-agent-api-key"])
|
key: str = Field(..., description="用于术语表生成的Agent的LLM API密钥。", examples=["sk-agent-api-key"])
|
||||||
model_id: str = Field(..., description="用于术语表生成的Agent的模型ID。", examples=["gpt-4-turbo"])
|
model_id: str = Field(..., description="用于术语表生成的Agent的模型ID。", examples=["gpt-4-turbo"])
|
||||||
|
to_lang: str = Field(..., description="术语表生成的目标语言。", examples=["简体中文", "English"])
|
||||||
temperature: float = Field(default=0.7, description="用于术语表生成的Agent的温度参数。")
|
temperature: float = Field(default=0.7, description="用于术语表生成的Agent的温度参数。")
|
||||||
max_concurrent: int = Field(default=30, description="Agent的最大并发请求数。")
|
max_concurrent: int = Field(default=30, description="Agent的最大并发请求数。")
|
||||||
timeout: int = Field(default=2000, description="Agent的API调用超时时间。")
|
timeout: int = Field(default=2000, description="Agent的API调用超时时间。")
|
||||||
@@ -399,7 +400,7 @@ class TranslateServiceRequest(BaseModel):
|
|||||||
{
|
{
|
||||||
"summary": "Markdown 工作流示例",
|
"summary": "Markdown 工作流示例",
|
||||||
"value": {
|
"value": {
|
||||||
"file_name": "annual_report_2023.pdf",
|
"file_name": "annual_report_203.pdf",
|
||||||
"file_content": "JVBERi0xLjcKJeLjz9MKMSAwIG9iago8PC9...",
|
"file_content": "JVBERi0xLjcKJeLjz9MKMSAwIG9iago8PC9...",
|
||||||
"payload": {
|
"payload": {
|
||||||
"workflow_type": "markdown_based",
|
"workflow_type": "markdown_based",
|
||||||
@@ -466,6 +467,7 @@ class TranslateServiceRequest(BaseModel):
|
|||||||
"baseurl": "https://api.openai.com/v1",
|
"baseurl": "https://api.openai.com/v1",
|
||||||
"key": "sk-your-agent-key-for-glossary",
|
"key": "sk-your-agent-key-for-glossary",
|
||||||
"model_id": "gpt-4-turbo",
|
"model_id": "gpt-4-turbo",
|
||||||
|
"to_lang": "简体中文",
|
||||||
"temperature": 0.5
|
"temperature": 0.5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -575,7 +577,6 @@ async def _perform_translation(
|
|||||||
agent_payload = payload.glossary_agent_config
|
agent_payload = payload.glossary_agent_config
|
||||||
return GlossaryAgentConfig(
|
return GlossaryAgentConfig(
|
||||||
logger=task_logger,
|
logger=task_logger,
|
||||||
to_lang=payload.to_lang,
|
|
||||||
**agent_payload.model_dump()
|
**agent_payload.model_dump()
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user