diff --git a/app.py b/app.py index 56a6a56..e000949 100644 --- a/app.py +++ b/app.py @@ -107,17 +107,35 @@ if "research_steps_output" not in st.session_state: with st.sidebar: st.header("⚙️ 设置") - # 全局 API Key 设置 - with st.expander("🔑 API Key 设置", expanded=True): - use_custom_key = st.checkbox("使用自定义 API Key") - if use_custom_key: - api_key = st.text_input( - "API Key", - type="password", - help="留空则使用环境变量中的 Key" - ) - else: - api_key = DEFAULT_API_KEY + # 全局 API Key & Provider 设置 + with st.expander("🔑 API / Provider 设置", expanded=True): + # Provider Selection + selected_provider_label = st.selectbox( + "选择 API 提供商", + options=list(config.LLM_PROVIDERS.keys()), + index=0 + ) + + provider_config = config.LLM_PROVIDERS[selected_provider_label] + provider_id = selected_provider_label.lower() + + # API Key Input + default_key = os.getenv(provider_config["api_key_var"], "") + api_key = st.text_input( + f"{selected_provider_label} API Key", + type="password", + value=default_key, + help=f"环境变量: {provider_config['api_key_var']}" + ) + + # Base URL + base_url = st.text_input( + "API Base URL", + value=provider_config["base_url"] + ) + + if not api_key: + st.warning("请配置 API Key 以继续") st.divider()