litellm-mirror/tests/local_testing/test_arize_phoenix.py
Krish Dholakia 9914c166b7
Litellm contributor prs 02 24 2025 (#8775)
* Adding VertexAI Claude 3.7 Sonnet (#8774)

Co-authored-by: Emerson Gomes <emerson.gomes@thalesgroup.com>

* build(model_prices_and_context_window.json): add anthropic 3-7 models on vertex ai and bedrock

* Support video_url (#8743)

* Support video_url

Support VLMs that works with video.
Example implemenation in vllm: https://github.com/vllm-project/vllm/pull/10020

* llms openai.py: Add ChatCompletionVideoObject

Add data structures to support `video_url` in chat completion

* test test_completion.py: add test for video_url

* Arize Phoenix - ensure correct endpoint/protocol are used; and default to phoenix cloud (#8750)

* minor fixes to default to http and to ensure that the correct endpoint is used

* Update test_arize_phoenix.py

* prioritize http over grpc

---------

Co-authored-by: Emerson Gomes <emerson.gomes@gmail.com>
Co-authored-by: Emerson Gomes <emerson.gomes@thalesgroup.com>
Co-authored-by: Pang Wu <104795337+pang-wu@users.noreply.github.com>
Co-authored-by: Nate Mar <67926244+nate-mar@users.noreply.github.com>
2025-02-24 18:55:48 -08:00

108 lines
3.8 KiB
Python

import asyncio
import logging
import pytest
from dotenv import load_dotenv
import litellm
from litellm._logging import verbose_logger, verbose_proxy_logger
from litellm.integrations.arize.arize_phoenix import ArizePhoenixConfig, ArizePhoenixLogger
load_dotenv()
@pytest.mark.asyncio()
async def test_async_otel_callback():
litellm.set_verbose = True
verbose_proxy_logger.setLevel(logging.DEBUG)
verbose_logger.setLevel(logging.DEBUG)
litellm.success_callback = ["arize_phoenix"]
await litellm.acompletion(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "this is arize phoenix"}],
mock_response="hello",
temperature=0.1,
user="OTEL_USER",
)
await asyncio.sleep(2)
@pytest.mark.parametrize(
"env_vars, expected_headers, expected_endpoint, expected_protocol",
[
pytest.param(
{"PHOENIX_API_KEY": "test_api_key"},
"api_key=test_api_key",
"https://app.phoenix.arize.com/v1/traces",
"otlp_http",
id="default to http protocol and Arize hosted Phoenix endpoint",
),
pytest.param(
{"PHOENIX_COLLECTOR_HTTP_ENDPOINT": "", "PHOENIX_API_KEY": "test_api_key"},
"api_key=test_api_key",
"https://app.phoenix.arize.com/v1/traces",
"otlp_http",
id="empty string/unset endpoint will default to http protocol and Arize hosted Phoenix endpoint",
),
pytest.param(
{"PHOENIX_COLLECTOR_HTTP_ENDPOINT": "http://localhost:4318", "PHOENIX_COLLECTOR_ENDPOINT": "http://localhost:4317", "PHOENIX_API_KEY": "test_api_key"},
"Authorization=Bearer test_api_key",
"http://localhost:4318",
"otlp_http",
id="prioritize http if both endpoints are set",
),
pytest.param(
{"PHOENIX_COLLECTOR_ENDPOINT": "https://localhost:6006", "PHOENIX_API_KEY": "test_api_key"},
"Authorization=Bearer test_api_key",
"https://localhost:6006",
"otlp_grpc",
id="custom grpc endpoint",
),
pytest.param(
{"PHOENIX_COLLECTOR_ENDPOINT": "https://localhost:6006"},
None,
"https://localhost:6006",
"otlp_grpc",
id="custom grpc endpoint with no auth",
),
pytest.param(
{"PHOENIX_COLLECTOR_HTTP_ENDPOINT": "https://localhost:6006", "PHOENIX_API_KEY": "test_api_key"},
"Authorization=Bearer test_api_key",
"https://localhost:6006",
"otlp_http",
id="custom http endpoint",
),
],
)
def test_get_arize_phoenix_config(monkeypatch, env_vars, expected_headers, expected_endpoint, expected_protocol):
for key, value in env_vars.items():
monkeypatch.setenv(key, value)
config = ArizePhoenixLogger.get_arize_phoenix_config()
assert isinstance(config, ArizePhoenixConfig)
assert config.otlp_auth_headers == expected_headers
assert config.endpoint == expected_endpoint
assert config.protocol == expected_protocol
@pytest.mark.parametrize(
"env_vars",
[
pytest.param(
{"PHOENIX_COLLECTOR_ENDPOINT": "https://app.phoenix.arize.com/v1/traces"},
id="missing api_key with explicit Arize Phoenix endpoint"
),
pytest.param(
{},
id="missing api_key with no endpoint (defaults to Arize Phoenix)"
),
],
)
def test_get_arize_phoenix_config_expection_on_missing_api_key(monkeypatch, env_vars):
for key, value in env_vars.items():
monkeypatch.setenv(key, value)
with pytest.raises(ValueError, match=f"PHOENIX_API_KEY must be set when the Arize hosted Phoenix endpoint is used."):
ArizePhoenixLogger.get_arize_phoenix_config()