术语表更新以旧值为准
This commit is contained in:
@@ -18,7 +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.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.
|
||||||
@@ -79,7 +79,7 @@ You are a professional machine translation engine.
|
|||||||
chunk: list[dict[str, str]]
|
chunk: list[dict[str, str]]
|
||||||
try:
|
try:
|
||||||
glossary_dict = {d["src"]: d["dst"] for d in chunk}
|
glossary_dict = {d["src"]: d["dst"] for d in chunk}
|
||||||
result = result | glossary_dict
|
result = glossary_dict | result
|
||||||
except JSONDecodeError as e:
|
except JSONDecodeError as e:
|
||||||
self.logger.info(f"json解析错误,解析文本:{chunk},错误:{e.__repr__()}")
|
self.logger.info(f"json解析错误,解析文本:{chunk},错误:{e.__repr__()}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -73,4 +73,4 @@ $$1+1=2$$
|
|||||||
if self.glossary_dict is None:
|
if self.glossary_dict is None:
|
||||||
self.glossary_dict = {}
|
self.glossary_dict = {}
|
||||||
if update_dict is not None:
|
if update_dict is not None:
|
||||||
self.glossary_dict = self.glossary_dict | update_dict
|
self.glossary_dict = update_dict | self.glossary_dict
|
||||||
|
|||||||
@@ -148,8 +148,8 @@ Warning: Never wrap the entire JSON object in quotes to make it a single string.
|
|||||||
result.extend(ls[last_end:])
|
result.extend(ls[last_end:])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def update_glossary_dict(self, update_dict: dict|None):
|
def update_glossary_dict(self, update_dict: dict | None):
|
||||||
if self.glossary_dict is None:
|
if self.glossary_dict is None:
|
||||||
self.glossary_dict = {}
|
self.glossary_dict = {}
|
||||||
if update_dict is not None:
|
if update_dict is not None:
|
||||||
self.glossary_dict = self.glossary_dict | update_dict
|
self.glossary_dict = update_dict | self.glossary_dict
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ The translated txt text as plain text.
|
|||||||
async def send_chunks_async(self, prompts: list[str]):
|
async def send_chunks_async(self, prompts: list[str]):
|
||||||
return await super().send_prompts_async(prompts=prompts, pre_send_handler=self._pre_send_handler)
|
return await super().send_prompts_async(prompts=prompts, pre_send_handler=self._pre_send_handler)
|
||||||
|
|
||||||
def update_glossary_dict(self, update_dict: dict|None):
|
def update_glossary_dict(self, update_dict: dict | None):
|
||||||
if self.glossary_dict is None:
|
if self.glossary_dict is None:
|
||||||
self.glossary_dict = {}
|
self.glossary_dict = {}
|
||||||
if update_dict is not None:
|
if update_dict is not None:
|
||||||
self.glossary_dict = self.glossary_dict | update_dict
|
self.glossary_dict = update_dict | self.glossary_dict
|
||||||
|
|||||||
Reference in New Issue
Block a user