From 0e21e3e2e75f14309318ef56eb2888ab769fee7c Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Wed, 6 Sep 2023 10:24:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B2=A1=E5=A1=AB=E5=86=99?= =?UTF-8?q?=E8=AE=AF=E9=A3=9EAPPID=E6=97=A0=E6=8A=A5=E9=94=99=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request_llm/bridge_spark.py | 15 ++++++++++++++- request_llm/com_sparkapi.py | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/request_llm/bridge_spark.py b/request_llm/bridge_spark.py index 1a3d43d115..0fe925f7a0 100644 --- a/request_llm/bridge_spark.py +++ b/request_llm/bridge_spark.py @@ -2,11 +2,17 @@ import time import threading import importlib -from toolbox import update_ui, get_conf +from toolbox import update_ui, get_conf, update_ui_lastest_msg from multiprocessing import Process, Pipe model_name = '星火认知大模型' +def validate_key(): + XFYUN_APPID, = get_conf('XFYUN_APPID', ) + if XFYUN_APPID == '00000000' or XFYUN_APPID == '': + return False + return True + def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", observe_window=[], console_slience=False): """ ⭐多线程方法 @@ -15,6 +21,9 @@ def predict_no_ui_long_connection(inputs, llm_kwargs, history=[], sys_prompt="", watch_dog_patience = 5 response = "" + if validate_key() is False: + raise RuntimeError('请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET') + from .com_sparkapi import SparkRequestInstance sri = SparkRequestInstance() for response in sri.generate(inputs, llm_kwargs, history, sys_prompt): @@ -32,6 +41,10 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp chatbot.append((inputs, "")) yield from update_ui(chatbot=chatbot, history=history) + if validate_key() is False: + yield from update_ui_lastest_msg(lastmsg="[Local Message]: 请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET", chatbot=chatbot, history=history, delay=0) + return + if additional_fn is not None: from core_functional import handle_core_functionality inputs, history = handle_core_functionality(additional_fn, inputs, history, chatbot) diff --git a/request_llm/com_sparkapi.py b/request_llm/com_sparkapi.py index 308aa6402d..0b8d655dff 100644 --- a/request_llm/com_sparkapi.py +++ b/request_llm/com_sparkapi.py @@ -58,7 +58,7 @@ def create_url(self): class SparkRequestInstance(): def __init__(self): XFYUN_APPID, XFYUN_API_SECRET, XFYUN_API_KEY = get_conf('XFYUN_APPID', 'XFYUN_API_SECRET', 'XFYUN_API_KEY') - + if XFYUN_APPID == '00000000' or XFYUN_APPID == '': raise RuntimeError('请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET') self.appid = XFYUN_APPID self.api_secret = XFYUN_API_SECRET self.api_key = XFYUN_API_KEY