mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
fix: add missing parameters order, limit, before, and after in get_assistants method for openai (#7537)
- Ensured that `before` and `after` parameters are only passed when provided to avoid AttributeError. - Implemented safe access using default values for `before` and `after` to prevent missing attribute issues. - Added consistent handling of `order` and `limit` to improve flexibility and robustness in API calls.
This commit is contained in:
parent
33f301ec86
commit
4b0505dffd
3 changed files with 74 additions and 5 deletions
|
@ -131,6 +131,10 @@ def get_assistants(
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
max_retries=optional_params.max_retries,
|
max_retries=optional_params.max_retries,
|
||||||
organization=organization,
|
organization=organization,
|
||||||
|
order=getattr(optional_params, "order", "desc"),
|
||||||
|
limit=getattr(optional_params, "limit", 20),
|
||||||
|
before=getattr(optional_params, "before", None),
|
||||||
|
after=getattr(optional_params, "after", None),
|
||||||
client=client,
|
client=client,
|
||||||
aget_assistants=aget_assistants, # type: ignore
|
aget_assistants=aget_assistants, # type: ignore
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
|
@ -1928,6 +1928,10 @@ class OpenAIAssistantsAPI(BaseLLM):
|
||||||
max_retries: Optional[int],
|
max_retries: Optional[int],
|
||||||
organization: Optional[str],
|
organization: Optional[str],
|
||||||
client: Optional[AsyncOpenAI],
|
client: Optional[AsyncOpenAI],
|
||||||
|
order: Optional[str] = 'desc',
|
||||||
|
limit: Optional[int] = 20,
|
||||||
|
before: Optional[str] = None,
|
||||||
|
after: Optional[str] = None,
|
||||||
) -> AsyncCursorPage[Assistant]:
|
) -> AsyncCursorPage[Assistant]:
|
||||||
openai_client = self.async_get_openai_client(
|
openai_client = self.async_get_openai_client(
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
|
@ -1937,8 +1941,16 @@ class OpenAIAssistantsAPI(BaseLLM):
|
||||||
organization=organization,
|
organization=organization,
|
||||||
client=client,
|
client=client,
|
||||||
)
|
)
|
||||||
|
request_params = {
|
||||||
|
"order": order,
|
||||||
|
"limit": limit,
|
||||||
|
}
|
||||||
|
if before:
|
||||||
|
request_params["before"] = before
|
||||||
|
if after:
|
||||||
|
request_params["after"] = after
|
||||||
|
|
||||||
response = await openai_client.beta.assistants.list()
|
response = await openai_client.beta.assistants.list(**request_params)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -1954,6 +1966,10 @@ class OpenAIAssistantsAPI(BaseLLM):
|
||||||
organization: Optional[str],
|
organization: Optional[str],
|
||||||
client: Optional[AsyncOpenAI],
|
client: Optional[AsyncOpenAI],
|
||||||
aget_assistants: Literal[True],
|
aget_assistants: Literal[True],
|
||||||
|
order: Optional[str] = 'desc',
|
||||||
|
limit: Optional[int] = 20,
|
||||||
|
before: Optional[str] = None,
|
||||||
|
after: Optional[str] = None,
|
||||||
) -> Coroutine[None, None, AsyncCursorPage[Assistant]]:
|
) -> Coroutine[None, None, AsyncCursorPage[Assistant]]:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -1967,6 +1983,10 @@ class OpenAIAssistantsAPI(BaseLLM):
|
||||||
organization: Optional[str],
|
organization: Optional[str],
|
||||||
client: Optional[OpenAI],
|
client: Optional[OpenAI],
|
||||||
aget_assistants: Optional[Literal[False]],
|
aget_assistants: Optional[Literal[False]],
|
||||||
|
order: Optional[str] = 'desc',
|
||||||
|
limit: Optional[int] = 20,
|
||||||
|
before: Optional[str] = None,
|
||||||
|
after: Optional[str] = None,
|
||||||
) -> SyncCursorPage[Assistant]:
|
) -> SyncCursorPage[Assistant]:
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -1981,6 +2001,10 @@ class OpenAIAssistantsAPI(BaseLLM):
|
||||||
organization: Optional[str],
|
organization: Optional[str],
|
||||||
client=None,
|
client=None,
|
||||||
aget_assistants=None,
|
aget_assistants=None,
|
||||||
|
order: Optional[str] = 'desc',
|
||||||
|
limit: Optional[int] = 20,
|
||||||
|
before: Optional[str] = None,
|
||||||
|
after: Optional[str] = None,
|
||||||
):
|
):
|
||||||
if aget_assistants is not None and aget_assistants is True:
|
if aget_assistants is not None and aget_assistants is True:
|
||||||
return self.async_get_assistants(
|
return self.async_get_assistants(
|
||||||
|
@ -1990,6 +2014,10 @@ class OpenAIAssistantsAPI(BaseLLM):
|
||||||
max_retries=max_retries,
|
max_retries=max_retries,
|
||||||
organization=organization,
|
organization=organization,
|
||||||
client=client,
|
client=client,
|
||||||
|
order=order,
|
||||||
|
limit=limit,
|
||||||
|
before=before,
|
||||||
|
after=after,
|
||||||
)
|
)
|
||||||
openai_client = self.get_openai_client(
|
openai_client = self.get_openai_client(
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
|
@ -2000,7 +2028,18 @@ class OpenAIAssistantsAPI(BaseLLM):
|
||||||
client=client,
|
client=client,
|
||||||
)
|
)
|
||||||
|
|
||||||
response = openai_client.beta.assistants.list()
|
request_params = {
|
||||||
|
"order": order,
|
||||||
|
"limit": limit,
|
||||||
|
}
|
||||||
|
|
||||||
|
if before:
|
||||||
|
request_params["before"] = before
|
||||||
|
if after:
|
||||||
|
request_params["after"] = after
|
||||||
|
|
||||||
|
|
||||||
|
response = openai_client.beta.assistants.list(**request_params)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
@ -4434,6 +4434,10 @@ async def get_assistants(
|
||||||
request: Request,
|
request: Request,
|
||||||
fastapi_response: Response,
|
fastapi_response: Response,
|
||||||
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
||||||
|
order: Optional[str] = Query(None, description="Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order."),
|
||||||
|
limit: Optional[int] = Query(None, description="A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20."),
|
||||||
|
after: Optional[str] = Query(None, description="A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list."),
|
||||||
|
before: Optional[str] = Query(None, description="A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list."),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Returns a list of assistants.
|
Returns a list of assistants.
|
||||||
|
@ -4456,6 +4460,28 @@ async def get_assistants(
|
||||||
proxy_config=proxy_config,
|
proxy_config=proxy_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Validate `order` parameter
|
||||||
|
if order and order not in ["asc", "desc"]:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=400, detail={"error": "order must be 'asc' or 'desc'"}
|
||||||
|
)
|
||||||
|
if order:
|
||||||
|
data["order"] = order
|
||||||
|
|
||||||
|
# Validate `limit` parameter
|
||||||
|
if limit is not None:
|
||||||
|
if not (1 <= limit <= 100):
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=400, detail={"error": "limit must be between 1 and 100"}
|
||||||
|
)
|
||||||
|
data["limit"] = limit
|
||||||
|
|
||||||
|
# Add pagination cursors if provided
|
||||||
|
if after:
|
||||||
|
data["after"] = after
|
||||||
|
if before:
|
||||||
|
data["before"] = before
|
||||||
|
|
||||||
# for now use custom_llm_provider=="openai" -> this will change as LiteLLM adds more providers for acreate_batch
|
# for now use custom_llm_provider=="openai" -> this will change as LiteLLM adds more providers for acreate_batch
|
||||||
if llm_router is None:
|
if llm_router is None:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue