[WIP] Chatgpt api translator#9
Conversation
| @@ -0,0 +1,78 @@ | |||
| class ChatGPTTranslator { | |||
| constructor(model = 'gpt-4o', openApiKey = "") { | |||
There was a problem hiding this comment.
Can we use model gpt-4o-mini? It would save users money and it have quite good quality
| const prompt = (from === 'auto' || from === '') | ||
| ? `Translate text to ${to}. Only return the translation without any additional text:\n\n${text}` | ||
| : `Translate text from ${from} to ${to}. Only return the translation without any additional text:\n\n${text}`; |
There was a problem hiding this comment.
Let's generate batch requests to translate array of texts with method translateBatch and then call this method with single text in translate method.
This approach may improve performance dramatically, since Linguist mostly call translateBatch method with as many texts as possible.
If we have 1k texts to translate, in current implementation user would sent 1k requests with prompt overhead, but if we will batch texts, linguist will send 50-200 texts in single request and eventually will sent only 5-20 requests.
| console.error("Translation request failed:", error); | ||
| return ''; |
There was a problem hiding this comment.
If exception has occurs, we must throw an error, to handle it properly. Otherwise user will see empty text in translations and will be confused
| getLengthLimit() { | ||
| return 20000; | ||
| } |
There was a problem hiding this comment.
How you think is it optimal value?
Linguist uses this number to understand "can we put more text to current batch?" to translate as many texts as possible in single request.
How much chars ChatGPT can handle for single message?
| test('handles length limit correctly', () => { | ||
| const longText = 'a'.repeat(21000); | ||
| expect(translator.checkLimitExceeding(longText)).toBe(1); | ||
| expect(translator.checkLimitExceeding('short text')).toBe(0); | ||
| }); |
There was a problem hiding this comment.
This method must return the number of chars that is out of limit. It is necessary for Linguist batch scheduler to efficiently group texts by its size.
You may check example here
linguist-translators/translators/LibreTranslator.js
Lines 45 to 51 in 4e9c69c
I think in this test a first assert should expect 1000 (that means we have to cut at least 1k chars) and second one is -19990 (that means we can add up to 19990 characters, and still fit in single request)
You may use console log and maybe even Try to open There must be logs of custom translator module |
This is OpenAI API based translator module. Started at translate-tools/linguist#230
@vitonsky Any idea how to debug from inside
eval()?console.loganddebugger;both are just not working.