mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-23 05:19:46 -05:00
Compare commits
2 Commits
Update-emb
...
integrate-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
174a3e0976 | ||
|
|
2a0d5ee2af |
@@ -10,6 +10,7 @@ from typing import Annotated
|
|||||||
import git
|
import git
|
||||||
import typer
|
import typer
|
||||||
import yaml
|
import yaml
|
||||||
|
from doc_parsing_utils import check_translation
|
||||||
from github import Github
|
from github import Github
|
||||||
from pydantic_ai import Agent
|
from pydantic_ai import Agent
|
||||||
from rich import print
|
from rich import print
|
||||||
@@ -119,9 +120,30 @@ def translate_page(
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
prompt = "\n\n".join(prompt_segments)
|
prompt = "\n\n".join(prompt_segments)
|
||||||
print(f"Running agent for {out_path}")
|
|
||||||
result = agent.run_sync(prompt)
|
MAX_ATTEMPTS = 3
|
||||||
out_content = f"{result.output.strip()}\n"
|
for attempt_no in range(1, MAX_ATTEMPTS + 1):
|
||||||
|
print(f"Running agent for {out_path} (attempt {attempt_no}/{MAX_ATTEMPTS})")
|
||||||
|
result = agent.run_sync(prompt)
|
||||||
|
out_content = f"{result.output.strip()}\n"
|
||||||
|
try:
|
||||||
|
check_translation(
|
||||||
|
doc_lines=out_content.splitlines(),
|
||||||
|
en_doc_lines=original_content.splitlines(),
|
||||||
|
lang_code=language,
|
||||||
|
auto_fix=False,
|
||||||
|
path=str(out_path),
|
||||||
|
)
|
||||||
|
break # Exit loop if no errors
|
||||||
|
except ValueError as e:
|
||||||
|
print(
|
||||||
|
f"Translation check failed on attempt {attempt_no}/{MAX_ATTEMPTS}: {e}"
|
||||||
|
)
|
||||||
|
continue # Retry if not reached max attempts
|
||||||
|
else: # Max retry attempts reached
|
||||||
|
print(f"Translation failed for {out_path} after {MAX_ATTEMPTS} attempts")
|
||||||
|
raise typer.Exit(code=1)
|
||||||
|
|
||||||
print(f"Saving translation to {out_path}")
|
print(f"Saving translation to {out_path}")
|
||||||
out_path.write_text(out_content, encoding="utf-8", newline="\n")
|
out_path.write_text(out_content, encoding="utf-8", newline="\n")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user