zengzzzzz / translate-epub-book-by-openai

translate epub book by the openai gpt-3.5-turbo api , like chatgpt translate function
MIT License
38 stars 8 forks source link

IndexError: list index out of range #2

Closed morris-y closed 1 year ago

morris-y commented 1 year ago

Any suggestions on this?

File "R:\...\make.py", line 148, in <module> e.translate_book()

File "R:\...\make.py", line 100, in translate_book c_p.string = c_p.text + translated_batch[j] IndexError: list index out of range

zengzzzzz commented 1 year ago

Thanks for your feedback. j comes from batch_p, batch_p is the input of the translate method, the length of translated_batch should be consistent, and there will be no list index out of range. It should be that when translate_batch executes the translate method, the number of translation results obtained is inconsistent with the number of batch_p. The possible reason is that when translating, the GPT API does not return as required. If you have a more specific example, we will be able to more accurately locate the problem.

morris-y commented 1 year ago

Thx for your advice. I tried with lemo.epub (text_books) two times lead to the same IndexError. Seems like a GPT API problem, will look into that direction.

zengzzzzz commented 1 year ago

I confirmed this problem, the structure we use when accessing openai is [a,b,c...], but occasionally openai will not return the [a,b,c...] structure as we expected , will use the [ab,c,...] structure, which will cause the array index to access out of bounds, and I will fix it later.

zengzzzzz commented 1 year ago

3 solved the problem

morris-y commented 1 year ago

The updated batch_p section has been tested without any issues and the translation has been successful. Thank you for keeping up the great work.