修复不能使用用户术语表的问题
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# SPDX-License-Identifier: MPL-2.0
|
# SPDX-License-Identifier: MPL-2.0
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import TypeVar
|
from typing import TypeVar, Dict
|
||||||
|
|
||||||
from docutranslate.agents.agent import AgentConfig
|
from docutranslate.agents.agent import AgentConfig
|
||||||
from docutranslate.agents.glossary_agent import GlossaryAgentConfig, GlossaryAgent
|
from docutranslate.agents.glossary_agent import GlossaryAgentConfig, GlossaryAgent
|
||||||
@@ -24,6 +24,7 @@ class AiTranslatorConfig(TranslatorConfig, AgentConfig):
|
|||||||
custom_prompt: str | None = None
|
custom_prompt: str | None = None
|
||||||
chunk_size: int = 3000
|
chunk_size: int = 3000
|
||||||
glossary: Glossary | None = None
|
glossary: Glossary | None = None
|
||||||
|
glossary_dict: Dict[str, str] | None = None
|
||||||
glossary_generate_enable: bool = False
|
glossary_generate_enable: bool = False
|
||||||
glossary_agent_config: GlossaryAgentConfig | None = None
|
glossary_agent_config: GlossaryAgentConfig | None = None
|
||||||
skip_translate: bool = False # 当skip_translate为False时base_url、model_id为必填项
|
skip_translate: bool = False # 当skip_translate为False时base_url、model_id为必填项
|
||||||
@@ -40,25 +41,38 @@ class AiTranslator(Translator[T]):
|
|||||||
def __init__(self, config: AiTranslatorConfig):
|
def __init__(self, config: AiTranslatorConfig):
|
||||||
super().__init__(config=config)
|
super().__init__(config=config)
|
||||||
self.skip_translate = config.skip_translate
|
self.skip_translate = config.skip_translate
|
||||||
self.glossary = config.glossary if config.glossary else Glossary()
|
|
||||||
|
|
||||||
|
if config.glossary:
|
||||||
|
self.glossary = config.glossary
|
||||||
|
elif config.glossary_dict:
|
||||||
|
self.glossary = Glossary(glossary_dict=config.glossary_dict)
|
||||||
|
else:
|
||||||
|
self.glossary = Glossary()
|
||||||
|
|
||||||
self.glossary_agent = None
|
self.glossary_agent = None
|
||||||
if not self.skip_translate and (
|
if not self.skip_translate and (
|
||||||
config.base_url is None or config.api_key is None or config.model_id is None
|
config.base_url is None or config.api_key is None or config.model_id is None
|
||||||
):
|
):
|
||||||
raise ValueError(
|
raise ValueError("skip_translate不为false时,base_url、api_key、model_id为必填项")
|
||||||
"skip_translate不为false时,base_url、api_key、model_id为必填项"
|
|
||||||
)
|
|
||||||
|
|
||||||
if config.glossary_generate_enable:
|
if config.glossary_generate_enable:
|
||||||
if config.glossary_agent_config:
|
if config.glossary_agent_config:
|
||||||
self.glossary_agent = GlossaryAgent(config.glossary_agent_config)
|
self.glossary_agent = GlossaryAgent(config.glossary_agent_config)
|
||||||
else:
|
else:
|
||||||
glossary_agent_config = GlossaryAgentConfig(
|
glossary_agent_config = GlossaryAgentConfig(
|
||||||
to_lang=config.to_lang, base_url=config.base_url,
|
to_lang=config.to_lang,
|
||||||
api_key=config.api_key, model_id=config.model_id, temperature=config.temperature,
|
base_url=config.base_url,
|
||||||
thinking=config.thinking, concurrent=config.concurrent, timeout=config.timeout,
|
api_key=config.api_key,
|
||||||
logger=self.logger, retry=config.retry,
|
model_id=config.model_id,
|
||||||
system_proxy_enable=config.system_proxy_enable, force_json=config.force_json,
|
temperature=config.temperature,
|
||||||
|
thinking=config.thinking,
|
||||||
|
concurrent=config.concurrent,
|
||||||
|
timeout=config.timeout,
|
||||||
|
logger=self.logger,
|
||||||
|
retry=config.retry,
|
||||||
|
system_proxy_enable=config.system_proxy_enable,
|
||||||
|
force_json=config.force_json,
|
||||||
rpm=config.rpm,
|
rpm=config.rpm,
|
||||||
tpm=config.tpm,
|
tpm=config.tpm,
|
||||||
provider=config.provider,
|
provider=config.provider,
|
||||||
|
|||||||
4
更新日志.txt
4
更新日志.txt
@@ -1,13 +1,13 @@
|
|||||||
更新日志
|
更新日志
|
||||||
----------------
|
----------------
|
||||||
v1.6.1版 2025.1.9
|
v1.6.1版 2025.1.10
|
||||||
特性
|
特性
|
||||||
- 支持mineruv2.7.1版本
|
- 支持mineruv2.7.1版本
|
||||||
- pdf生成的html带有目录
|
- pdf生成的html带有目录
|
||||||
- 自动生成术语表不覆盖用户术语表,最终下载的是合并术语表
|
- 自动生成术语表不覆盖用户术语表,最终下载的是合并术语表
|
||||||
优化
|
优化
|
||||||
- 其它优化
|
|
||||||
- 移除tiktoken依赖
|
- 移除tiktoken依赖
|
||||||
|
- 其它优化
|
||||||
----------------
|
----------------
|
||||||
v1.6.0版 2025.12.31
|
v1.6.0版 2025.12.31
|
||||||
特性
|
特性
|
||||||
|
|||||||
Reference in New Issue
Block a user