Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an option to create a draft translation with GPT #133

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
87 changes: 84 additions & 3 deletions docassemble/ALDashboard/data/questions/generate_translation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,49 @@ metadata:
title: |
Translation support tool
---
mandatory: True
code: |
the_yaml_path
if not the_task.ready():
waiting_screen
if the_task.failed():
error_screen
show_translation_results
---
# code: |
# translations = [
# translation_file(the_yaml_path, tr_lang, use_gpt=use_gpt)
# for tr_lang
# in tr_langs.split()
# ]
---
code: |
the_task = background_action('translate_file')
---
event: waiting_screen
question: |
Please wait while we translate your file
subquestion: |
<div class="spinner-border" role="status">
<span class="visually-hidden">Processing...</span>
</div>
reload: True
---
event: translate_file
code: |
background_error_action('bg_fail', stage='calculation')
translations = [
translation_file(the_yaml_path, tr_lang)
translation_file(the_yaml_path, tr_lang, use_gpt=use_gpt, openai_api=get_config("openai api key", get_config("open ai", {}).get("key")))
for tr_lang
in tr_langs.split()
]
background_response_action('save_translations', translations=translations)
---
event: save_translations
code: |
background_error_action('bg_fail', stage='saving')
translations = action_argument('translations')
background_response()
---
question: |
What file do you want to translate?
Expand All @@ -28,8 +65,19 @@ fields:
]
- "Language codes (like: es, one per line)": tr_langs
datatype: area
- Include a draft translation with GPT or Google Translate: use_gpt
datatype: yesno
show if:
code: |
gpt_is_available() # or google_translate_is_available()
- note: |
To use OpenAI's GPT-3, you need to set up an OpenAI account and get an API key.
show if:
code: |
not gpt_is_available()

---
mandatory: True
event: show_translation_results
question: |
Translation results
subquestion: |
Expand All @@ -42,4 +90,37 @@ subquestion: |
Number of untranslated rows: ${ translations[index].untranslated_segments }

Percentage of rows that are not translated: %${ translations[index].untranslated_segments/translations[index].total_rows * 100 }
% endfor
% endfor
---
event: bg_fail
code: |
errmess = "Failure at the " \
+ action_argument('stage') \
+ " stage due to a " \
+ action_argument('error_type') \
+ " error"
background_response('handled_error')
---
event: error_screen
question: |
There was an error.
subquestion: |
The saved error message was
${ errmess }.

The value was
`${ the_task.get() }`.

The error was
`${ the_task.result().error_type }`.

The trace was

${ indent(the_task.result().error_trace) }

The message was

${ indent(the_task.result().error_message) }

The variables were
`${ repr(the_task.result().variables) }`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
mandatory: True
code: |
intro_screen
show_results
---
modules:
- .translation
---
code: |
example_strings = {
0: "The quick brown fox jumps over the lazy dog.",
20: "Your name",
22: "${ users[0] }'s birthdate is"
}
---
question: |
Click to send the dictionary to GPT-3.5-turbo-1106
subquestion: |
${ repr(example_strings) }
continue button field: intro_screen
---
continue button field: show_results
question: |
Here are the results
subquestion: |
${ repr(translate_fragments_gpt(example_strings, "en", "fr")) }
6 changes: 3 additions & 3 deletions docassemble/ALDashboard/package_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def fetch_github_repo_version(repo_list, key_pkgs, github_user) -> dict:
version_num = decoded_line[str_start:str_end][9:].replace(
"',\n", ""
)
v[
"version"
] = version_num # Add version number to the original repo_list.
v["version"] = (
version_num # Add version number to the original repo_list.
)
has_version_num = True
break

Expand Down
Loading
Loading