Update conf
This commit is contained in:
@@ -8,14 +8,15 @@ import openai
|
|||||||
|
|
||||||
class ChatGPT:
|
class ChatGPT:
|
||||||
|
|
||||||
def __init__(self, key: str, api: str, proxy: str, prompt: str) -> None:
|
def __init__(self, conf: dict) -> None:
|
||||||
openai.api_key = key
|
openai.api_key = conf["key"]
|
||||||
# 自己搭建或第三方代理的接口
|
# 自己搭建或第三方代理的接口
|
||||||
openai.api_base = api
|
openai.api_base = conf["api"]
|
||||||
|
proxy = conf["proxy"]
|
||||||
if proxy:
|
if proxy:
|
||||||
openai.proxy = {"http": proxy, "https": proxy}
|
openai.proxy = {"http": proxy, "https": proxy}
|
||||||
self.conversation_list = {}
|
self.conversation_list = {}
|
||||||
self.system_content_msg = {"role": "system", "content": prompt}
|
self.system_content_msg = {"role": "system", "content": conf["prompt"]}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'ChatGPT'
|
return 'ChatGPT'
|
||||||
@@ -44,8 +45,6 @@ class ChatGPT:
|
|||||||
except Exception as e0:
|
except Exception as e0:
|
||||||
rsp = "发生未知错误:" + str(e0)
|
rsp = "发生未知错误:" + str(e0)
|
||||||
|
|
||||||
# print(self.conversation_list[wxid])
|
|
||||||
|
|
||||||
return rsp
|
return rsp
|
||||||
|
|
||||||
def updateMessage(self, wxid: str, question: str, role: str) -> None:
|
def updateMessage(self, wxid: str, question: str, role: str) -> None:
|
||||||
@@ -84,12 +83,7 @@ if __name__ == "__main__":
|
|||||||
if not config:
|
if not config:
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
key = config.get("key")
|
chat = ChatGPT(config)
|
||||||
api = config.get("api")
|
|
||||||
proxy = config.get("proxy")
|
|
||||||
prompt = config.get("prompt")
|
|
||||||
|
|
||||||
chat = ChatGPT(key, api, proxy, prompt)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
q = input(">>> ")
|
q = input(">>> ")
|
||||||
|
|||||||
6
robot.py
6
robot.py
@@ -35,8 +35,7 @@ class Robot(Job):
|
|||||||
if chat_type == ChatType.TIGER_BOT.value and self.value_check(self.config.TIGERBOT):
|
if chat_type == ChatType.TIGER_BOT.value and self.value_check(self.config.TIGERBOT):
|
||||||
self.chat = TigerBot(self.config.TIGERBOT)
|
self.chat = TigerBot(self.config.TIGERBOT)
|
||||||
elif chat_type == ChatType.CHATGPT.value and self.value_check(self.config.CHATGPT):
|
elif chat_type == ChatType.CHATGPT.value and self.value_check(self.config.CHATGPT):
|
||||||
cgpt = self.config.CHATGPT
|
self.chat = ChatGPT(self.config.CHATGPT)
|
||||||
self.chat = ChatGPT(cgpt.get("key"), cgpt.get("api"), cgpt.get("proxy"), cgpt.get("prompt"))
|
|
||||||
elif chat_type == ChatType.XINGHUO_WEB.value and self.value_check(self.config.XINGHUO_WEB):
|
elif chat_type == ChatType.XINGHUO_WEB.value and self.value_check(self.config.XINGHUO_WEB):
|
||||||
self.chat = XinghuoWeb(self.config.XINGHUO_WEB)
|
self.chat = XinghuoWeb(self.config.XINGHUO_WEB)
|
||||||
elif chat_type == ChatType.CHATGLM.value and self.value_check(self.config.CHATGLM):
|
elif chat_type == ChatType.CHATGLM.value and self.value_check(self.config.CHATGLM):
|
||||||
@@ -48,8 +47,7 @@ class Robot(Job):
|
|||||||
if self.value_check(self.config.TIGERBOT):
|
if self.value_check(self.config.TIGERBOT):
|
||||||
self.chat = TigerBot(self.config.TIGERBOT)
|
self.chat = TigerBot(self.config.TIGERBOT)
|
||||||
elif self.value_check(self.config.CHATGPT):
|
elif self.value_check(self.config.CHATGPT):
|
||||||
cgpt = self.config.CHATGPT
|
self.chat = ChatGPT(self.config.CHATGPT)
|
||||||
self.chat = ChatGPT(cgpt.get("key"), cgpt.get("api"), cgpt.get("proxy"), cgpt.get("prompt"))
|
|
||||||
elif self.value_check(self.config.XINGHUO_WEB):
|
elif self.value_check(self.config.XINGHUO_WEB):
|
||||||
self.chat = XinghuoWeb(self.config.XINGHUO_WEB)
|
self.chat = XinghuoWeb(self.config.XINGHUO_WEB)
|
||||||
elif self.value_check(self.config.CHATGLM):
|
elif self.value_check(self.config.CHATGLM):
|
||||||
|
|||||||
Reference in New Issue
Block a user