binary-husky/gpt_academic · error · RuntimeError

请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET

Error message

请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET

What it means

Raised by the multi-thread entry point of the iFlytek Spark (讯飞星火) bridge when validate_key() returns False, i.e. the XFYUN_APPID / XFYUN_API_KEY / XFYUN_API_SECRET configuration values read via get_conf() are empty. It is a fail-fast configuration guard thrown before any network call to the Spark WebSocket API is made.

Source

Thrown at request_llms/bridge_spark.py:26

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:str, llm_kwargs:dict, history:list=[], sys_prompt:str="",
                                  observe_window:list=[], console_silence:bool=False):
    """
        ⭐多线程方法
        函数的说明请见 request_llms/bridge_all.py
    """
    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, use_image_api=False):
        if len(observe_window) >= 1:
            observe_window[0] = response
        if len(observe_window) >= 2:
            if (time.time()-observe_window[1]) > watch_dog_patience: raise RuntimeError("程序终止。")
    return response

def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
    """
        ⭐单线程方法
        函数的说明请见 request_llms/bridge_all.py
    """
    chatbot.append((inputs, ""))
    yield from update_ui(chatbot=chatbot, history=history)

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Set XFYUN_APPID, XFYUN_API_KEY and XFYUN_API_SECRET in config_private.py (or as environment variables / docker-compose env), then restart the service
  2. Verify the values are non-empty at runtime: from toolbox import get_conf; assert all(get_conf('XFYUN_APPID','XFYUN_API_KEY','XFYUN_API_KEY'))
  3. If running under docker, add the three variables to docker-compose.yml environment section and recreate the container
  4. Make sure you edited the config actually loaded (config_private.py overrides config.py; env vars are read through shared_utils/config_loader.get_conf)

Example fix

# before (config_private.py)
XFYUN_APPID = ''
XFYUN_API_KEY = ''
XFYUN_API_SECRET = ''

# after
XFYUN_APPID = 'your-app-id'
XFYUN_API_KEY = 'your-api-key'
XFYUN_API_SECRET = 'your-api-secret'
Defensive patterns

Strategy: validation

Validate before calling

from toolbox import get_conf
appid, sec, key = get_conf('XFYUN_APPID', 'XFYUN_API_SECRET', 'XFYUN_API_KEY')
assert appid and sec and key, 'XFYUN credentials missing - set them in config_private.py'

Try / catch

try:
    predict_no_ui_long_connection(...)
except RuntimeError as e:
    if 'XFYUN' in str(e):
        raise ConfigurationError('Spark credentials missing') from e
    raise

Prevention

When it happens

Trigger: Calling predict_no_ui_long_connection() from request_llms/bridge_spark.py when one or more of the XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET keys resolve to '' in config.py / config_private.py / environment variables. This path is used by plugins that run the LLM in a worker thread.

Common situations: Fresh clone where config.py still holds placeholder empty keys; docker-compose deployed without the XFYUN_* env vars; user set keys in the wrong file (e.g. a config_private.py that is gitignored but not created); typos in the variable names so get_conf falls back to the empty default.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/0b48d73c2312a3c8. Report an issue: GitHub.