Selaa lähdekoodia

feat: add global model check

master
zhayujie 1 vuosi sitten
vanhempi
commit
5ff753a492
2 muutettua tiedostoa jossa 24 lisäystä ja 2 poistoa
  1. +2
    -0
      common/const.py
  2. +22
    -2
      plugins/godcmd/godcmd.py

+ 2
- 0
common/const.py Näytä tiedosto

@@ -7,3 +7,5 @@ CHATGPTONAZURE = "chatGPTOnAzure"
LINKAI = "linkai"

VERSION = "1.3.0"

MODEL_LIST = ["gpt-3.5-turbo-16k", "gpt-4", "wenxin", "xunfei"]

+ 22
- 2
plugins/godcmd/godcmd.py Näytä tiedosto

@@ -4,7 +4,6 @@ import json
import os
import random
import string
import traceback
from typing import Tuple

import plugins
@@ -12,7 +11,6 @@ from bridge.bridge import Bridge
from bridge.context import ContextType
from bridge.reply import Reply, ReplyType
from common import const
from common.log import logger
from config import conf, load_config, global_config
from plugins import *

@@ -32,6 +30,10 @@ COMMANDS = {
"args": ["口令"],
"desc": "管理员认证",
},
"model": {
"alias": ["model", "模型"],
"desc": "查看和设置全局模型",
},
"set_openai_api_key": {
"alias": ["set_openai_api_key"],
"args": ["api_key"],
@@ -257,6 +259,18 @@ class Godcmd(Plugin):
break
if not ok:
result = "插件不存在或未启用"
elif cmd == "model":
if not isadmin and not self.is_admin_in_group(e_context["context"]):
ok, result = False, "需要管理员权限执行"
elif len(args) == 0:
ok, result = True, "当前模型为: " + str(conf().get("model"))
elif len(args) == 1:
if args[0] not in const.MODEL_LIST:
ok, result = False, "模型名称不存在"
else:
conf()["model"] = args[0]
Bridge().reset_bot()
ok, result = True, "模型设置为: " + str(conf().get("model"))
elif cmd == "id":
ok, result = True, user
elif cmd == "set_openai_api_key":
@@ -438,3 +452,9 @@ class Godcmd(Plugin):

def get_help_text(self, isadmin=False, isgroup=False, **kwargs):
return get_help_text(isadmin, isgroup)


def is_admin_in_group(self, context):
if context["isgroup"]:
return context.kwargs.get("msg").actual_user_id in global_config["admin_users"]
return False

Loading…
Peruuta
Tallenna