更新json工作流readme

This commit is contained in:
xunbu
2025-08-04 11:48:30 +08:00
parent 8f918e596b
commit 0c9acf7da0
5 changed files with 62 additions and 9 deletions

View File

@@ -162,6 +162,7 @@ class Agent:
) -> list[str]:
max_concurrent = self.max_concurrent if max_concurrent is None else max_concurrent
total = len(prompts)
self.logger.info(f"收到{total}个片段,并发请求数:{max_concurrent}")
count = 0
semaphore = asyncio.Semaphore(max_concurrent)
tasks = []
@@ -231,6 +232,8 @@ class Agent:
prompts: list[str],
system_prompt: str | None = None,
) -> list[str]:
self.logger.info(f"收到{len(prompts)}个片段,并发请求数:{self.max_concurrent}")
system_prompts = [system_prompt] * len(prompts)
counts = [PromptsCounter(len(prompts), self.logger)] * len(prompts)
output_list = []

View File

@@ -16,19 +16,21 @@ class JsonTranslateAgent(Agent):
# 角色
你是一个专业的机器翻译引擎
# 工作
翻译输入的json的值保持键不改变
你接收一个待翻译片段的序列以json格式表示。其中键是待片段的编号值是待翻译片段。
你需要将待翻译片段翻译成目标语言。
目标语言:{config.to_lang}
# 要求
翻译要求专业准确
不输出任何解释和注释
如果已经是目标语言,则保持原样
翻译后的片段应该与源格式尽量相同
如果待翻译片段已经是目标语言,则保持原样
# 输出
翻译后的json纯文本
翻译后的片段序列以json格式表示。其中键是片段编号值是翻译后的片段
# 示例
## 输入
{r'{"1":"hello","2":"apple","3":true,"4":"false"}'}
{r'{"0":"hello","1":"apple","2":true,"3":"false"}'}
## 输出
{r'{"1":"你好","2":"苹果","3":true,"4":"错误"}'}
{r'{"0":"你好","1":"苹果","2":true,"3":"错误"}'}
"""
if config.custom_prompt:
self.system_prompt += "\n# 重要规则或背景【非常重要】\n" + config.custom_prompt + '\n'

File diff suppressed because one or more lines are too long

View File

@@ -2,7 +2,7 @@ import json
from dataclasses import dataclass
from typing import Self, Any
from jsonpath_ng import parse
from jsonpath_ng.ext import parse
from docutranslate.agents.segments_agent import JsonTranslateAgentConfig, JsonTranslateAgent
from docutranslate.ir.document import Document