bilingual_book_maker icon indicating copy to clipboard operation
bilingual_book_maker copied to clipboard

optimize sleep time

Open goldengrape opened this issue 1 year ago • 1 comments

https://github.com/yihong0618/bilingual_book_maker/blob/0dd61e5b3e6a82b20b6fc6244e2878a2963556db/book_maker/translator/chatgptapi_translator.py#L79

Regarding the optimization of sleeptime, it can be linearly increasing (+=10) and exponentially decreasing ( /=2 ). For your consideration.

sleeptime=60 ....

while True:
        try:
            t_text = self.get_translation(text)
            sleeptime=int(sleeptime/2) #exponentially decreasing
            sleeptime=5 if sleeptime<5 else sleeptime # sleep time >=5sec
            break
        except Exception as e:
            # todo: better sleep time? 
            print(e, f"will sleep {sleep_time} seconds")
            time.sleep(sleep_time)
            sleeptime = sleeptime+10 #linearly increasing
            if sleeptime >=120:
                    print("sleep too much, I give up")
                    break

goldengrape avatar Mar 13 '23 20:03 goldengrape

应该能加快翻译的速度,希望能提交pr

GoTop avatar Mar 16 '23 03:03 GoTop