machinewrapped / gpt-subtrans

Open Source project using LLMs to translate SRT subtitles
Other
347 stars 40 forks source link

Solution for OpenAI free user? #68

Closed haitranvua closed 1 year ago

haitranvua commented 1 year ago

I am using your source code and it is working great. However, I am using a free OpenAI API, I am often limited in some uses (because the .srt file is quite large, 500~600 subtitle lines). I came up with this I don't know if it's stupid, but if I have multiple free APIs, is there a way to edit the source code so that each time it is limited, the function will automatically change to the next API.

machinewrapped commented 1 year ago

Hi, that's not a bad idea - though if I recall correctly you need a verified phone number to get the free credit, so it might be difficult to put into practise.

If you want to try it, the api key is currently set in the init method of SubtitleTranslator:

openai.api_key = options.api_key() or openai.api_key

You could initialise a list of api keys instead, e.g.

self.api_keys = ["Key1", "Key2", "Key3", "Key4"]

Then modify TranslateBatches in the same class to set a new api key for each batch, something like:

openai.api_key = self.api_keys[0]
self.api_keys = self.api_keys[1:] + self.api_keys[0]

This would cycle through the list using each key in turn then looping back to the first.

It's possible the API checks IP addresses to prevent things like this, of course.