From e79fefa813e771115a42a6b1cfa08d320aef175f Mon Sep 17 00:00:00 2001 From: ikaros <327209194@qq.com> Date: Fri, 8 Mar 2024 22:28:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=AF=E9=A3=9E=E6=98=9F?= =?UTF-8?q?=E7=81=AB=E5=8A=A9=E6=89=8BAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...7\345\212\250\347\250\213\345\272\217.bat" | 4 ++ config.json | 5 ++- config.json.bak | 5 ++- utils/gpt_model/sparkdesk.py | 44 +++++++++---------- webui.py | 13 +++--- 5 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 "1.\345\217\214\345\207\273\346\210\221\345\220\257\345\212\250\347\250\213\345\272\217.bat" diff --git "a/1.\345\217\214\345\207\273\346\210\221\345\220\257\345\212\250\347\250\213\345\272\217.bat" "b/1.\345\217\214\345\207\273\346\210\221\345\220\257\345\212\250\347\250\213\345\272\217.bat" new file mode 100644 index 00000000..7926b4c1 --- /dev/null +++ "b/1.\345\217\214\345\207\273\346\210\221\345\220\257\345\212\250\347\250\213\345\272\217.bat" @@ -0,0 +1,4 @@ +@echo off +Miniconda3\python.exe webui.py + +cmd /k \ No newline at end of file diff --git a/config.json b/config.json index 5c6aa6d3..7ffa3f2f 100644 --- a/config.json +++ b/config.json @@ -199,14 +199,15 @@ "preset": "现在你正在blibili进行直播。" }, "sparkdesk": { - "type": "web", + "type": "api", "cookie": "", "fd": "", "GtToken": "", "app_id": "", "api_secret": "", "api_key": "", - "version": 3.1 + "version": 3.5, + "assistant_id": "xyzspsb4i5s7_v1" }, "zhipu": { "api_key": "", diff --git a/config.json.bak b/config.json.bak index 5c6aa6d3..7ffa3f2f 100644 --- a/config.json.bak +++ b/config.json.bak @@ -199,14 +199,15 @@ "preset": "现在你正在blibili进行直播。" }, "sparkdesk": { - "type": "web", + "type": "api", "cookie": "", "fd": "", "GtToken": "", "app_id": "", "api_secret": "", "api_key": "", - "version": 3.1 + "version": 3.5, + "assistant_id": "xyzspsb4i5s7_v1" }, "zhipu": { "api_key": "", diff --git a/utils/gpt_model/sparkdesk.py b/utils/gpt_model/sparkdesk.py index ab316a0f..68ae8b80 100644 --- a/utils/gpt_model/sparkdesk.py +++ b/utils/gpt_model/sparkdesk.py @@ -1,5 +1,4 @@ -import json, logging -import requests +import logging from sparkdesk_web.core import SparkWeb from sparkdesk_api.core import SparkAPI @@ -16,32 +15,33 @@ def __init__(self, data): Configure_logger(file_path) self.type = data["type"] - # web版配置 - self.cookie = data["cookie"] - self.fd = data["fd"] - self.GtToken = data["GtToken"] - # api版配置 - self.app_id = data["app_id"] - self.api_secret = data["api_secret"] - self.api_key = data["api_key"] - self.version = data["version"] + self.sparkWeb = None self.sparkAPI = None - if self.cookie != "" and self.fd != "" and self.GtToken != "": + if data["cookie"] != "" and data["fd"] != "" and data["GtToken"] != "": self.sparkWeb = SparkWeb( - cookie = self.cookie, - fd = self.fd, - GtToken = self.GtToken - ) - elif self.app_id != "" and self.api_secret != "" and self.api_key != "" and self.version != "": - self.sparkAPI = SparkAPI( - app_id = self.app_id, - api_secret = self.api_secret, - api_key = self.api_key, - version = self.version + cookie = data["cookie"], + fd = data["fd"], + GtToken = data["GtToken"] ) + elif data["app_id"] != "" and data["api_secret"] != "" and data["api_key"] != "": + if data["assistant_id"] == "": + self.sparkAPI = SparkAPI( + app_id = data["app_id"], + api_secret = data["api_secret"], + api_key = data["api_key"], + version = data["version"] + ) + else: + self.sparkAPI = SparkAPI( + app_id = data["app_id"], + api_secret = data["api_secret"], + api_key = data["api_key"], + version = data["version"], + assistant_id = data["assistant_id"] + ) else: logging.info("讯飞星火配置为空") diff --git a/webui.py b/webui.py index 0a41af0d..d1b4a8af 100644 --- a/webui.py +++ b/webui.py @@ -1105,6 +1105,7 @@ def common_textarea_handle(content): config_data["sparkdesk"]["api_secret"] = input_sparkdesk_api_secret.value config_data["sparkdesk"]["api_key"] = input_sparkdesk_api_key.value config_data["sparkdesk"]["version"] = round(float(select_sparkdesk_version.value), 1) + config_data["sparkdesk"]["assistant_id"] = input_sparkdesk_assistant_id.value if config.get("webui", "show_card", "llm", "langchain_chatglm"): config_data["langchain_chatglm"]["api_ip_port"] = input_langchain_chatglm_api_ip_port.value @@ -2461,12 +2462,9 @@ def common_textarea_handle(content): with ui.card().style(card_css): ui.label("API") with ui.row(): - input_sparkdesk_app_id = ui.input(label='app_id', placeholder='申请官方API后,云平台中提供的APPID', value=config.get("sparkdesk", "app_id")) - input_sparkdesk_app_id.style("width:200px") - input_sparkdesk_api_secret = ui.input(label='api_secret', placeholder='申请官方API后,云平台中提供的APISecret', value=config.get("sparkdesk", "api_secret")) - input_sparkdesk_api_secret.style("width:200px") - input_sparkdesk_api_key = ui.input(label='api_key', placeholder='申请官方API后,云平台中提供的APIKey', value=config.get("sparkdesk", "api_key")) - input_sparkdesk_api_key.style("width:200px") + input_sparkdesk_app_id = ui.input(label='app_id', value=config.get("sparkdesk", "app_id"), placeholder='申请官方API后,云平台中提供的APPID').style("width:100px") + input_sparkdesk_api_secret = ui.input(label='api_secret', value=config.get("sparkdesk", "api_secret"), placeholder='申请官方API后,云平台中提供的APISecret').style("width:200px") + input_sparkdesk_api_key = ui.input(label='api_key', value=config.get("sparkdesk", "api_key"), placeholder='申请官方API后,云平台中提供的APIKey').style("width:200px") lines = ["3.5","3.1", "2.1", "1.1"] data_json = {} for line in lines: @@ -2476,7 +2474,8 @@ def common_textarea_handle(content): options=data_json, value=str(config.get("sparkdesk", "version")) ).style("width:100px") - + input_sparkdesk_assistant_id = ui.input(label='助手ID', value=config.get("sparkdesk", "assistant_id"), placeholder='助手创作中心,创建助手后助手API的接口地址最后的助手ID').style("width:100px") + if config.get("webui", "show_card", "llm", "langchain_chatglm"): with ui.card().style(card_css): ui.label("Langchain_ChatGLM")