ElvisWang111 commited on
Commit
c74debe
·
verified ·
1 Parent(s): c42d0d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -18
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import sys, os
2
  import tempfile
3
  import streamlit as st
 
4
 
5
  from config import MODEL_CONFIGS, CUSTOM_MODEL_KEY
6
  from utils.save_secrets import *
@@ -33,24 +34,28 @@ def init_session_state():
33
  if 'selected_model' not in st.session_state:
34
  st.session_state.selected_model = "DeepSeek"
35
 
36
- if 'model_configs_runtime' not in st.session_state:
37
- # 运行时模型配置,包含预设和自定义模型
38
- st.session_state.model_configs_runtime = MODEL_CONFIGS.copy()
39
- # 加载用户配置(包括 API 密钥和自定义模型)
40
- # user_configs = load_local_model_configs()
41
- for model_name, config in user_configs.items():
42
- if model_name in MODEL_CONFIGS:
43
- # 预设模型:只更新 API 密钥
44
- st.session_state.model_configs_runtime[model_name]["api_key"] = config.get("api_key", "")
45
- else:
46
- # 自定义模型:添加完整配置
47
- st.session_state.model_configs_runtime[model_name] = {
48
- "api_base": config.get("api_base", ""),
49
- "model_name": config.get("model_name", ""),
50
- "api_key": config.get("api_key", ""),
51
- "api_type": "openai",
52
- "is_preset": False,
53
- }
 
 
 
 
54
 
55
  # 从 model_configs_runtime 提取 api_keys(用于传递给 Agent)
56
  if 'api_keys' not in st.session_state:
 
1
  import sys, os
2
  import tempfile
3
  import streamlit as st
4
+ import copy
5
 
6
  from config import MODEL_CONFIGS, CUSTOM_MODEL_KEY
7
  from utils.save_secrets import *
 
34
  if 'selected_model' not in st.session_state:
35
  st.session_state.selected_model = "DeepSeek"
36
 
37
+ # if 'model_configs_runtime' not in st.session_state:
38
+ # # 运行时模型配置,包含预设和自定义模型
39
+ # st.session_state.model_configs_runtime = MODEL_CONFIGS.copy()
40
+ # # 加载用户配置(包括 API 密钥和自定义模型)
41
+ # user_configs = load_local_model_configs()
42
+ # for model_name, config in user_configs.items():
43
+ # if model_name in MODEL_CONFIGS:
44
+ # # 预设模型:只更新 API 密钥
45
+ # st.session_state.model_configs_runtime[model_name]["api_key"] = config.get("api_key", "")
46
+ # else:
47
+ # # 自定义模型:添加完整配置
48
+ # st.session_state.model_configs_runtime[model_name] = {
49
+ # "api_base": config.get("api_base", ""),
50
+ # "model_name": config.get("model_name", ""),
51
+ # "api_key": config.get("api_key", ""),
52
+ # "api_type": "openai",
53
+ # "is_preset": False,
54
+ # }
55
+
56
+ if "model_configs_runtime" not in st.session_state:
57
+ # 使用深拷贝避免修改全局 MODEL_CONFIGS
58
+ st.session_state.model_configs_runtime = copy.deepcopy(MODEL_CONFIGS)
59
 
60
  # 从 model_configs_runtime 提取 api_keys(用于传递给 Agent)
61
  if 'api_keys' not in st.session_state: