|
5 | 5 | from datetime import datetime |
6 | 6 | from unittest import mock |
7 | 7 |
|
8 | | -import httpx |
9 | 8 | import pytest |
10 | 9 |
|
11 | 10 | import sentry_sdk |
@@ -2533,61 +2532,6 @@ def test_integration_setup(sentry_init): |
2533 | 2532 | assert _failure_callback in (litellm.failure_callback or []) |
2534 | 2533 |
|
2535 | 2534 |
|
2536 | | -@pytest.mark.asyncio(loop_scope="session") |
2537 | | -async def test_anthropic_passthrough_request_stays_serializable( |
2538 | | - reset_litellm_executor, sentry_init |
2539 | | -): |
2540 | | - """Regression test for GH-6596: litellm's Anthropic ``/v1/messages`` |
2541 | | - passthrough forwards the caller's ``metadata`` into the request body, so the |
2542 | | - integration must not make that body unserializable. Drive the real |
2543 | | - passthrough with a mocked transport and assert the request body serializes. |
2544 | | - """ |
2545 | | - sentry_init( |
2546 | | - integrations=[LiteLLMIntegration()], |
2547 | | - disabled_integrations=[StdlibIntegration], |
2548 | | - traces_sample_rate=1.0, |
2549 | | - send_default_pii=True, |
2550 | | - ) |
2551 | | - |
2552 | | - captured = {} |
2553 | | - anthropic_response = { |
2554 | | - "id": "msg_1", |
2555 | | - "type": "message", |
2556 | | - "role": "assistant", |
2557 | | - "content": [{"type": "text", "text": "Hi there"}], |
2558 | | - "model": "claude-3-5-sonnet-latest", |
2559 | | - "stop_reason": "end_turn", |
2560 | | - "stop_sequence": None, |
2561 | | - "usage": {"input_tokens": 1, "output_tokens": 1}, |
2562 | | - } |
2563 | | - |
2564 | | - client = AsyncHTTPHandler() |
2565 | | - |
2566 | | - def capture_post(*args, **kwargs): |
2567 | | - captured["data"] = kwargs.get("data") |
2568 | | - return httpx.Response( |
2569 | | - 200, |
2570 | | - json=anthropic_response, |
2571 | | - request=httpx.Request("POST", "https://api.anthropic.com/v1/messages"), |
2572 | | - ) |
2573 | | - |
2574 | | - with mock.patch.object(client, "post", side_effect=capture_post), start_transaction( |
2575 | | - name="litellm test" |
2576 | | - ): |
2577 | | - await litellm.anthropic.messages.acreate( |
2578 | | - model="anthropic/claude-3-5-sonnet-latest", |
2579 | | - messages=[{"role": "user", "content": "Hello!"}], |
2580 | | - max_tokens=16, |
2581 | | - metadata={"user_id": "my-org"}, |
2582 | | - api_key="test-key", |
2583 | | - client=client, |
2584 | | - ) |
2585 | | - |
2586 | | - assert "data" in captured |
2587 | | - request_body = json.loads(captured["data"]) |
2588 | | - assert request_body["metadata"] == {"user_id": "my-org"} |
2589 | | - |
2590 | | - |
2591 | 2535 | def test_litellm_message_truncation(sentry_init, capture_events): |
2592 | 2536 | """Test that large messages are truncated properly in LiteLLM integration.""" |
2593 | 2537 | sentry_init( |
|
0 commit comments