mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
test_model_connection
This commit is contained in:
parent
5aec90c513
commit
6787d0dabe
2 changed files with 31 additions and 25 deletions
|
@ -5487,7 +5487,9 @@ async def ahealth_check(
|
||||||
model_params["litellm_logging_obj"] = litellm_logging_obj
|
model_params["litellm_logging_obj"] = litellm_logging_obj
|
||||||
|
|
||||||
mode_handlers = {
|
mode_handlers = {
|
||||||
"chat": lambda: litellm.acompletion(**model_params),
|
"chat": lambda: litellm.acompletion(
|
||||||
|
**model_params,
|
||||||
|
),
|
||||||
"completion": lambda: litellm.atext_completion(
|
"completion": lambda: litellm.atext_completion(
|
||||||
**_filter_model_params(model_params),
|
**_filter_model_params(model_params),
|
||||||
prompt=prompt or "test",
|
prompt=prompt or "test",
|
||||||
|
@ -5544,12 +5546,7 @@ async def ahealth_check(
|
||||||
"error": f"error:{str(e)}. Missing `mode`. Set the `mode` for the model - https://docs.litellm.ai/docs/proxy/health#embedding-models \nstacktrace: {stack_trace}"
|
"error": f"error:{str(e)}. Missing `mode`. Set the `mode` for the model - https://docs.litellm.ai/docs/proxy/health#embedding-models \nstacktrace: {stack_trace}"
|
||||||
}
|
}
|
||||||
|
|
||||||
error_to_return = (
|
error_to_return = str(e) + "\nstack trace: " + stack_trace
|
||||||
str(e)
|
|
||||||
+ "\nHave you set 'mode' - https://docs.litellm.ai/docs/proxy/health#embedding-models"
|
|
||||||
+ "\nstack trace: "
|
|
||||||
+ stack_trace
|
|
||||||
)
|
|
||||||
|
|
||||||
raw_request_typed_dict = litellm_logging_obj.model_call_details.get(
|
raw_request_typed_dict = litellm_logging_obj.model_call_details.get(
|
||||||
"raw_request_typed_dict"
|
"raw_request_typed_dict"
|
||||||
|
|
|
@ -3,13 +3,14 @@ import copy
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Literal, Optional, Union
|
from typing import Any, Dict, Literal, Optional, Union
|
||||||
|
|
||||||
import fastapi
|
import fastapi
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request, Response, status
|
from fastapi import APIRouter, Depends, HTTPException, Request, Response, status
|
||||||
|
|
||||||
import litellm
|
import litellm
|
||||||
from litellm._logging import verbose_proxy_logger
|
from litellm._logging import verbose_proxy_logger
|
||||||
|
from litellm.constants import HEALTH_CHECK_TIMEOUT_SECONDS
|
||||||
from litellm.proxy._types import (
|
from litellm.proxy._types import (
|
||||||
AlertType,
|
AlertType,
|
||||||
CallInfo,
|
CallInfo,
|
||||||
|
@ -21,6 +22,7 @@ from litellm.proxy._types import (
|
||||||
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
||||||
from litellm.proxy.health_check import (
|
from litellm.proxy.health_check import (
|
||||||
_clean_endpoint_data,
|
_clean_endpoint_data,
|
||||||
|
_update_litellm_params_for_health_check,
|
||||||
perform_health_check,
|
perform_health_check,
|
||||||
run_with_timeout,
|
run_with_timeout,
|
||||||
)
|
)
|
||||||
|
@ -626,9 +628,9 @@ async def test_model_connection(
|
||||||
"realtime",
|
"realtime",
|
||||||
]
|
]
|
||||||
] = fastapi.Body("chat", description="The mode to test the model with"),
|
] = fastapi.Body("chat", description="The mode to test the model with"),
|
||||||
prompt: Optional[str] = fastapi.Body(None, description="Test prompt for the model"),
|
litellm_params: Dict = fastapi.Body(
|
||||||
timeout: Optional[int] = fastapi.Body(
|
None,
|
||||||
30, description="Timeout in seconds for the health check"
|
description="Parameters for litellm.completion, litellm.embedding for the health check",
|
||||||
),
|
),
|
||||||
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
|
||||||
):
|
):
|
||||||
|
@ -644,10 +646,14 @@ async def test_model_connection(
|
||||||
-H 'Authorization: Bearer sk-1234' \\
|
-H 'Authorization: Bearer sk-1234' \\
|
||||||
-H 'Content-Type: application/json' \\
|
-H 'Content-Type: application/json' \\
|
||||||
-d '{
|
-d '{
|
||||||
"model": "openai/gpt-3.5-turbo",
|
"litellm_params": {
|
||||||
"mode": "chat",
|
"model": "gpt-4",
|
||||||
"prompt": "Hello, world!",
|
"custom_llm_provider": "azure_ai",
|
||||||
"timeout": 30
|
"litellm_credential_name": null,
|
||||||
|
"api_key": "6xxxxxxx",
|
||||||
|
"api_base": "https://litellm8397336933.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-10-21",
|
||||||
|
},
|
||||||
|
"mode": "chat"
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -655,23 +661,26 @@ async def test_model_connection(
|
||||||
dict: A dictionary containing the health check result with either success information or error details.
|
dict: A dictionary containing the health check result with either success information or error details.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Create basic params for the model
|
# Include health_check_params if provided
|
||||||
model_params = await request.json()
|
litellm_params = _update_litellm_params_for_health_check(
|
||||||
model_params.pop("mode")
|
model_info={},
|
||||||
|
litellm_params=litellm_params,
|
||||||
# Run the health check with timeout
|
)
|
||||||
|
mode = mode or litellm_params.pop("mode", None)
|
||||||
result = await run_with_timeout(
|
result = await run_with_timeout(
|
||||||
litellm.ahealth_check(
|
litellm.ahealth_check(
|
||||||
model_params,
|
model_params=litellm_params,
|
||||||
mode=mode,
|
mode=mode,
|
||||||
prompt=prompt,
|
prompt="test from litellm",
|
||||||
input=[prompt] if prompt else ["test from litellm"],
|
input=["test from litellm"],
|
||||||
),
|
),
|
||||||
timeout,
|
HEALTH_CHECK_TIMEOUT_SECONDS,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Clean the result for display
|
# Clean the result for display
|
||||||
cleaned_result = _clean_endpoint_data({**model_params, **result}, details=True)
|
cleaned_result = _clean_endpoint_data(
|
||||||
|
{**litellm_params, **result}, details=True
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"status": "error" if "error" in result else "success",
|
"status": "error" if "error" in result else "success",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue