Skip to content

Commit

Permalink
Add file save option to get_translation_result method
Browse files Browse the repository at this point in the history
- Added optional `save_to_file` parameter to `get_translation_result`
- Implemented file saving logic for translation results
  • Loading branch information
cr2007 committed Jun 24, 2024
1 parent ae2d860 commit 569b98a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cambai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,5 +1210,15 @@ def get_translation_result(

if response.status_code != 200:
print("Error: There was an error with your GET request.")
return response.json()

if save_to_file:
# text_to_write = response.json()
with open(f"translation_result_{run_id}.txt", "w", encoding="utf-8") as file:
file.writelines([
"Camb AI Translation Result\n",
f"Run ID: {run_id}\n"
])
file.write(response.json()["text"])

return response.json()

0 comments on commit 569b98a

Please sign in to comment.