Skip to content

Commit

Permalink
支持讯飞星火助手API
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Mar 8, 2024
1 parent b974e3f commit e79fefa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
4 changes: 4 additions & 0 deletions 1.双击我启动程序.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
Miniconda3\python.exe webui.py

cmd /k
5 changes: 3 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
5 changes: 3 additions & 2 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
44 changes: 22 additions & 22 deletions utils/gpt_model/sparkdesk.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json, logging
import requests
import logging

from sparkdesk_web.core import SparkWeb
from sparkdesk_api.core import SparkAPI
Expand All @@ -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("讯飞星火配置为空")

Expand Down
13 changes: 6 additions & 7 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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")
Expand Down

0 comments on commit e79fefa

Please sign in to comment.