Cerlancism / chatgpt-subtitle-translator

Efficient translation tool based on ChatGPT API
https://cerlancism.github.io/chatgpt-subtitle-translator/
MIT License
145 stars 16 forks source link

Error with JSON parsing #2

Closed LiamK closed 1 year ago

LiamK commented 1 year ago

The subtitle translator is working pretty nicely, and the attention paid to backing off, and keeping numbers in sync is appreciated. Unfortunately, it threw an exception, which resulted in no file being generated. That's a bit unfortunate.
I can split the file up in pieces and run them separately, so I think that will be a workaround. I wonder, though, if it would be possible to update the output file incrementally. That would help when recovering from errors such as this. I'm happy to help debug this, however javascript is not my strongest language.

cli/translator.mjs --stream --temperature 0  --to Spanish --file ../translate/files/subtitle.srt 
...
node:internal/process/esm_loader:42
      internalBinding('errors').triggerUncaughtException(
                                ^
[Error_TranslationPrompt] Thu May 18 2023 17:50:19 GMT+0200 (Central European Summer Time) unknown error SyntaxError: Could not JSON parse stream message: Expected property name or '}' in JSON at position 151
(Use `node --trace-uncaught ...` to show where the exception was thrown)
Cerlancism commented 1 year ago

I am aware of this issue, will take a closer look. It seems to happen only in stream mode.

For incremental saving, it is already implemented (the output files consist of a csv file to keep track the progress, running the same command will pick it where it was left if it was interrupted by error or CTRL+C), however it will only update after a batch is successfully streamed completely (default every 100 lines). It appears that your request failed during the generation of the very first batch, therefore no file output is saved