diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1dcb91a..43bf8dc 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,12 @@
-
+
+
+
+
+
+
@@ -301,7 +306,10 @@
-
+
+
+
+
@@ -311,7 +319,7 @@
-
+
diff --git a/docutranslate/translater.py b/docutranslate/translater.py
index 1176195..bcc420f 100644
--- a/docutranslate/translater.py
+++ b/docutranslate/translater.py
@@ -62,7 +62,7 @@ class FileTranslater:
applications and scenarios becoming more and more extensive.
Blockchain's origination was Bitcoin, the most successful of the digital currencies (cryptocurrencies). Since 1983, when digital currency was first proposed, the Internet has continued to burgeon, with its
输出:
-Blockchain's origination was Bitcoin, the most successful of the digital currencies (cryptocurrencies). Since 1983, when digital currency was first proposed, the Internet has continued to burgeon, with its applications and scenarios becoming more and more extensive.
+Blockchain's origination was Bitcoin, the most successful of the digital currencies (cryptocurrencies). Since 1983, when digital currency was first proposed, the Internet has continued to burgeon, with its applications and scenarios becoming more and more extensive.【answer-end】
## 去掉异常字词
输入:
你@好,你叫什么\名#字
diff --git a/docutranslate/utils/agent_utils.py b/docutranslate/utils/agent_utils.py
index 8cfcab1..d86d19d 100644
--- a/docutranslate/utils/agent_utils.py
+++ b/docutranslate/utils/agent_utils.py
@@ -1,4 +1,5 @@
import asyncio
+import re
import httpx
@@ -15,7 +16,7 @@ class Agent:
self.client_async = httpx.AsyncClient()
self.max_concurrent = max_concurrent
- def _prepare_request_data(self, prompt, system_prompt, temperature=None, top_p=0.9):
+ def _prepare_request_data(self, prompt:str, system_prompt:str, temperature=None, top_p=0.9):
if temperature is None:
temperature = self.temperature
headers = {"Content-Type": "application/json",
@@ -23,7 +24,7 @@ class Agent:
data = {
"model": self.model_id,
"messages": [
- {"role": "system", "content": system_prompt},
+ {"role": "system", "content": "所有回复必须严格以<>开头,包括简短回答。示例:\n<>这是示例回答\n"+system_prompt},
{"role": "user", "content": prompt}
],
"temperature": temperature,
@@ -52,8 +53,14 @@ class Agent:
timeout=timeout
)
response.raise_for_status()
- result: str = response.json()["choices"][0]["message"]["content"]
- return result.lstrip()
+ result=response.json()["choices"][0]["message"]["content"]
+ pattern=r"<>(.*)"
+ match= re.search(pattern,result, re.DOTALL)
+ if match is None:
+ print("检测开头<失败")
+ else:
+ result=match.group(1)
+ return result
except httpx.HTTPStatusError as e:
raise Exception(f"AI请求错误 (async): {e.response.status_code} - {e.response.text}") from e
except httpx.RequestError as e:
diff --git a/pyproject.toml b/pyproject.toml
index 3a754c9..488f1c8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "docutranslate"
-version = "0.0.3"
+version = "0.0.4"
description = "能翻译pdf和markdown的软件"
readme = "README.md"
requires-python = ">=3.10"
@@ -10,4 +10,3 @@ dependencies = [
"markdown2>=2.5.3",
"transformers>=4.42.4",
]
-