{"record":{"id":"ecda302df0e80315","repo":"binary-husky/gpt_academic","slug":"azure-cfg-array-azure","errorCode":null,"errorMessage":"AZURE_CFG_ARRAY中配置的模型必须以azure开头","messagePattern":"AZURE_CFG_ARRAY中配置的模型必须以azure开头","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"request_llms/bridge_all.py","lineNumber":1383,"sourceCode":"        continue\n    model_info.update({\n        model: {\n            \"fn_with_ui\": ollama_ui,\n            \"fn_without_ui\": ollama_noui,\n            \"endpoint\": ollama_endpoint,\n            \"max_token\": max_token_tmp,\n            \"tokenizer\": tokenizer_gpt35,\n            \"token_cnt\": get_token_num_gpt35,\n        },\n    })\n\n# -=-=-=-=-=-=- azure模型对齐支持 -=-=-=-=-=-=-\nAZURE_CFG_ARRAY = get_conf(\"AZURE_CFG_ARRAY\") # <-- 用于定义和切换多个azure模型 -->\nif len(AZURE_CFG_ARRAY) > 0:\n    for azure_model_name, azure_cfg_dict in AZURE_CFG_ARRAY.items():\n        # 可能会覆盖之前的配置，但这是意料之中的\n        if not azure_model_name.startswith('azure'):\n            raise ValueError(\"AZURE_CFG_ARRAY中配置的模型必须以azure开头\")\n        endpoint_ = azure_cfg_dict[\"AZURE_ENDPOINT\"] + \\\n            f'openai/deployments/{azure_cfg_dict[\"AZURE_ENGINE\"]}/chat/completions?api-version=2023-05-15'\n        model_info.update({\n            azure_model_name: {\n                \"fn_with_ui\": chatgpt_ui,\n                \"fn_without_ui\": chatgpt_noui,\n                \"endpoint\": endpoint_,\n                \"azure_api_key\": azure_cfg_dict[\"AZURE_API_KEY\"],\n                \"max_token\": azure_cfg_dict[\"AZURE_MODEL_MAX_TOKEN\"],\n                \"tokenizer\": tokenizer_gpt35,   # tokenizer只用于粗估token数量\n                \"token_cnt\": get_token_num_gpt35,\n            }\n        })\n        if azure_model_name not in AVAIL_LLM_MODELS:\n            AVAIL_LLM_MODELS += [azure_model_name]\n\n# -=-=-=-=-=-=- Openrouter模型对齐支持 -=-=-=-=-=-=-\n# 为了更灵活地接入Openrouter路由，设计了此接口","sourceCodeStart":1365,"sourceCodeEnd":1401,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_all.py#L1365-L1401","documentation":"At import time, bridge_all.py iterates the AZURE_CFG_ARRAY config (from shared_utils/config_loader via get_conf) and requires every key (model name) to start with 'azure'; otherwise it raises ValueError. This is a naming contract: azure-prefixed names are what route requests to the Azure endpoint wiring defined right below the check.","triggerScenarios":"Editing config so that AZURE_CFG_ARRAY contains a key like 'gpt-4-32k' or 'my_azure_model' (no 'azure' prefix) — the import of request_llms.bridge_all then fails immediately, usually at startup or when any module first imports the bridge.","commonSituations":"Users copy an Azure model block from another project keeping the original model name; typos like 'Azure-gpt4' (capital A — startswith('azure') is case-sensitive and fails); commenting out one field but renaming the key; config shared across machines with local edits.","solutions":["Rename every key in AZURE_CFG_ARRAY to start with lowercase 'azure', e.g. 'azure-gpt-4-32k' (then select that name as LLM_MODEL).","Check for case/whitespace: 'Azure-xxx' and ' azure-xxx' both fail the startswith check.","Restart the app after fixing config — the check runs at import time, not per request.","If you intended a non-Azure model, remove it from AZURE_CFG_ARRAY and configure it under the regular model section instead."],"exampleFix":"# before (config)\nAZURE_CFG_ARRAY = {\n  'gpt-4-azure': {'AZURE_ENDPOINT': ..., 'AZURE_API_KEY': ..., 'AZURE_ENGINE': ...}\n}\n\n# after\nAZURE_CFG_ARRAY = {\n  'azure-gpt-4': {'AZURE_ENDPOINT': ..., 'AZURE_API_KEY': ..., 'AZURE_ENGINE': ...}\n}","handlingStrategy":"validation","validationCode":"def validate_azure_cfg(cfg: dict) -> list[str]:\n    return [name for name in cfg if not name.startswith('azure')]\n\nbad = validate_azure_cfg(get_conf('AZURE_CFG_ARRAY'))\nif bad:\n    raise SystemExit(f'rename {bad} to start with \"azure\" in AZURE_CFG_ARRAY')","typeGuard":null,"tryCatchPattern":"try:\n    import request_llms.bridge_all  # noqa: F401  (config check runs at import)\nexcept ValueError as e:\n    if 'azure开头' in str(e):\n        raise SystemExit(f'config error: {e} — fix AZURE_CFG_ARRAY keys and restart')\n    raise","preventionTips":["Always name Azure entries with the lowercase 'azure' prefix (azure-gpt-4, azure-gpt35-turbo).","Validate config keys in a startup script so import-time crashes become readable startup messages.","Re-check after copying config blocks from other projects or docs."],"tags":["azure","configuration","naming-convention","startup","openai"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}