2023-05-19 18:12:02 +08:00
|
|
|
|
from revChatGPT.V1 import Chatbot
|
|
|
|
|
from core.content_db import Content_Db
|
|
|
|
|
from utils import config_util as cfg
|
2023-05-27 17:03:43 +08:00
|
|
|
|
import time
|
2023-05-19 18:12:02 +08:00
|
|
|
|
|
2023-05-27 17:03:43 +08:00
|
|
|
|
count = 0
|
2023-05-19 18:12:02 +08:00
|
|
|
|
def question(cont):
|
2023-05-27 17:03:43 +08:00
|
|
|
|
global count
|
2023-05-19 18:12:02 +08:00
|
|
|
|
try:
|
|
|
|
|
chatbot = Chatbot(config={
|
2023-05-23 00:49:31 +08:00
|
|
|
|
"access_token": cfg.key_gpt_access_token,
|
|
|
|
|
"paid": False,
|
|
|
|
|
"collect_analytics": True,
|
2023-05-27 17:03:43 +08:00
|
|
|
|
"model": "gpt-4",
|
2023-05-23 00:49:31 +08:00
|
|
|
|
"conversation_id":cfg.key_gpt_conversation_id
|
|
|
|
|
},conversation_id=cfg.key_gpt_conversation_id,
|
|
|
|
|
parent_id=None)
|
2023-05-19 18:12:02 +08:00
|
|
|
|
|
2023-05-23 00:49:31 +08:00
|
|
|
|
prompt = cont
|
2023-05-19 18:12:02 +08:00
|
|
|
|
response = ""
|
2023-05-23 00:49:31 +08:00
|
|
|
|
for data in chatbot.ask(prompt):
|
2023-05-19 18:12:02 +08:00
|
|
|
|
response = data["message"]
|
2023-05-27 17:03:43 +08:00
|
|
|
|
count = 0
|
2023-05-19 18:12:02 +08:00
|
|
|
|
return response
|
2023-05-27 17:03:43 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
count += 1
|
|
|
|
|
if count < 3:
|
|
|
|
|
time.sleep(15)
|
|
|
|
|
return question(cont)
|
|
|
|
|
return 'gpt当前繁忙,请稍后重试' + e
|