olivebot/ai_module/nlp_gpt.py
xszyou f8ff5a2187 周末愉快
+ 增加运行时自动清理ui缓存;
+ 增加gpt代理设置可为空;
+ 提高灵聚对接的稳定性。
2023-07-28 18:22:44 +08:00

22 lines
610 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from revChatGPT.V3 import Chatbot
from utils import config_util as cfg
import time
count = 0
def question(cont):
global count
try:
if cfg.proxy_config != '' :
chatbot = Chatbot(proxy = cfg.proxy_config, api_key = cfg.key_chatgpt_api_key)
else:
chatbot = Chatbot(api_key = cfg.key_chatgpt_api_key)
response = chatbot.ask(cont)
count = 0
return response
except Exception as e:
count += 1
if count < 3:
time.sleep(15)
return question(cont)
return 'gpt当前繁忙请稍后重试' + e