mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
test_assistants_passthrough_logging
This commit is contained in:
parent
76bccca603
commit
b076ae9bc8
8 changed files with 52 additions and 26 deletions
|
@ -43,7 +43,9 @@ class AnthropicMessagesHandler:
|
||||||
from litellm.proxy.pass_through_endpoints.success_handler import (
|
from litellm.proxy.pass_through_endpoints.success_handler import (
|
||||||
PassThroughEndpointLogging,
|
PassThroughEndpointLogging,
|
||||||
)
|
)
|
||||||
from litellm.proxy.pass_through_endpoints.types import EndpointType
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import (
|
||||||
|
EndpointType,
|
||||||
|
)
|
||||||
|
|
||||||
# Create success handler object
|
# Create success handler object
|
||||||
passthrough_success_handler_obj = PassThroughEndpointLogging()
|
passthrough_success_handler_obj = PassThroughEndpointLogging()
|
||||||
|
@ -98,12 +100,12 @@ async def anthropic_messages(
|
||||||
api_base=optional_params.api_base,
|
api_base=optional_params.api_base,
|
||||||
api_key=optional_params.api_key,
|
api_key=optional_params.api_key,
|
||||||
)
|
)
|
||||||
anthropic_messages_provider_config: Optional[
|
anthropic_messages_provider_config: Optional[BaseAnthropicMessagesConfig] = (
|
||||||
BaseAnthropicMessagesConfig
|
ProviderConfigManager.get_provider_anthropic_messages_config(
|
||||||
] = ProviderConfigManager.get_provider_anthropic_messages_config(
|
|
||||||
model=model,
|
model=model,
|
||||||
provider=litellm.LlmProviders(_custom_llm_provider),
|
provider=litellm.LlmProviders(_custom_llm_provider),
|
||||||
)
|
)
|
||||||
|
)
|
||||||
if anthropic_messages_provider_config is None:
|
if anthropic_messages_provider_config is None:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Anthropic messages provider config not found for model: {model}"
|
f"Anthropic messages provider config not found for model: {model}"
|
||||||
|
|
|
@ -13,7 +13,9 @@ from litellm.llms.anthropic.chat.handler import (
|
||||||
from litellm.llms.anthropic.chat.transformation import AnthropicConfig
|
from litellm.llms.anthropic.chat.transformation import AnthropicConfig
|
||||||
from litellm.proxy._types import PassThroughEndpointLoggingTypedDict
|
from litellm.proxy._types import PassThroughEndpointLoggingTypedDict
|
||||||
from litellm.proxy.auth.auth_utils import get_end_user_id_from_request_body
|
from litellm.proxy.auth.auth_utils import get_end_user_id_from_request_body
|
||||||
from litellm.proxy.pass_through_endpoints.types import PassthroughStandardLoggingPayload
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import (
|
||||||
|
PassthroughStandardLoggingPayload,
|
||||||
|
)
|
||||||
from litellm.types.utils import ModelResponse, TextCompletionResponse
|
from litellm.types.utils import ModelResponse, TextCompletionResponse
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -122,9 +124,9 @@ class AnthropicPassthroughLoggingHandler:
|
||||||
litellm_model_response.id = logging_obj.litellm_call_id
|
litellm_model_response.id = logging_obj.litellm_call_id
|
||||||
litellm_model_response.model = model
|
litellm_model_response.model = model
|
||||||
logging_obj.model_call_details["model"] = model
|
logging_obj.model_call_details["model"] = model
|
||||||
logging_obj.model_call_details[
|
logging_obj.model_call_details["custom_llm_provider"] = (
|
||||||
"custom_llm_provider"
|
litellm.LlmProviders.ANTHROPIC.value
|
||||||
] = litellm.LlmProviders.ANTHROPIC.value
|
)
|
||||||
return kwargs
|
return kwargs
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
verbose_proxy_logger.exception(
|
verbose_proxy_logger.exception(
|
||||||
|
|
|
@ -14,11 +14,13 @@ from litellm.litellm_core_utils.litellm_logging import (
|
||||||
get_standard_logging_object_payload,
|
get_standard_logging_object_payload,
|
||||||
)
|
)
|
||||||
from litellm.litellm_core_utils.thread_pool_executor import executor
|
from litellm.litellm_core_utils.thread_pool_executor import executor
|
||||||
from litellm.proxy.pass_through_endpoints.types import PassthroughStandardLoggingPayload
|
|
||||||
from litellm.types.passthrough_endpoints.assembly_ai import (
|
from litellm.types.passthrough_endpoints.assembly_ai import (
|
||||||
ASSEMBLY_AI_MAX_POLLING_ATTEMPTS,
|
ASSEMBLY_AI_MAX_POLLING_ATTEMPTS,
|
||||||
ASSEMBLY_AI_POLLING_INTERVAL,
|
ASSEMBLY_AI_POLLING_INTERVAL,
|
||||||
)
|
)
|
||||||
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import (
|
||||||
|
PassthroughStandardLoggingPayload,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AssemblyAITranscriptResponse(TypedDict, total=False):
|
class AssemblyAITranscriptResponse(TypedDict, total=False):
|
||||||
|
|
|
@ -13,7 +13,9 @@ from litellm.litellm_core_utils.litellm_logging import (
|
||||||
from litellm.llms.base_llm.chat.transformation import BaseConfig
|
from litellm.llms.base_llm.chat.transformation import BaseConfig
|
||||||
from litellm.proxy._types import PassThroughEndpointLoggingTypedDict
|
from litellm.proxy._types import PassThroughEndpointLoggingTypedDict
|
||||||
from litellm.proxy.auth.auth_utils import get_end_user_id_from_request_body
|
from litellm.proxy.auth.auth_utils import get_end_user_id_from_request_body
|
||||||
from litellm.proxy.pass_through_endpoints.types import PassthroughStandardLoggingPayload
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import (
|
||||||
|
PassthroughStandardLoggingPayload,
|
||||||
|
)
|
||||||
from litellm.types.utils import LlmProviders, ModelResponse, TextCompletionResponse
|
from litellm.types.utils import LlmProviders, ModelResponse, TextCompletionResponse
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
|
@ -8,6 +8,7 @@ import httpx
|
||||||
from litellm._logging import verbose_proxy_logger
|
from litellm._logging import verbose_proxy_logger
|
||||||
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
||||||
from litellm.proxy._types import PassThroughEndpointLoggingResultValues
|
from litellm.proxy._types import PassThroughEndpointLoggingResultValues
|
||||||
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import EndpointType
|
||||||
from litellm.types.utils import StandardPassThroughResponseObject
|
from litellm.types.utils import StandardPassThroughResponseObject
|
||||||
|
|
||||||
from .llm_provider_handlers.anthropic_passthrough_logging_handler import (
|
from .llm_provider_handlers.anthropic_passthrough_logging_handler import (
|
||||||
|
@ -17,7 +18,6 @@ from .llm_provider_handlers.vertex_passthrough_logging_handler import (
|
||||||
VertexPassthroughLoggingHandler,
|
VertexPassthroughLoggingHandler,
|
||||||
)
|
)
|
||||||
from .success_handler import PassThroughEndpointLogging
|
from .success_handler import PassThroughEndpointLogging
|
||||||
from .types import EndpointType
|
|
||||||
|
|
||||||
|
|
||||||
class PassThroughStreamingHandler:
|
class PassThroughStreamingHandler:
|
||||||
|
|
|
@ -14,19 +14,31 @@ sys.path.insert(
|
||||||
|
|
||||||
import litellm
|
import litellm
|
||||||
from litellm.proxy._types import UserAPIKeyAuth
|
from litellm.proxy._types import UserAPIKeyAuth
|
||||||
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import PassthroughStandardLoggingPayload
|
||||||
from litellm.integrations.custom_logger import CustomLogger
|
from litellm.integrations.custom_logger import CustomLogger
|
||||||
from litellm.proxy.pass_through_endpoints.pass_through_endpoints import pass_through_request
|
from litellm.proxy.pass_through_endpoints.pass_through_endpoints import pass_through_request
|
||||||
|
|
||||||
class TestCustomLogger(CustomLogger):
|
class TestCustomLogger(CustomLogger):
|
||||||
|
def __init__(self):
|
||||||
|
self.logged_kwargs: Optional[dict] = None
|
||||||
|
|
||||||
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
|
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
|
||||||
print("in async log success event kwargs", json.dumps(kwargs, indent=4, default=str))
|
print("in async log success event kwargs", json.dumps(kwargs, indent=4, default=str))
|
||||||
pass
|
self.logged_kwargs = kwargs
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_assistants_passthrough_logging():
|
async def test_assistants_passthrough_logging():
|
||||||
test_custom_logger = TestCustomLogger()
|
test_custom_logger = TestCustomLogger()
|
||||||
litellm._async_success_callback = [test_custom_logger]
|
litellm._async_success_callback = [test_custom_logger]
|
||||||
|
|
||||||
|
TARGET_URL = "https://api.openai.com/v1/assistants"
|
||||||
|
REQUEST_BODY = {
|
||||||
|
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
|
||||||
|
"name": "Math Tutor",
|
||||||
|
"tools": [{"type": "code_interpreter"}],
|
||||||
|
"model": "gpt-4o"
|
||||||
|
}
|
||||||
|
|
||||||
result = await pass_through_request(
|
result = await pass_through_request(
|
||||||
request=Request(
|
request=Request(
|
||||||
scope={
|
scope={
|
||||||
|
@ -41,7 +53,7 @@ async def test_assistants_passthrough_logging():
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
target="https://api.openai.com/v1/assistants",
|
target=TARGET_URL,
|
||||||
custom_headers={
|
custom_headers={
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f"Bearer {os.getenv('OPENAI_API_KEY')}",
|
"Authorization": f"Bearer {os.getenv('OPENAI_API_KEY')}",
|
||||||
|
@ -53,12 +65,7 @@ async def test_assistants_passthrough_logging():
|
||||||
team_id="test",
|
team_id="test",
|
||||||
end_user_id="test",
|
end_user_id="test",
|
||||||
),
|
),
|
||||||
custom_body={
|
custom_body=REQUEST_BODY,
|
||||||
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
|
|
||||||
"name": "Math Tutor",
|
|
||||||
"tools": [{"type": "code_interpreter"}],
|
|
||||||
"model": "gpt-4o"
|
|
||||||
},
|
|
||||||
forward_headers=False,
|
forward_headers=False,
|
||||||
merge_query_params=False,
|
merge_query_params=False,
|
||||||
)
|
)
|
||||||
|
@ -67,7 +74,17 @@ async def test_assistants_passthrough_logging():
|
||||||
print("result status code", result.status_code)
|
print("result status code", result.status_code)
|
||||||
print("result content", result.body)
|
print("result content", result.body)
|
||||||
|
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
assert test_custom_logger.logged_kwargs is not None
|
||||||
|
passthrough_logging_payload: Optional[PassthroughStandardLoggingPayload] = test_custom_logger.logged_kwargs["passthrough_logging_payload"]
|
||||||
|
assert passthrough_logging_payload is not None
|
||||||
|
assert passthrough_logging_payload["url"] == TARGET_URL
|
||||||
|
assert passthrough_logging_payload["request_body"] == REQUEST_BODY
|
||||||
|
|
||||||
|
# assert that the response body content matches the response body content
|
||||||
|
client_facing_response_body = json.loads(result.body)
|
||||||
|
assert passthrough_logging_payload["response_body"] == client_facing_response_body
|
||||||
|
|
||||||
|
|
||||||
await asyncio.sleep(5)
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import pytest
|
||||||
import litellm
|
import litellm
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
||||||
from litellm.proxy.pass_through_endpoints.types import EndpointType
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import EndpointType
|
||||||
from litellm.proxy.pass_through_endpoints.success_handler import (
|
from litellm.proxy.pass_through_endpoints.success_handler import (
|
||||||
PassThroughEndpointLogging,
|
PassThroughEndpointLogging,
|
||||||
)
|
)
|
||||||
|
@ -34,7 +34,7 @@ from litellm.proxy.pass_through_endpoints.pass_through_endpoints import (
|
||||||
_init_kwargs_for_pass_through_endpoint,
|
_init_kwargs_for_pass_through_endpoint,
|
||||||
_update_metadata_with_tags_in_header,
|
_update_metadata_with_tags_in_header,
|
||||||
)
|
)
|
||||||
from litellm.proxy.pass_through_endpoints.types import PassthroughStandardLoggingPayload
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import PassthroughStandardLoggingPayload
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
@ -13,7 +13,8 @@ import pytest
|
||||||
import litellm
|
import litellm
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
|
||||||
from litellm.proxy.pass_through_endpoints.types import EndpointType
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import EndpointType
|
||||||
|
from litellm.types.passthrough_endpoints.pass_through_endpoints import PassthroughStandardLoggingPayload
|
||||||
from litellm.proxy.pass_through_endpoints.success_handler import (
|
from litellm.proxy.pass_through_endpoints.success_handler import (
|
||||||
PassThroughEndpointLogging,
|
PassThroughEndpointLogging,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue