yangtb24 commited on
Commit
45a91e1
1 Parent(s): e17b54e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -45
app.py CHANGED
@@ -101,15 +101,12 @@ def refresh_models():
101
  """
102
  global text_models, free_text_models
103
  global embedding_models, free_embedding_models
104
-
105
- text_models = get_all_models(
106
- FREE_MODEL_TEST_KEY,
107
- "chat"
108
- )
109
- embedding_models = get_all_models(
110
- FREE_MODEL_TEST_KEY,
111
- "embedding"
112
- ) + get_all_models(FREE_MODEL_TEST_KEY, "reranker")
113
  free_text_models = []
114
  free_embedding_models = []
115
 
@@ -123,9 +120,7 @@ def refresh_models():
123
  model
124
  ): model for model in text_models
125
  }
126
- for future in concurrent.futures.as_completed(
127
- future_to_model
128
- ):
129
  model = future_to_model[future]
130
  try:
131
  is_free = future.result()
@@ -140,13 +135,10 @@ def refresh_models():
140
  future_to_model = {
141
  executor.submit(
142
  test_embedding_model_availability,
143
- FREE_MODEL_TEST_KEY,
144
- model
145
  ): model for model in embedding_models
146
  }
147
- for future in concurrent.futures.as_completed(
148
- future_to_model
149
- ):
150
  model = future_to_model[future]
151
  try:
152
  is_free = future.result()
@@ -164,9 +156,6 @@ def test_embedding_model_availability(api_key, model_name):
164
  """
165
  测试指定的向量模型是否可用。
166
  """
167
- logging.info(
168
- f"测试向量模型 {model_name}"
169
- )
170
  headers = {
171
  "Authorization": f"Bearer {api_key}",
172
  "Content-Type": "application/json"
@@ -181,34 +170,10 @@ def test_embedding_model_availability(api_key, model_name):
181
  },
182
  timeout=10
183
  )
184
-
185
- if response.status_code == 200:
186
- return True
187
- elif response.status_code == 429:
188
- logging.warning(
189
- f"测试向量模型 {model_name} 可用性时遇到频率限制,"
190
- f"API Key:{api_key},响应:{response.text}"
191
- )
192
  return True
193
- elif response.status_code == 400:
194
- try:
195
- error_message = response.json().get("error", {}).get("message", "")
196
- if (
197
- "maximum context length" in error_message or
198
- "This model's maximum context length" in error_message
199
- ):
200
- logging.warning(
201
- f"测试向量模型 {model_name} 可用性失败,"
202
- f"API Key:{api_key},错误信息:模型不支持大于1的输入"
203
- )
204
- return False
205
- else:
206
- return False
207
- except (KeyError, TypeError, json.JSONDecodeError):
208
- return False
209
  else:
210
  return False
211
-
212
  except requests.exceptions.RequestException as e:
213
  logging.error(
214
  f"测试向量模型 {model_name} 可用性失败,"
 
101
  """
102
  global text_models, free_text_models
103
  global embedding_models, free_embedding_models
104
+
105
+ text_models = get_all_models(FREE_MODEL_TEST_KEY, "chat")
106
+ embedding_models = {
107
+ sub_type: get_all_models(FREE_MODEL_TEST_KEY, sub_type)
108
+ for sub_type in ["embedding", "reranker"]
109
+ }
 
 
 
110
  free_text_models = []
111
  free_embedding_models = []
112
 
 
120
  model
121
  ): model for model in text_models
122
  }
123
+ for future in concurrent.futures.as_completed(future_to_model):
 
 
124
  model = future_to_model[future]
125
  try:
126
  is_free = future.result()
 
135
  future_to_model = {
136
  executor.submit(
137
  test_embedding_model_availability,
138
+ FREE_MODEL_TEST_KEY, model
 
139
  ): model for model in embedding_models
140
  }
141
+ for future in concurrent.futures.as_completed(future_to_model):
 
 
142
  model = future_to_model[future]
143
  try:
144
  is_free = future.result()
 
156
  """
157
  测试指定的向量模型是否可用。
158
  """
 
 
 
159
  headers = {
160
  "Authorization": f"Bearer {api_key}",
161
  "Content-Type": "application/json"
 
170
  },
171
  timeout=10
172
  )
173
+ if response.status_code == 429 or response.status_code == 200:
 
 
 
 
 
 
 
174
  return True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  else:
176
  return False
 
177
  except requests.exceptions.RequestException as e:
178
  logging.error(
179
  f"测试向量模型 {model_name} 可用性失败,"