yangtb24 commited on
Commit
50f1e91
1 Parent(s): 00407d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py CHANGED
@@ -28,6 +28,8 @@ text_models = []
28
  free_text_models = []
29
  embedding_models = []
30
  free_embedding_models = []
 
 
31
 
32
  invalid_keys_global = []
33
  free_keys_global = []
@@ -100,11 +102,14 @@ def refresh_models():
100
  """
101
  global text_models, free_text_models
102
  global embedding_models, free_embedding_models
 
103
 
104
  text_models = get_all_models(FREE_MODEL_TEST_KEY, "chat")
105
  embedding_models = get_all_models(FREE_MODEL_TEST_KEY, "embedding")
 
106
  free_text_models = []
107
  free_embedding_models = []
 
108
 
109
  ban_models_str = os.environ.get("BAN_MODELS")
110
  ban_models = []
@@ -124,6 +129,7 @@ def refresh_models():
124
 
125
  text_models = [model for model in text_models if model not in ban_models]
126
  embedding_models = [model for model in embedding_models if model not in ban_models]
 
127
 
128
  with concurrent.futures.ThreadPoolExecutor(
129
  max_workers=100
@@ -161,11 +167,31 @@ def refresh_models():
161
  free_embedding_models.append(model)
162
  except Exception as exc:
163
  logging.error(f"模型 {model} 测试生成异常: {exc}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
  logging.info(f"所有文本模型列表:{text_models}")
166
  logging.info(f"免费文本模型列表:{free_text_models}")
167
  logging.info(f"所有向量模型列表:{embedding_models}")
168
  logging.info(f"免费向量模型列表:{free_embedding_models}")
 
 
169
 
170
  def test_embedding_model_availability(api_key, model_name):
171
  """
@@ -195,6 +221,17 @@ def test_embedding_model_availability(api_key, model_name):
195
  f"API Key:{api_key},错误信息:{e}"
196
  )
197
  return False
 
 
 
 
 
 
 
 
 
 
 
198
 
199
  def load_keys():
200
  """
 
28
  free_text_models = []
29
  embedding_models = []
30
  free_embedding_models = []
31
+ image_models = []
32
+ free_image_models = []
33
 
34
  invalid_keys_global = []
35
  free_keys_global = []
 
102
  """
103
  global text_models, free_text_models
104
  global embedding_models, free_embedding_models
105
+ global image_models, free_image_models
106
 
107
  text_models = get_all_models(FREE_MODEL_TEST_KEY, "chat")
108
  embedding_models = get_all_models(FREE_MODEL_TEST_KEY, "embedding")
109
+ image_models = get_all_models(FREE_MODEL_TEST_KEY, "embedding")
110
  free_text_models = []
111
  free_embedding_models = []
112
+ free_image_models = []
113
 
114
  ban_models_str = os.environ.get("BAN_MODELS")
115
  ban_models = []
 
129
 
130
  text_models = [model for model in text_models if model not in ban_models]
131
  embedding_models = [model for model in embedding_models if model not in ban_models]
132
+ image_models = [model for model in embedding_models if model not in ban_models]
133
 
134
  with concurrent.futures.ThreadPoolExecutor(
135
  max_workers=100
 
167
  free_embedding_models.append(model)
168
  except Exception as exc:
169
  logging.error(f"模型 {model} 测试生成异常: {exc}")
170
+
171
+ with concurrent.futures.ThreadPoolExecutor(
172
+ max_workers=100
173
+ ) as executor:
174
+ future_to_model = {
175
+ executor.submit(
176
+ test_image_model_availability,
177
+ FREE_MODEL_TEST_KEY, model
178
+ ): model for model in embedding_models
179
+ }
180
+ for future in concurrent.futures.as_completed(future_to_model):
181
+ model = future_to_model[future]
182
+ try:
183
+ is_free = future.result()
184
+ if is_free:
185
+ free_image_models.append(model)
186
+ except Exception as exc:
187
+ logging.error(f"模型 {model} 测试生成异常: {exc}")
188
 
189
  logging.info(f"所有文本模型列表:{text_models}")
190
  logging.info(f"免费文本模型列表:{free_text_models}")
191
  logging.info(f"所有向量模型列表:{embedding_models}")
192
  logging.info(f"免费向量模型列表:{free_embedding_models}")
193
+ logging.info(f"所有生图模型列表:{image_models}")
194
+ logging.info(f"免费生图模型列表:{free_image_models}")
195
 
196
  def test_embedding_model_availability(api_key, model_name):
197
  """
 
221
  f"API Key:{api_key},错误信息:{e}"
222
  )
223
  return False
224
+
225
+ def test_image_model_availability(api_key, model_name):
226
+ """
227
+ 测试指定的向量模型是否可用。
228
+ """
229
+ headers = {
230
+ "Authorization": f"Bearer {api_key}",
231
+ "Content-Type": "application/json"
232
+ }
233
+
234
+ return True
235
 
236
  def load_keys():
237
  """