mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
feat - add DELETE assistants endpoint
This commit is contained in:
parent
b6f1c4f296
commit
a9e15dad62
2 changed files with 115 additions and 0 deletions
|
@ -4059,6 +4059,101 @@ async def create_assistant(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete(
|
||||||
|
"/v1/assistants/{assistant_id:path}",
|
||||||
|
dependencies=[Depends(user_api_key_auth)],
|
||||||
|
tags=["assistants"],
|
||||||
|
)
|
||||||
|
@router.delete(
|
||||||
|
"/assistants/{assistant_id:path}",
|
||||||
|
dependencies=[Depends(user_api_key_auth)],
|
||||||
|
tags=["assistants"],
|
||||||
|
)
|
||||||
|
async def delete_assistant(
|
||||||
|
request: Request,
|
||||||
|
assistant_id: str,
|
||||||
|
fastapi_response: Response,
|
||||||
|
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Delete assistant
|
||||||
|
|
||||||
|
API Reference docs - https://platform.openai.com/docs/api-reference/assistants/createAssistant
|
||||||
|
"""
|
||||||
|
global proxy_logging_obj
|
||||||
|
data: Dict = {}
|
||||||
|
try:
|
||||||
|
# Use orjson to parse JSON data, orjson speeds up requests significantly
|
||||||
|
|
||||||
|
# Include original request and headers in the data
|
||||||
|
data = await add_litellm_data_to_request(
|
||||||
|
data=data,
|
||||||
|
request=request,
|
||||||
|
general_settings=general_settings,
|
||||||
|
user_api_key_dict=user_api_key_dict,
|
||||||
|
version=version,
|
||||||
|
proxy_config=proxy_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
# for now use custom_llm_provider=="openai" -> this will change as LiteLLM adds more providers for acreate_batch
|
||||||
|
if llm_router is None:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=500, detail={"error": CommonProxyErrors.no_llm_router.value}
|
||||||
|
)
|
||||||
|
response = await llm_router.adelete_assistant(assistant_id=assistant_id, **data)
|
||||||
|
|
||||||
|
### ALERTING ###
|
||||||
|
asyncio.create_task(
|
||||||
|
proxy_logging_obj.update_request_status(
|
||||||
|
litellm_call_id=data.get("litellm_call_id", ""), status="success"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
### RESPONSE HEADERS ###
|
||||||
|
hidden_params = getattr(response, "_hidden_params", {}) or {}
|
||||||
|
model_id = hidden_params.get("model_id", None) or ""
|
||||||
|
cache_key = hidden_params.get("cache_key", None) or ""
|
||||||
|
api_base = hidden_params.get("api_base", None) or ""
|
||||||
|
|
||||||
|
fastapi_response.headers.update(
|
||||||
|
get_custom_headers(
|
||||||
|
user_api_key_dict=user_api_key_dict,
|
||||||
|
model_id=model_id,
|
||||||
|
cache_key=cache_key,
|
||||||
|
api_base=api_base,
|
||||||
|
version=version,
|
||||||
|
model_region=getattr(user_api_key_dict, "allowed_model_region", ""),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
await proxy_logging_obj.post_call_failure_hook(
|
||||||
|
user_api_key_dict=user_api_key_dict, original_exception=e, request_data=data
|
||||||
|
)
|
||||||
|
verbose_proxy_logger.error(
|
||||||
|
"litellm.proxy.proxy_server.delete_assistant(): Exception occured - {}".format(
|
||||||
|
str(e)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
verbose_proxy_logger.debug(traceback.format_exc())
|
||||||
|
if isinstance(e, HTTPException):
|
||||||
|
raise ProxyException(
|
||||||
|
message=getattr(e, "message", str(e.detail)),
|
||||||
|
type=getattr(e, "type", "None"),
|
||||||
|
param=getattr(e, "param", "None"),
|
||||||
|
code=getattr(e, "status_code", status.HTTP_400_BAD_REQUEST),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
error_msg = f"{str(e)}"
|
||||||
|
raise ProxyException(
|
||||||
|
message=getattr(e, "message", error_msg),
|
||||||
|
type=getattr(e, "type", "None"),
|
||||||
|
param=getattr(e, "param", "None"),
|
||||||
|
code=getattr(e, "status_code", 500),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
"/v1/threads",
|
"/v1/threads",
|
||||||
dependencies=[Depends(user_api_key_auth)],
|
dependencies=[Depends(user_api_key_auth)],
|
||||||
|
|
|
@ -43,6 +43,7 @@ from typing_extensions import overload
|
||||||
|
|
||||||
import litellm
|
import litellm
|
||||||
from litellm._logging import verbose_router_logger
|
from litellm._logging import verbose_router_logger
|
||||||
|
from litellm.assistants.main import AssistantDeleted
|
||||||
from litellm.caching import DualCache, InMemoryCache, RedisCache
|
from litellm.caching import DualCache, InMemoryCache, RedisCache
|
||||||
from litellm.integrations.custom_logger import CustomLogger
|
from litellm.integrations.custom_logger import CustomLogger
|
||||||
from litellm.llms.azure import get_azure_ad_token_from_oidc
|
from litellm.llms.azure import get_azure_ad_token_from_oidc
|
||||||
|
@ -1989,6 +1990,25 @@ class Router:
|
||||||
custom_llm_provider=custom_llm_provider, client=client, **kwargs
|
custom_llm_provider=custom_llm_provider, client=client, **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def adelete_assistant(
|
||||||
|
self,
|
||||||
|
custom_llm_provider: Optional[Literal["openai", "azure"]] = None,
|
||||||
|
client: Optional[AsyncOpenAI] = None,
|
||||||
|
**kwargs,
|
||||||
|
) -> AssistantDeleted:
|
||||||
|
if custom_llm_provider is None:
|
||||||
|
if self.assistants_config is not None:
|
||||||
|
custom_llm_provider = self.assistants_config["custom_llm_provider"]
|
||||||
|
kwargs.update(self.assistants_config["litellm_params"])
|
||||||
|
else:
|
||||||
|
raise Exception(
|
||||||
|
"'custom_llm_provider' must be set. Either via:\n `Router(assistants_config={'custom_llm_provider': ..})` \nor\n `router.arun_thread(custom_llm_provider=..)`"
|
||||||
|
)
|
||||||
|
|
||||||
|
return await litellm.adelete_assistant(
|
||||||
|
custom_llm_provider=custom_llm_provider, client=client, **kwargs
|
||||||
|
)
|
||||||
|
|
||||||
async def aget_assistants(
|
async def aget_assistants(
|
||||||
self,
|
self,
|
||||||
custom_llm_provider: Optional[Literal["openai", "azure"]] = None,
|
custom_llm_provider: Optional[Literal["openai", "azure"]] = None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue