mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-20 13:47:15 +08:00
feat(命令): 添加set_gpt_model、set_gpt_model、set_gpt_model 几个命令的使用
This commit is contained in:
@@ -66,7 +66,7 @@ class ChatGPTBot(Bot, OpenAIImage):
|
|||||||
logger.debug("[CHATGPT] session query={}".format(session.messages))
|
logger.debug("[CHATGPT] session query={}".format(session.messages))
|
||||||
|
|
||||||
api_key = context.get("openai_api_key")
|
api_key = context.get("openai_api_key")
|
||||||
|
self.args['model'] = context.get('gpt_model') or "gpt-3.5-turbo"
|
||||||
# if context.get('stream'):
|
# if context.get('stream'):
|
||||||
# # reply in stream
|
# # reply in stream
|
||||||
# return self.reply_text_stream(query, new_query, session_id)
|
# return self.reply_text_stream(query, new_query, session_id)
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class ChatChannel(Channel):
|
|||||||
cmsg = context["msg"]
|
cmsg = context["msg"]
|
||||||
user_data = conf().get_user_data(cmsg.from_user_id)
|
user_data = conf().get_user_data(cmsg.from_user_id)
|
||||||
context["openai_api_key"] = user_data.get("openai_api_key")
|
context["openai_api_key"] = user_data.get("openai_api_key")
|
||||||
|
context["gpt_model"] = user_data.get("gpt_model")
|
||||||
if context.get("isgroup", False):
|
if context.get("isgroup", False):
|
||||||
group_name = cmsg.other_user_nickname
|
group_name = cmsg.other_user_nickname
|
||||||
group_id = cmsg.other_user_id
|
group_id = cmsg.other_user_id
|
||||||
|
|||||||
@@ -41,6 +41,18 @@ COMMANDS = {
|
|||||||
"alias": ["reset_openai_api_key"],
|
"alias": ["reset_openai_api_key"],
|
||||||
"desc": "重置为默认的api_key",
|
"desc": "重置为默认的api_key",
|
||||||
},
|
},
|
||||||
|
"set_gpt_model": {
|
||||||
|
"alias": ["set_gpt_model"],
|
||||||
|
"desc": "设置你的私有模型",
|
||||||
|
},
|
||||||
|
"reset_gpt_model": {
|
||||||
|
"alias": ["reset_gpt_model"],
|
||||||
|
"desc": "重置你的私有模型",
|
||||||
|
},
|
||||||
|
"gpt_model": {
|
||||||
|
"alias": ["gpt_model"],
|
||||||
|
"desc": "查询你使用的模型",
|
||||||
|
},
|
||||||
"id": {
|
"id": {
|
||||||
"alias": ["id", "用户"],
|
"alias": ["id", "用户"],
|
||||||
"desc": "获取用户id", # wechaty和wechatmp的用户id不会变化,可用于绑定管理员
|
"desc": "获取用户id", # wechaty和wechatmp的用户id不会变化,可用于绑定管理员
|
||||||
@@ -264,6 +276,26 @@ class Godcmd(Plugin):
|
|||||||
ok, result = True, "你的OpenAI私有api_key已清除"
|
ok, result = True, "你的OpenAI私有api_key已清除"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ok, result = False, "你没有设置私有api_key"
|
ok, result = False, "你没有设置私有api_key"
|
||||||
|
elif cmd == "set_gpt_model":
|
||||||
|
if len(args) == 1:
|
||||||
|
user_data = conf().get_user_data(user)
|
||||||
|
user_data["gpt_model"] = args[0]
|
||||||
|
ok, result = True, "你的GPT模型已设置为" + args[0]
|
||||||
|
else:
|
||||||
|
ok, result = False, "请提供一个GPT模型"
|
||||||
|
elif cmd == "gpt_model":
|
||||||
|
user_data = conf().get_user_data(user)
|
||||||
|
model = conf().get('model')
|
||||||
|
if 'gpt_model' in user_data:
|
||||||
|
model = user_data['gpt_model']
|
||||||
|
ok, result = True, "你的GPT模型为" + str(model)
|
||||||
|
elif cmd == "reset_gpt_model":
|
||||||
|
try:
|
||||||
|
user_data = conf().get_user_data(user)
|
||||||
|
user_data.pop("gpt_model")
|
||||||
|
ok, result = True, "你的GPT模型已重置"
|
||||||
|
except Exception as e:
|
||||||
|
ok, result = False, "你没有设置私有GPT模型"
|
||||||
elif cmd == "reset":
|
elif cmd == "reset":
|
||||||
if bottype in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE]:
|
if bottype in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE]:
|
||||||
bot.sessions.clear_session(session_id)
|
bot.sessions.clear_session(session_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user