-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1074 from julep-ai/dev
dev -> main
- Loading branch information
Showing
12 changed files
with
1,945 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from fastapi import HTTPException | ||
from starlette.status import HTTP_400_BAD_REQUEST | ||
|
||
from ...clients.litellm import get_model_list | ||
|
||
|
||
async def validate_model(model_name: str) -> None: | ||
""" | ||
Validates if a given model name is available in LiteLLM. | ||
Raises HTTPException if model is not available. | ||
""" | ||
models = await get_model_list() | ||
available_models = [model["id"] for model in models] | ||
|
||
if model_name not in available_models: | ||
raise HTTPException( | ||
status_code=HTTP_400_BAD_REQUEST, | ||
detail=f"Model {model_name} not available. Available models: {available_models}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from unittest.mock import patch | ||
|
||
from agents_api.routers.utils.model_validation import validate_model | ||
from fastapi import HTTPException | ||
from ward import raises, test | ||
|
||
from tests.fixtures import SAMPLE_MODELS | ||
|
||
|
||
@test("validate_model: succeeds when model is available") | ||
async def _(): | ||
# Use async context manager for patching | ||
with patch("agents_api.routers.utils.model_validation.get_model_list") as mock_get_models: | ||
mock_get_models.return_value = SAMPLE_MODELS | ||
await validate_model("gpt-4o-mini") | ||
mock_get_models.assert_called_once() | ||
|
||
|
||
@test("validate_model: fails when model is unavailable") | ||
async def _(): | ||
with patch("agents_api.routers.utils.model_validation.get_model_list") as mock_get_models: | ||
mock_get_models.return_value = SAMPLE_MODELS | ||
with raises(HTTPException) as exc: | ||
await validate_model("non-existent-model") | ||
|
||
assert exc.raised.status_code == 400 | ||
assert "Model non-existent-model not available" in exc.raised.detail | ||
mock_get_models.assert_called_once() |
Oops, something went wrong.