Update app.py
Browse files
app.py
CHANGED
|
@@ -178,10 +178,34 @@ def test_embedding_model_availability(api_key, model_name):
|
|
| 178 |
},
|
| 179 |
timeout=10
|
| 180 |
)
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
else:
|
| 184 |
return False
|
|
|
|
| 185 |
except requests.exceptions.RequestException as e:
|
| 186 |
logging.error(
|
| 187 |
f"测试向量模型 {model_name} 可用性失败,"
|
|
|
|
| 178 |
},
|
| 179 |
timeout=10
|
| 180 |
)
|
| 181 |
+
|
| 182 |
+
if response.status_code == 200:
|
| 183 |
+
return True
|
| 184 |
+
elif response.status_code == 429:
|
| 185 |
+
logging.warning(
|
| 186 |
+
f"测试向量模型 {model_name} 可用性时遇到频率限制,"
|
| 187 |
+
f"API Key:{api_key},响应:{response.text}"
|
| 188 |
+
)
|
| 189 |
return True
|
| 190 |
+
elif response.status_code == 400:
|
| 191 |
+
try:
|
| 192 |
+
error_message = response.json().get("error", {}).get("message", "")
|
| 193 |
+
if (
|
| 194 |
+
"maximum context length" in error_message or
|
| 195 |
+
"This model's maximum context length" in error_message
|
| 196 |
+
):
|
| 197 |
+
logging.warning(
|
| 198 |
+
f"测试向量模型 {model_name} 可用性失败,"
|
| 199 |
+
f"API Key:{api_key},错误信息:模型不支持大于1的输入"
|
| 200 |
+
)
|
| 201 |
+
return False
|
| 202 |
+
else:
|
| 203 |
+
return False
|
| 204 |
+
except (KeyError, TypeError, json.JSONDecodeError):
|
| 205 |
+
return False
|
| 206 |
else:
|
| 207 |
return False
|
| 208 |
+
|
| 209 |
except requests.exceptions.RequestException as e:
|
| 210 |
logging.error(
|
| 211 |
f"测试向量模型 {model_name} 可用性失败,"
|