mirror of
https://github.com/open-webui/open-webui
synced 2024-11-24 04:54:12 +00:00
refac: optimisation
This commit is contained in:
parent
4b83a83576
commit
9a2dd5b126
@ -9,6 +9,8 @@ from typing import Optional, Union
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
from aiocache import cached
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from open_webui.apps.webui.models.models import Models
|
from open_webui.apps.webui.models.models import Models
|
||||||
from open_webui.config import (
|
from open_webui.config import (
|
||||||
@ -256,6 +258,7 @@ def merge_models_lists(model_lists):
|
|||||||
return list(merged_models.values())
|
return list(merged_models.values())
|
||||||
|
|
||||||
|
|
||||||
|
@cached(ttl=3)
|
||||||
async def get_all_models():
|
async def get_all_models():
|
||||||
log.info("get_all_models()")
|
log.info("get_all_models()")
|
||||||
if app.state.config.ENABLE_OLLAMA_API:
|
if app.state.config.ENABLE_OLLAMA_API:
|
||||||
@ -295,8 +298,6 @@ async def get_all_models():
|
|||||||
for model in response.get("models", []):
|
for model in response.get("models", []):
|
||||||
model["model"] = f"{prefix_id}.{model['model']}"
|
model["model"] = f"{prefix_id}.{model['model']}"
|
||||||
|
|
||||||
print(responses)
|
|
||||||
|
|
||||||
models = {
|
models = {
|
||||||
"models": merge_models_lists(
|
"models": merge_models_lists(
|
||||||
map(
|
map(
|
||||||
|
@ -6,7 +6,10 @@ from pathlib import Path
|
|||||||
from typing import Literal, Optional, overload
|
from typing import Literal, Optional, overload
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
from aiocache import cached
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
from open_webui.apps.webui.models.models import Models
|
from open_webui.apps.webui.models.models import Models
|
||||||
from open_webui.config import (
|
from open_webui.config import (
|
||||||
CACHE_DIR,
|
CACHE_DIR,
|
||||||
@ -325,6 +328,7 @@ async def get_all_models_responses() -> list:
|
|||||||
return responses
|
return responses
|
||||||
|
|
||||||
|
|
||||||
|
@cached(ttl=3)
|
||||||
async def get_all_models() -> dict[str, list]:
|
async def get_all_models() -> dict[str, list]:
|
||||||
log.info("get_all_models()")
|
log.info("get_all_models()")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user