mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
feat: List all available search tools configured in the router.
This commit is contained in:
parent
d12ce3cd5d
commit
4c1017034d
1 changed files with 73 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#### Search Endpoints #####
|
||||
|
||||
import orjson
|
||||
from fastapi import APIRouter, Depends, Request, Response
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Response
|
||||
from fastapi.responses import ORJSONResponse
|
||||
|
||||
from litellm.proxy._types import *
|
||||
|
|
@ -181,3 +181,75 @@ async def search(
|
|||
version=version,
|
||||
)
|
||||
|
||||
@router.get(
|
||||
"/v1/search/tools",
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
response_class=ORJSONResponse,
|
||||
tags=["search"],
|
||||
)
|
||||
@router.get(
|
||||
"/search/tools",
|
||||
dependencies=[Depends(user_api_key_auth)],
|
||||
response_class=ORJSONResponse,
|
||||
tags=["search"],
|
||||
)
|
||||
async def list_search_tools(
|
||||
request: Request,
|
||||
fastapi_response: Response,
|
||||
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
||||
):
|
||||
"""
|
||||
List all available search tools configured in the router.
|
||||
|
||||
This endpoint returns the search tools that are currently loaded and available
|
||||
for use with the /v1/search endpoint.
|
||||
|
||||
Example:
|
||||
```bash
|
||||
curl -X GET "http://localhost:4000/v1/search/tools" \
|
||||
-H "Authorization: Bearer sk-1234"
|
||||
```
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"object": "list",
|
||||
"data": [
|
||||
{
|
||||
"search_tool_name": "litellm-search",
|
||||
"search_provider": "perplexity",
|
||||
"description": "Perplexity search tool"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
"""
|
||||
from litellm.proxy.proxy_server import llm_router
|
||||
|
||||
try:
|
||||
search_tools_list = []
|
||||
|
||||
if llm_router is not None and hasattr(llm_router, "search_tools"):
|
||||
for tool in llm_router.search_tools:
|
||||
tool_info = {
|
||||
"search_tool_name": tool.get("search_tool_name"),
|
||||
"search_provider": tool.get("litellm_params", {}).get("search_provider"),
|
||||
}
|
||||
|
||||
# Add description if available
|
||||
if "search_tool_info" in tool and tool["search_tool_info"]:
|
||||
description = tool["search_tool_info"].get("description")
|
||||
if description:
|
||||
tool_info["description"] = description
|
||||
|
||||
search_tools_list.append(tool_info)
|
||||
|
||||
return {
|
||||
"object": "list",
|
||||
"data": search_tools_list
|
||||
}
|
||||
except Exception as e:
|
||||
from litellm._logging import verbose_proxy_logger
|
||||
verbose_proxy_logger.exception(f"Error listing search tools: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue