ryanhex53 / gpt-po Goto Github PK
View Code? Open in Web Editor NEWcommand tool for translate po files by using openai api
command tool for translate po files by using openai api
I am trying to use this and read the .po file correctly (I think)
But it never get past this point: ░░░░░░░░░░░░░░░░░░░░ 0% 0/1419
I have two ideas to improve the dictionary:
1 - When the dictionary is large it returns an error:
400
{
error: {
message: "This model's maximum context length is 4097 tokens. However, your messages resulted in 5904 tokens. Please reduce the length of the messages.",
type: 'invalid_request_error',
param: 'messages',
code: 'context_length_exceeded'
}
}
I think that the dictionary is sent for each string to be translated, so it would be good to filter the dictionary with only the strings that contain the text to be translated.
2 - When I work with many languages I need to change dictionary to each language. It would be nice to use a dictionary for each language (e.g. dictionary-spanish.json
, dictionary-italian.json
, dictionary-simplified-chinese.json
) or to be able to pass the address of the dictionary through a parameter (e.g. gpt-po --po it_IT.po --lang "italian" --dic <dictionary>
).
Hi there, really useful project!
I did a couple of experiments and until now I only discovered one issue: GPT "thinks" it should create a draft instead of only translating the word.
this is the command I used:
gpt-po translate --po django.po --source german --lang english --verbose
content of django.po
:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-24 20:24+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: gpt-po v1.0.10\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: German\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: launcher/models.py:154
msgid "draft"
msgstr ""
and this is the output:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-24 20:24+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: gpt-po v1.0.10\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: German\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: launcher/models.py:154
msgid "draft"
msgstr ""
"Dear Sir/Madam,\n"
"\n"
"I hope this email finds you well. I am writing to provide you with a draft of the translation you requested. Please "
"find the translated text below:\n"
"\n"
"\"Sehr geehrte Damen und Herren,\n"
"\n"
"ich hoffe, diese E-Mail erreicht Sie in bester Verfassung. Ich schreibe Ihnen, um Ihnen einen Entwurf der von Ihnen "
"angeforderten Übersetzung zur Verfügung zu stellen. Bitte finden Sie den übersetzten Text unten:\n"
"\n"
"[Translated text]\n"
"\n"
"I hope this translation meets your expectations. If you have any further questions or require any revisions, please do "
"not hesitate to contact me. I am at your disposal to assist you with any additional language needs.\n"
"\n"
"Thank you for considering my services. I look forward to hearing from you soon.\n"
"\n"
"Best regards,\n"
"[Your Name]\""
The expected output would have been the translation of the word "draft" (German: "Entwurf")
OpenAI pushed a new version (v4).
The project doesn't work anymore:
Module '"openai"' has no exported member 'ChatCompletionRequestMessageRoleEnum'
Hey, thanks for this project, it saved me from the apocalypse.
I found a strange translation. The original string was "Want this emailed to you?"
, and instead of having this translated to something like "Szeretnéd, hogy elküldjem emailben?"
, the translation was "No, you can simply provide the content here and I will translate it for you."
, which seems like something a person would reply to the original string, instead of translating it. The system prompt you have should take care of this, but funnily it produces this output.
gpt-po uses home directory as base instead of the git repo I am currently in, or the current working directory to save systemprompt and dictionary. That makes customizations saved globally instead of specific to each project.
To be useable in a multi projects context, they should be saved in the git repo if found, or in the current directory, again, as hidden files or in a hidden folder (translation is rarely "the" project, it's a feature added to it).
To at least use these file if they exist, without altering your current behaviour otherwise, something like this could do the trick:
// ...
import { homedir } from "os";
import { join } from "path";
import fs from "fs";
import gitRootDir from "git-root-dir";
// ...
const getFirstFound = (fileName) => {
const currentDir = process.cwd();
const gitRoot = gitRootDir() || currentDir;
const home = homedir();
const filePaths = [
join(currentDir, ".gpt-po", fileName), // (current directory)/.gpt-po/
join(gitRoot, ".gpt-po", fileName), // (git repository root directory)/.gpt-po/
join(home, ".gpt-po", fileName), // ~/.gpt-po/
join("/etc/gpt-po", fileName), // /etc/gpt-po/
];
for (const filePath of filePaths) {
if (fs.existsSync(filePath)) {
return filePath;
}
}
// Return join(home, fileName) as fallback if nothing is found
return join(home, fileName);
};
// ... (Rest of the code)
//
// const promptHome = getFirstFound("systemprompt.txt");
//
// ... (Rest of the code)
As I have multiple projects (and translation management is not supposed to be included in them), I installed gpt-po globally, but I saw in the code that homedir() was used to save the files anyway.
And IMHO an application should never save config as visible files in home directory anyway (particularly with names as vague as "dictionary.json"). This is a place we have a hard time to maintain organized, so global config and preference files should be saved as dot files (.gpt-po/systemprompt) or in the standard /.config/ directory (/.config/gpt-po/systemprompt).
That said, it's a great project, it helps me a lot.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.