Annotate /v1/models with OpenWebUI web_search capability (default-on)
This commit is contained in:
1 parent
80ac982055
commit
5490eeb2fc
1 file changed
+22
-6
+22
-6
@@ -489,17 +489,33 @@ async def opencollective_webhook(request: Request, token: str):
|
|||||||
|
|
||||||
@app.get("/v1/models")
|
@app.get("/v1/models")
|
||||||
async def list_models():
|
async def list_models():
|
||||||
"""List models (same for everyone — no per-user auth needed)."""
|
"""List models (same for everyone — no per-user auth needed).
|
||||||
|
|
||||||
|
Annotates each model with OpenWebUI metadata so web search is enabled by
|
||||||
|
default (defaultFeatureIds includes 'web_search'). Without this, OpenWebUI
|
||||||
|
leaves web search off for these models and members must toggle it manually.
|
||||||
|
"""
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
r = await client.get(
|
r = await client.get(
|
||||||
f"{LITELLM_BASE}/v1/models",
|
f"{LITELLM_BASE}/v1/models",
|
||||||
headers={"Authorization": f"Bearer {LITELLM_MASTER_KEY}"},
|
headers={"Authorization": f"Bearer {LITELLM_MASTER_KEY}"},
|
||||||
)
|
)
|
||||||
return Response(
|
if r.status_code != 200:
|
||||||
content=r.content,
|
return Response(
|
||||||
status_code=r.status_code,
|
content=r.content,
|
||||||
headers={"content-type": r.headers.get("content-type", "application/json")},
|
status_code=r.status_code,
|
||||||
)
|
headers={"content-type": r.headers.get("content-type", "application/json")},
|
||||||
|
)
|
||||||
|
|
||||||
|
payload = r.json()
|
||||||
|
for model in payload.get("data", []):
|
||||||
|
model.setdefault("info", {}).setdefault("meta", {})
|
||||||
|
model["info"]["meta"].setdefault("capabilities", {})["web_search"] = True
|
||||||
|
model["info"]["meta"].setdefault("defaultFeatureIds", [])
|
||||||
|
if "web_search" not in model["info"]["meta"]["defaultFeatureIds"]:
|
||||||
|
model["info"]["meta"]["defaultFeatureIds"].append("web_search")
|
||||||
|
|
||||||
|
return JSONResponse(content=payload)
|
||||||
|
|
||||||
|
|
||||||
@app.api_route("/v1/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
@app.api_route("/v1/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
||||||
|
|||||||
Reference in new issue
Block a user