-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
feat: add tui interactive interface to work with llm translation #1007
base: 3.13
Are you sure you want to change the base?
Conversation
Co-Authored-By: Becca <[email protected]>
def main(po_file_path: str): | ||
app = TranslationApp(Path(po_file_path)) | ||
app.run() | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
if len(sys.argv) > 1: | ||
main(sys.argv[1]) | ||
else: | ||
print("Please provide a PO file path") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def main(po_file_path: str): | |
app = TranslationApp(Path(po_file_path)) | |
app.run() | |
if __name__ == "__main__": | |
import sys | |
if len(sys.argv) > 1: | |
main(sys.argv[1]) | |
else: | |
print("Please provide a PO file path") | |
def main(po_file_path: str): | |
app = TranslationApp(po_file_path) | |
app.run() | |
if __name__ == "__main__": | |
import argparse | |
desc = 'TUI for LLM translations' | |
parser = argparse.ArgumentParser(description=desc) | |
parser.add_argument('po_file_path', type=Path, | |
help='Path to the PO file to translate') | |
args = parser.parse_args() | |
main(args.po_file_path) |
What about using argparse
instead of sys.argv
?
prompt = ("Translate the following Python documentation into Traditional Chinese" | ||
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid[1]}. Ensure " | ||
"that the translation is accurate and uses appropriate technical terminology. The" | ||
" output must be in Traditional Chinese. Pay careful attention to context, idiomatic" | ||
" expressions, and any specialized vocabulary related to Python programming. Maintain " | ||
"the structure and format of the original documentation as much as possible to ensure" | ||
" clarity and usability for readers.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prompt = ("Translate the following Python documentation into Traditional Chinese" | |
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid[1]}. Ensure " | |
"that the translation is accurate and uses appropriate technical terminology. The" | |
" output must be in Traditional Chinese. Pay careful attention to context, idiomatic" | |
" expressions, and any specialized vocabulary related to Python programming. Maintain " | |
"the structure and format of the original documentation as much as possible to ensure" | |
" clarity and usability for readers.") | |
prompt = ("Translate the following Python documentation into Traditional Chinese " | |
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid[1]}. Ensure " | |
"that the translation is accurate and uses appropriate technical terminology. The " | |
"output must be in Traditional Chinese. Pay careful attention to context, idiomatic " | |
"expressions, and any specialized vocabulary related to Python programming. Maintain " | |
"the structure and format of the original documentation as much as possible to ensure " | |
"clarity and usability for readers.") |
There's a missing space at the end of the first line that causes Chinesefor
to be merged together. While I was at it I made the spacing of the other lines consistent, by moving all the spaces at the end of the sentences.
else: | ||
self.notify("Failed to generate translation", severity="error") | ||
except Exception as e: | ||
self.notify(f"Error: {str(e)}", severity="error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.notify(f"Error: {str(e)}", severity="error") | |
self.notify(f"Error: {e}", severity="error") |
The str()
is not necessary here.
prompt = ("Translate the following Python documentation into Traditional Chinese" | ||
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid}. Ensure " | ||
"that the translation is accurate and uses appropriate technical terminology. The" | ||
" output must be in Traditional Chinese. Pay careful attention to context, idiomatic" | ||
" expressions, and any specialized vocabulary related to Python programming. Maintain " | ||
"the structure and format of the original documentation as much as possible to ensure" | ||
" clarity and usability for readers.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prompt = ("Translate the following Python documentation into Traditional Chinese" | |
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid}. Ensure " | |
"that the translation is accurate and uses appropriate technical terminology. The" | |
" output must be in Traditional Chinese. Pay careful attention to context, idiomatic" | |
" expressions, and any specialized vocabulary related to Python programming. Maintain " | |
"the structure and format of the original documentation as much as possible to ensure" | |
" clarity and usability for readers.") | |
prompt = ("Translate the following Python documentation into Traditional Chinese " | |
f"for {self.po_file_path}:{entry.occurrences} with message {entry.msgid}. Ensure " | |
"that the translation is accurate and uses appropriate technical terminology. The " | |
"output must be in Traditional Chinese. Pay careful attention to context, idiomatic " | |
"expressions, and any specialized vocabulary related to Python programming. Maintain " | |
"the structure and format of the original documentation as much as possible to ensure " | |
"clarity and usability for readers.") |
This has the same bug (Chinesefor
) as the other prompt. Since it looks duplicated, it might be better to factor it out, and reusing it in both places instead.
This pull request introduces a new interactive translation application using the
textual
framework and integrates Google Generative AI for translation tasks. It also includes updates to the dependencies in thepyproject.toml
file.New interactive translation application:
.scripts/interactive_translate/main.py
: Added a newTranslationApp
class using thetextual
framework to provide an interactive UI for translating PO files. The application supports navigation through entries, accepting translations, generating translations using Google Generative AI, and saving changes.Dependency updates:
.scripts/pyproject.toml
: Added new dependenciestextual
,powrap
, andgoogle-generativeai
to support the new translation application.