返回提交历史
Modified
g4f/api/__init__.py
+10
-1
XFEstudio/gpt4free
perf(api): cache static model specifications for /v1/models endpoint
2e5abf7b
代码差异
1 个文件
+10
-1
@@ -533,6 +533,8 @@ class Api:
533
533
self.client = AsyncClient()
534
534
self.get_g4f_api_key = APIKeyHeader(name="g4f-api-key")
535
535
self.conversations: dict[str, dict[str, BaseConversation]] = {}
536
self._models_cache: dict | None = None
537
self._models_cache_time: float = 0.0
536
538
537
539
security = HTTPBearer(auto_error=False)
538
540
basic_security = HTTPBasic()
@@ -645,7 +647,11 @@ class Api:
645
647
},
646
648
)
647
649
async def models():
648
return {
650
now = time.time()
651
if self._models_cache is not None and (now - self._models_cache_time) < 300:
652
return self._models_cache
653
654
result = {
649
655
"object": "list",
650
656
"data": [
651
657
{
@@ -673,6 +679,9 @@ class Api:
673
679
if provider.working
674
680
],
675
681
}
682
self._models_cache = result
683
self._models_cache_time = now
684
return result
676
685
677
686
@self.app.get(
678
687
"/api/{provider:path}/models",