Skip to content

Commit

Permalink
feat: 添加逆向语言模型服务相关配置到面板
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulter committed Jan 5, 2024
1 parent 7ab37f3 commit 8cd398a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
46 changes: 44 additions & 2 deletions addons/dashboard/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ def parse_default_config(self, dashboard_data: DashBoardData, config: dict):

llm_group = DashBoardConfig(
config_type="group",
name="LLM 配置",
name="OpenAI 官方接口类设置",
description="",
body=[
DashBoardConfig(
config_type="item",
val_type="list",
name="OpenAI API KEY",
description="OpenAI API 的 KEY。支持使用非官方但是兼容的 API。",
description="OpenAI API 的 KEY。支持使用非官方但是兼容的 API(第三方中转key)。",
value=config['openai']['key'],
path="openai.key",
),
Expand Down Expand Up @@ -400,6 +400,47 @@ def parse_default_config(self, dashboard_data: DashBoardData, config: dict):
]
)

rev_chatgpt_accounts = config['rev_ChatGPT']['account']
new_accs = []
for i in rev_chatgpt_accounts:
if isinstance(i, dict) and 'access_token' in i:
new_accs.append(i['access_token'])
elif isinstance(i, str):
new_accs.append(i)
config['rev_ChatGPT']['account'] = new_accs

rev_chatgpt_group = DashBoardConfig(
config_type="group",
name="逆向语言模型服务设置",
description="",
body=[
DashBoardConfig(
config_type="item",
val_type="bool",
name="启用逆向语言模型服务",
description="",
value=config['rev_ChatGPT']['enable'],
path="rev_ChatGPT.enable",
),
DashBoardConfig(
config_type="item",
val_type="string",
name="终结点(Endpoint)地址",
description="逆向服务的终结点服务器的地址。",
value=config['CHATGPT_BASE_URL'],
path="CHATGPT_BASE_URL",
),
DashBoardConfig(
config_type="item",
val_type="list",
name="assess_token",
description="assess_token",
value=config['rev_ChatGPT']['account'],
path="rev_ChatGPT.account",
),
]
)

baidu_aip_group = DashBoardConfig(
config_type="group",
name="百度内容审核",
Expand Down Expand Up @@ -476,6 +517,7 @@ def parse_default_config(self, dashboard_data: DashBoardData, config: dict):
gocq_platform_detail_group,
proxy_group,
llm_group,
rev_chatgpt_group,
other_group,
baidu_aip_group
]
Expand Down
20 changes: 13 additions & 7 deletions model/provider/rev_chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ def __init__(self, config, base_url = None):
for i in range(0, len(config['account'])):
try:
gu.log(f"创建逆向ChatGPT负载{str(i+1)}中...", level=gu.LEVEL_INFO, tag="RevChatGPT")

if 'password' in config['account'][i]:
gu.log(f"创建逆向ChatGPT负载{str(i+1)}失败: 已不支持账号密码登录,请使用access_token方式登录。", level=gu.LEVEL_ERROR, tag="RevChatGPT")
continue
rev_account_config = {
'access_token': config['account'][i]['access_token'],
}

if isinstance(config['account'][i], str):
# 默认是 access_token
rev_account_config = {
'access_token': config['account'][i],
}
else:
if 'password' in config['account'][i]:
gu.log(f"创建逆向ChatGPT负载{str(i+1)}失败: 已不支持账号密码登录,请使用access_token方式登录。", level=gu.LEVEL_ERROR, tag="RevChatGPT")
continue
rev_account_config = {
'access_token': config['account'][i]['access_token'],
}
if self.cc.get("rev_chatgpt_model") != "":
rev_account_config['model'] = self.cc.get("rev_chatgpt_model")
if len(self.cc.get("rev_chatgpt_plugin_ids")) > 0:
Expand Down

0 comments on commit 8cd398a

Please sign in to comment.