Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add tui interactive interface to work with llm translation#1007

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
josix wants to merge1 commit into3.13
base:3.13
Choose a base branch
Loading
fromfeat/llm-interactive-translation

Conversation

josix
Copy link
Collaborator

@josixjosix commentedDec 16, 2024
edited
Loading

This pull request introduces a new interactive translation application using thetextual 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.

image

ezio-melotti reacted with eyes emoji
Co-Authored-By: Becca <beccalin.8359@gmail.com>
Comment on lines +215 to +224
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
defmain(po_file_path:str):
app=TranslationApp(Path(po_file_path))
app.run()
if__name__=="__main__":
importsys
iflen(sys.argv)>1:
main(sys.argv[1])
else:
print("Please provide a PO file path")
defmain(po_file_path:str):
app=TranslationApp(po_file_path)
app.run()
if__name__=="__main__":
importargparse
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 usingargparse instead ofsys.argv?

Comment on lines +199 to +205
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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
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 causesChinesefor 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
self.notify(f"Error:{str(e)}",severity="error")
self.notify(f"Error:{e}",severity="error")

Thestr() is not necessary here.

Comment on lines +142 to +148
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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ezio-melottiezio-melottiezio-melotti left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@josix@ezio-melotti

[8]ページ先頭

©2009-2025 Movatter.jp