回退httpx版本,优化提示词(有关表格),修复了ai报错过多时卡死的问题
This commit is contained in:
@@ -175,7 +175,10 @@ from docutranslate.agents import MDTranslateAgent
|
||||
|
||||
translater = FileTranslater()
|
||||
|
||||
translate_agent = MDTranslateAgent(baseurl="<baseurl>", key="<key>", model_id="<model-id>",custom_prompt="Ordering Node全部翻译为排序节点")#这里必须指定baseurl\api-key\model_id
|
||||
translate_agent = MDTranslateAgent(baseurl="<baseurl>",
|
||||
key="<key>",
|
||||
model_id="<model-id>",
|
||||
custom_prompt="Ordering Node全部翻译为排序节点")#这里必须指定baseurl\api-key\model_id
|
||||
|
||||
translater.translate_file("<文件路径>", to_lang="中文",translate_agent=translate_agent)
|
||||
```
|
||||
@@ -292,4 +295,4 @@ translater = FileTranslater(base_url="<baseurl>",
|
||||
)
|
||||
```
|
||||
|
||||
> 对于llm功能,可以使用ollama或lm studio等方式本地部署。
|
||||
> 对于本地ai翻译功能,可以使用ollama或lm studio等方式本地部署。
|
||||
@@ -1,4 +1,4 @@
|
||||
__version__="0.2.41"
|
||||
__version__="0.2.42"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,9 +32,7 @@ class TotalErrorCounter:
|
||||
self.count += 1
|
||||
if self.count>MAX_TOTAL_ERROR_COUNT:
|
||||
translater_logger.info(f"错误响应过多")
|
||||
raise Exception("错误响应过多")
|
||||
self.lock.release()
|
||||
|
||||
return self.reach_limit()
|
||||
|
||||
def reach_limit(self):
|
||||
@@ -89,7 +87,7 @@ class Agent:
|
||||
{"role": "user", "content": prompt}
|
||||
],
|
||||
"temperature": temperature,
|
||||
"top_p": top_p
|
||||
"top_p": top_p,
|
||||
}
|
||||
return headers, data
|
||||
|
||||
@@ -121,7 +119,8 @@ class Agent:
|
||||
raise Exception(f"AI响应格式错误 (async): {repr(e)}")
|
||||
# 如果没有正常获取结果则重试
|
||||
if retry and retry_count < MAX_RETRY_COUNT:
|
||||
total_error_counter.add()
|
||||
if total_error_counter.add():
|
||||
return prompt
|
||||
translater_logger.info(f"正在重试,重试次数{retry_count}")
|
||||
await asyncio.sleep(0.5)
|
||||
return await self.send_async(prompt, system_prompt, retry=True, retry_count=retry_count + 1)
|
||||
@@ -187,12 +186,13 @@ class Agent:
|
||||
raise Exception(f"AI响应格式错误 (sync): {repr(e)}")
|
||||
# 如果没有正常获取结果则重试
|
||||
if retry and retry_count < MAX_RETRY_COUNT:
|
||||
total_error_counter.add()
|
||||
if total_error_counter.add():
|
||||
return prompt
|
||||
translater_logger.info(f"正在重试,重试次数{retry_count}")
|
||||
time.sleep(0.5)
|
||||
return self.send(prompt, system_prompt, retry=True, retry_count=retry_count + 1)
|
||||
else:
|
||||
translater_logger.error(f"达到重试次数上限,返回空行")
|
||||
translater_logger.error(f"达到重试次数上限")
|
||||
return prompt
|
||||
|
||||
def _send_prompt_count(self, prompt: str, system_prompt: None | str, count: PromptsCounter) -> str:
|
||||
|
||||
@@ -57,6 +57,7 @@ class MDTranslateAgent(Agent):
|
||||
不能改变形如<ph-xxxxxx>的占位符
|
||||
code、latex和HTML只翻译说明文字,其余保持原文
|
||||
公式无论长短必须表示为能被解析的合法latex公式,公式需被$或\\(\\)或$$正确包裹,如不正确则进行修正
|
||||
表格如果是table标签请改为普通表格写法,注意表格正确性
|
||||
去除、修正明显异常的字符、但不能改变原意
|
||||
引用参考文献时请严格保持原文,不要翻译。参考文献格式示例如下:
|
||||
[1] Author A, Author B. "Original Title". Journal, 2023.
|
||||
|
||||
@@ -4,7 +4,7 @@ description = "文件翻译工具"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
"httpx>=0.28.1",
|
||||
"httpx==0.27.2",
|
||||
"markdown2>=2.5.3",
|
||||
"fastapi[standard]>=0.115.12",
|
||||
|
||||
|
||||
9
uv.lock
generated
9
uv.lock
generated
@@ -340,7 +340,7 @@ dev = [
|
||||
requires-dist = [
|
||||
{ name = "docling", marker = "extra == 'docling'", specifier = ">=2.40.0" },
|
||||
{ name = "fastapi", extras = ["standard"], specifier = ">=0.115.12" },
|
||||
{ name = "httpx", specifier = ">=0.28.1" },
|
||||
{ name = "httpx", specifier = "==0.27.2" },
|
||||
{ name = "markdown2", specifier = ">=2.5.3" },
|
||||
{ name = "opencv-python", marker = "extra == 'docling'", specifier = ">=4.11.0.86" },
|
||||
]
|
||||
@@ -542,17 +542,18 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "httpx"
|
||||
version = "0.28.1"
|
||||
version = "0.27.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "anyio" },
|
||||
{ name = "certifi" },
|
||||
{ name = "httpcore" },
|
||||
{ name = "idna" },
|
||||
{ name = "sniffio" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/b1/df/48c586a5fe32a0f01324ee087459e112ebb7224f646c0b5023f5e79e9956/httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc", size = 141406 }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/78/82/08f8c936781f67d9e6b9eeb8a0c8b4e406136ea4c3d1f89a5db71d42e0e6/httpx-0.27.2.tar.gz", hash = "sha256:f7c2be1d2f3c3c3160d441802406b206c2b76f5947b11115e6df10c6c65e66c2", size = 144189 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/2a/39/e50c7c3a983047577ee07d2a9e53faf5a69493943ec3f6a384bdc792deb2/httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad", size = 73517 },
|
||||
{ url = "https://files.pythonhosted.org/packages/56/95/9377bcb415797e44274b51d46e3249eba641711cf3348050f76ee7b15ffc/httpx-0.27.2-py3-none-any.whl", hash = "sha256:7bb2708e112d8fdd7829cd4243970f0c223274051cb35ee80c03301ee29a3df0", size = 76395 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
Reference in New Issue
Block a user