sanbo
commited on
Commit
·
0a65462
1
Parent(s):
fc1a612
update sth. at 2025-01-11 19:17:20
Browse files
degpt.py
CHANGED
@@ -22,8 +22,11 @@ cache_duration = 14400 # 缓存有效期,单位:秒 (4小时)
|
|
22 |
cached_models = {
|
23 |
"object": "list",
|
24 |
"data": [],
|
25 |
-
"version": "",
|
26 |
-
"provider": "",
|
|
|
|
|
|
|
27 |
"time": 0
|
28 |
}
|
29 |
|
@@ -180,7 +183,8 @@ async def _fetch_and_update_models():
|
|
180 |
try:
|
181 |
await get_model_names_from_js()
|
182 |
except Exception as e:
|
183 |
-
|
|
|
184 |
try:
|
185 |
get_alive_models()
|
186 |
except Exception as e:
|
@@ -310,7 +314,7 @@ async def get_model_names_from_js(url="https://www.degpt.ai/", timeout: int = 60
|
|
310 |
content_type = response.headers.get('content-type', '').lower()
|
311 |
if 'javascript' in content_type:
|
312 |
js_content = await response.text()
|
313 |
-
if 'models' in js_content
|
314 |
# print(f"找到包含模型信息的JS文件: {response.url}")
|
315 |
models = await parse_models_from_js(js_content)
|
316 |
if models:
|
@@ -352,9 +356,45 @@ async def get_model_names_from_js(url="https://www.degpt.ai/", timeout: int = 60
|
|
352 |
await browser.close()
|
353 |
except Exception as e:
|
354 |
print(f"提取过程发生错误: {str(e)}")
|
355 |
-
|
356 |
raise
|
357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
|
359 |
|
360 |
async def is_model_available(model_id: str, cooldown_seconds: int = 300) -> bool:
|
|
|
22 |
cached_models = {
|
23 |
"object": "list",
|
24 |
"data": [],
|
25 |
+
"version": "0.1.125",
|
26 |
+
"provider": "DeGPT",
|
27 |
+
"name": "DeGPT",
|
28 |
+
"default_locale": "en-US",
|
29 |
+
"status": True,
|
30 |
"time": 0
|
31 |
}
|
32 |
|
|
|
183 |
try:
|
184 |
await get_model_names_from_js()
|
185 |
except Exception as e:
|
186 |
+
# print(f"{e}")
|
187 |
+
pass
|
188 |
try:
|
189 |
get_alive_models()
|
190 |
except Exception as e:
|
|
|
314 |
content_type = response.headers.get('content-type', '').lower()
|
315 |
if 'javascript' in content_type:
|
316 |
js_content = await response.text()
|
317 |
+
if 'models' in js_content:
|
318 |
# print(f"找到包含模型信息的JS文件: {response.url}")
|
319 |
models = await parse_models_from_js(js_content)
|
320 |
if models:
|
|
|
356 |
await browser.close()
|
357 |
except Exception as e:
|
358 |
print(f"提取过程发生错误: {str(e)}")
|
359 |
+
get_from_js()
|
360 |
raise
|
361 |
|
362 |
+
def get_from_js():
|
363 |
+
import requests
|
364 |
+
import re
|
365 |
+
import json
|
366 |
+
global cached_models
|
367 |
+
# 获取 JavaScript 文件内容
|
368 |
+
# url = "https://www.degpt.ai/_app/immutable/chunks/index.83d92b06.js"
|
369 |
+
url = "https://www.degpt.ai/_app/immutable/chunks/index.4aecf75a.js"
|
370 |
+
response = requests.get(url)
|
371 |
+
|
372 |
+
if response.status_code == 200:
|
373 |
+
js_content = response.text
|
374 |
+
models = await parse_models_from_js(js_content)
|
375 |
+
if models:
|
376 |
+
# print("\n提取的模型列表:")
|
377 |
+
existing_ids = {m.get('id') for m in cached_models["data"]}
|
378 |
+
for model in models:
|
379 |
+
model_id = model.get('model', '').strip()
|
380 |
+
# print(f"- 名称: {model.get('name', '')}")
|
381 |
+
# print(f" 模型: {model.get('model', '')}")
|
382 |
+
# print(f" 描述: {model.get('desc', '')}")
|
383 |
+
record_call(model_id)
|
384 |
+
if model_id and model_id not in existing_ids:
|
385 |
+
model_data = {
|
386 |
+
"id": model_id,
|
387 |
+
"object": "model",
|
388 |
+
"model": model_id,
|
389 |
+
"created": int(time.time()),
|
390 |
+
"owned_by": model_id.split("-")[0] if "-" in model_id else "unknown",
|
391 |
+
"name": model.get('name', ''),
|
392 |
+
"description": model.get('desc', ''),
|
393 |
+
"support": model.get('support', 'text'),
|
394 |
+
"tip": model.get('tip', '')
|
395 |
+
}
|
396 |
+
cached_models["data"].append(model_data)
|
397 |
+
# print(f"添加新模型: {model_id}")
|
398 |
|
399 |
|
400 |
async def is_model_available(model_id: str, cooldown_seconds: int = 300) -> bool:
|