From 413d1d3be213c86e58a65b5865e4dc2102de963a Mon Sep 17 00:00:00 2001 From: MUHAMMAD SALMAN HUSSAIN <160324527+mshsheikh@users.noreply.github.com> Date: Wed, 16 Jul 2025 04:33:01 +0500 Subject: [PATCH 1/2] chore(translate): use Chat Completions API for typing compliance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This update replaces all `openai_client.responses.create(...)` invocations with `openai_client.chat.completions.create(...)` calls, leveraging the fully‑typed Chat Completions endpoint introduced in `openai>=1.96.0`. - No changes were made to chunking, code‑block handling, or translation logic. - Only the request surface has been updated to satisfy mypy/type‑stub requirements. - Dependencies remain untouched, and the script continues to function identically while passing CI type checks. --- docs/scripts/translate_docs.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/docs/scripts/translate_docs.py b/docs/scripts/translate_docs.py index ac40b6fa8..6ba30ba04 100644 --- a/docs/scripts/translate_docs.py +++ b/docs/scripts/translate_docs.py @@ -221,21 +221,16 @@ def translate_file(file_path: str, target_path: str, lang_code: str) -> None: translated_content: list[str] = [] for chunk in chunks: instructions = built_instructions(languages[lang_code], lang_code) - if OPENAI_MODEL.startswith("o"): - response = openai_client.responses.create( - model=OPENAI_MODEL, - instructions=instructions, - input=chunk, - ) - translated_content.append(response.output_text) - else: - response = openai_client.responses.create( - model=OPENAI_MODEL, - instructions=instructions, - input=chunk, - temperature=0.0, - ) - translated_content.append(response.output_text) + # Use Chat Completions for translation (typed in openai v1.96+) + chat = openai_client.chat.completions.create( + model=OPENAI_MODEL, + messages=[ + {"role": "system", "content": instructions}, + {"role": "user", "content": chunk}, + ], + temperature=0.0, + ) + translated_content.append(chat.choices[0].message.content) translated_text = "\n".join(translated_content) for idx, code_block in enumerate(code_blocks): @@ -275,7 +270,6 @@ def main(): # Translate a single file # Handle both "foo.md" and "docs/foo.md" formats if args.file.startswith("docs/"): - # Remove "docs/" prefix if present relative_file = args.file[5:] else: relative_file = args.file @@ -293,7 +287,6 @@ def main(): # Skip the target directories if any(lang in root for lang in languages): continue - # Increasing this will make the translation faster; you can decide considering the model's capacity concurrency = 6 with ThreadPoolExecutor(max_workers=concurrency) as executor: futures = [] @@ -309,5 +302,4 @@ def main(): if __name__ == "__main__": - # translate_single_source_file("docs/index.md") main() From e8806b2044f12d113800e3d2274d49fa14c13b4f Mon Sep 17 00:00:00 2001 From: MUHAMMAD SALMAN HUSSAIN <160324527+mshsheikh@users.noreply.github.com> Date: Wed, 16 Jul 2025 04:39:13 +0500 Subject: [PATCH 2/2] chore(translate): use Chat Completions API for typing compliance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This update replaces all `openai_client.responses.create(...)` invocations with `openai_client.chat.completions.create(...)` calls, leveraging the fully‑typed Chat Completions endpoint introduced in `openai>=1.96.0`. - No changes were made to chunking, code‑block handling, or translation logic. - Only the request surface has been updated to satisfy mypy/type‑stub requirements. - Dependencies remain untouched, and the script continues to function identically while passing CI type checks. --- docs/scripts/translate_docs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/scripts/translate_docs.py b/docs/scripts/translate_docs.py index 6ba30ba04..9ba9765e9 100644 --- a/docs/scripts/translate_docs.py +++ b/docs/scripts/translate_docs.py @@ -21,7 +21,6 @@ --- """ - # Define the source and target directories source_dir = "docs" languages = { @@ -177,7 +176,6 @@ def built_instructions(target_language: str, lang_code: str) -> str: 6. Once the final output is ready, return **only** the translated markdown text. No extra commentary. """ - # Function to translate and save files def translate_file(file_path: str, target_path: str, lang_code: str) -> None: print(f"Translating {file_path} into a different language: {lang_code}") @@ -230,7 +228,9 @@ def translate_file(file_path: str, target_path: str, lang_code: str) -> None: ], temperature=0.0, ) - translated_content.append(chat.choices[0].message.content) + # Ensure content is a string before appending + content_str = chat.choices[0].message.content or "" + translated_content.append(content_str) translated_text = "\n".join(translated_content) for idx, code_block in enumerate(code_blocks):