代码格式化
This commit is contained in:
9
.idea/workspace.xml
generated
9
.idea/workspace.xml
generated
@@ -5,13 +5,8 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="6b18b44a-df57-4212-a857-9e291ebe5dd2" name="更改" comment="">
|
<list default="true" id="6b18b44a-df57-4212-a857-9e291ebe5dd2" name="更改" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/docutranslate/Agents/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/Agents/__init__.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/docutranslate/Agents/agent.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/Agents/agent.py" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/docutranslate/translater.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/translater.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/docutranslate/translater.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/translater.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/docutranslate/utils/markdown_splitter.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/utils/markdown_splitter.py" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pyproject.toml" beforeDir="false" afterPath="$PROJECT_DIR$/pyproject.toml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/uv.lock" beforeDir="false" afterPath="$PROJECT_DIR$/uv.lock" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -402,7 +397,7 @@
|
|||||||
<workItem from="1746788668813" duration="25000" />
|
<workItem from="1746788668813" duration="25000" />
|
||||||
<workItem from="1746791230782" duration="3129000" />
|
<workItem from="1746791230782" duration="3129000" />
|
||||||
<workItem from="1746799824552" duration="317000" />
|
<workItem from="1746799824552" duration="317000" />
|
||||||
<workItem from="1746801217905" duration="14612000" />
|
<workItem from="1746801217905" duration="14698000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -2,15 +2,17 @@ from pathlib import Path
|
|||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
import markdown2
|
import markdown2
|
||||||
# import mdformat
|
|
||||||
|
|
||||||
|
from docutranslate.Agents import Agent, AgentArgs
|
||||||
from docutranslate.Agents import MDRefineAgent, MDTranslateAgent
|
from docutranslate.Agents import MDRefineAgent, MDTranslateAgent
|
||||||
from docutranslate.Agents.agent import Agent, AgentArgs
|
|
||||||
from docutranslate.utils.convert import file2markdown_embed_images
|
from docutranslate.utils.convert import file2markdown_embed_images
|
||||||
from docutranslate.utils.markdown_splitter import split_markdown_text
|
from docutranslate.utils.markdown_splitter import split_markdown_text
|
||||||
from docutranslate.utils.markdown_utils import uris2placeholder, placeholder2_uris, MaskDict
|
from docutranslate.utils.markdown_utils import uris2placeholder, placeholder2_uris, MaskDict
|
||||||
|
|
||||||
|
|
||||||
|
# import mdformat
|
||||||
|
|
||||||
|
|
||||||
class FileTranslater:
|
class FileTranslater:
|
||||||
def __init__(self, file_path: Path | str | None = None, chunksize: int = 4096, base_url="", key=None,
|
def __init__(self, file_path: Path | str | None = None, chunksize: int = 4096, base_url="", key=None,
|
||||||
model_id="", temperature=0.7, max_concurrent=20, docling_artifact: Path | str | None = None,
|
model_id="", temperature=0.7, max_concurrent=20, docling_artifact: Path | str | None = None,
|
||||||
@@ -69,7 +71,8 @@ class FileTranslater:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def read_file(self, file_path: Path | str | None = None, formula=False, code=False, save=False,
|
def read_file(self, file_path: Path | str | None = None, formula=False, code=False, save=False,
|
||||||
save_format: Literal["markdown", "html"] = "markdown", refine=False, refine_agent:Agent|None=None):
|
save_format: Literal["markdown", "html"] = "markdown", refine=False,
|
||||||
|
refine_agent: Agent | None = None):
|
||||||
if file_path is None:
|
if file_path is None:
|
||||||
if self.file_path is None:
|
if self.file_path is None:
|
||||||
raise Exception("未设置文件路径")
|
raise Exception("未设置文件路径")
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import threading
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MaskDict:
|
class MaskDict:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._dict = {}
|
self._dict = {}
|
||||||
@@ -33,6 +32,7 @@ class MaskDict:
|
|||||||
with self._lock:
|
with self._lock:
|
||||||
return item in self._dict
|
return item in self._dict
|
||||||
|
|
||||||
|
|
||||||
# def uris2placeholder(markdown:str, mask_dict:MaskDict):
|
# def uris2placeholder(markdown:str, mask_dict:MaskDict):
|
||||||
##替换整个uri
|
##替换整个uri
|
||||||
# def uri2placeholder(match: re.Match):
|
# def uri2placeholder(match: re.Match):
|
||||||
@@ -54,6 +54,8 @@ def uris2placeholder(markdown:str, mask_dict:MaskDict):
|
|||||||
uri_pattern = r'(!?\[.*?\])\((.*?)\)'
|
uri_pattern = r'(!?\[.*?\])\((.*?)\)'
|
||||||
markdown = re.sub(uri_pattern, uri2placeholder, markdown)
|
markdown = re.sub(uri_pattern, uri2placeholder, markdown)
|
||||||
return markdown
|
return markdown
|
||||||
|
|
||||||
|
|
||||||
def placeholder2_uris(markdown: str, mask_dict: MaskDict):
|
def placeholder2_uris(markdown: str, mask_dict: MaskDict):
|
||||||
def placeholder2uri(match: re.Match):
|
def placeholder2uri(match: re.Match):
|
||||||
id = match.group(1)
|
id = match.group(1)
|
||||||
@@ -67,6 +69,5 @@ def placeholder2_uris(markdown:str, mask_dict:MaskDict):
|
|||||||
return markdown
|
return markdown
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user