agent增加system_proxy_enable参数

This commit is contained in:
xunbu
2025-09-23 23:53:49 +08:00
parent 760b1b36dd
commit f611468a13
10 changed files with 83 additions and 72 deletions

View File

@@ -48,6 +48,7 @@ class AgentConfig:
timeout: int = 1200 # 单位(秒)这个值是httpx.TimeOut中read的值,并非总的超时时间
thinking: ThinkingMode = "disable"
retry: int = 2
system_proxy_enable: bool = USE_PROXY
class TotalErrorCounter:
@@ -248,6 +249,7 @@ class Agent:
self.retry = config.retry
self.system_proxy_enable=config.system_proxy_enable
def _add_thinking_mode(self, data: dict):
if self.domain not in self._think_factory:
return
@@ -459,7 +461,7 @@ class Agent:
semaphore = asyncio.Semaphore(max_concurrent)
tasks = []
proxies = get_httpx_proxies() if USE_PROXY else None
proxies = get_httpx_proxies() if self.system_proxy_enable else None
limits = httpx.Limits(
max_connections=self.max_concurrent * 2, # 为重试和并发预留空间
@@ -710,7 +712,7 @@ class Agent:
max_connections=self.max_concurrent * 2, # 允许连接复用
max_keepalive_connections=self.max_concurrent, # 保持活跃连接
)
proxies = get_httpx_proxies() if USE_PROXY else None
proxies = get_httpx_proxies() if self.system_proxy_enable else None
with httpx.Client(
trust_env=False, proxies=proxies, verify=False, limits=limits
) as client:

View File

@@ -38,7 +38,8 @@ class AssTranslator(AiTranslator):
timeout=config.timeout,
logger=self.logger,
glossary_dict=config.glossary_dict,
retry=config.retry
retry=config.retry,
system_proxy_enable=config.system_proxy_enable
)
self.translate_agent = SegmentsTranslateAgent(agent_config)
self.insert_mode = config.insert_mode

View File

@@ -53,7 +53,8 @@ class DocxTranslator(AiTranslator):
timeout=config.timeout,
logger=self.logger,
glossary_dict=config.glossary_dict,
retry=config.retry
retry=config.retry,
system_proxy_enable=config.system_proxy_enable
)
self.translate_agent = SegmentsTranslateAgent(agent_config)
self.insert_mode = config.insert_mode

View File

@@ -44,7 +44,8 @@ class EpubTranslator(AiTranslator):
timeout=config.timeout,
logger=self.logger,
glossary_dict=config.glossary_dict,
retry=config.retry
retry=config.retry,
system_proxy_enable=config.system_proxy_enable
)
self.translate_agent = SegmentsTranslateAgent(agent_config)
self.insert_mode = config.insert_mode

View File

@@ -101,7 +101,8 @@ class HtmlTranslator(AiTranslator):
timeout=config.timeout,
logger=self.logger,
glossary_dict=config.glossary_dict,
retry=config.retry
retry=config.retry,
system_proxy_enable=config.system_proxy_enable
)
self.translate_agent = SegmentsTranslateAgent(agent_config)
self.insert_mode = config.insert_mode

View File

@@ -34,7 +34,8 @@ class JsonTranslator(AiTranslator):
timeout=config.timeout,
logger=self.logger,
glossary_dict=config.glossary_dict,
retry=config.retry
retry=config.retry,
system_proxy_enable=config.system_proxy_enable
)
self.translate_agent = SegmentsTranslateAgent(agent_config)
self.json_paths = config.json_paths

View File

@@ -34,7 +34,8 @@ class MDTranslator(AiTranslator):
timeout=config.timeout,
logger=self.logger,
glossary_dict=config.glossary_dict,
retry=config.retry)
retry=config.retry,
system_proxy_enable=config.system_proxy_enable)
self.translate_agent = MDTranslateAgent(agent_config)
def translate(self, document: MarkdownDocument) -> Self:

View File

@@ -40,7 +40,8 @@ class SrtTranslator(AiTranslator):
timeout=config.timeout,
logger=self.logger,
glossary_dict=config.glossary_dict,
retry=config.retry
retry=config.retry,
system_proxy_enable=config.system_proxy_enable
)
self.translate_agent = SegmentsTranslateAgent(agent_config)
self.insert_mode = config.insert_mode

View File

@@ -58,7 +58,8 @@ class TXTTranslator(AiTranslator):
timeout=config.timeout,
logger=self.logger,
glossary_dict=config.glossary_dict,
retry=config.retry
retry=config.retry,
system_proxy_enable=config.system_proxy_enable
)
self.translate_agent = SegmentsTranslateAgent(agent_config)
self.insert_mode = config.insert_mode

View File

@@ -42,7 +42,8 @@ class XlsxTranslator(AiTranslator):
timeout=config.timeout,
logger=self.logger,
glossary_dict=config.glossary_dict,
retry=config.retry
retry=config.retry,
system_proxy_enable=config.system_proxy_enable
)
self.translate_agent = SegmentsTranslateAgent(agent_config)
self.insert_mode = config.insert_mode