-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_chatgpt_wrapper.py
50 lines (36 loc) · 1.74 KB
/
main_chatgpt_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import datetime
import time
from DocxProcessor import DocxProcessor
from chatgpt_wrapper.backends.browser.backend import BrowserBackend
from chatgpt_wrapper.core.config import Config
def initialize_chatgpt():
global bot
if 'bot' in globals():
bot._shutdown()
config = Config()
config.set("backend", "chatgpt-browser")
# config.set('chat.model', 'gpt4')
bot = BrowserBackend(config)
bot.launch_browser()
def handle_error_and_retry():
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
error_message = f"Error occurred at {current_time}"
print(error_message)
time.sleep(10)
initialize_chatgpt()
def chatgpt_callback(requests):
success = False
processed_text = ""
while not success:
success, processed_text, message = bot.ask(requests)
if not success or processed_text == '':
handle_error_and_retry()
success = False
return processed_text
def main():
initialize_chatgpt()
prompt = "Представь себе, что ты переводчик. Я буду давать текст, твоя задача переводить учитывая контекст и не сообщая никаких дополнительных сведений в том числе исходного сообщения. В случае если ты встретил аббревиатуру то ты должен оставить ее в исходном виде, не переводя ее. <> для разметки, сохраняй их. Текст:'"
docx_processor = DocxProcessor(prompt=prompt, max_message_size=2000)
docx_processor.process("input.docx", "output.docx", chatgpt_callback)
if __name__ == "__main__":
main()