mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-28 04:04:31 +00:00
otel test - callbacks
This commit is contained in:
parent
4d7ff7c79b
commit
29fed0e198
1 changed files with 60 additions and 8 deletions
|
@ -11,25 +11,77 @@ import pytest
|
||||||
verbose_logger.setLevel(logging.DEBUG)
|
verbose_logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="new test")
|
# @pytest.mark.skip(reason="new test")
|
||||||
def test_otel_callback():
|
def test_otel_callback():
|
||||||
exporter = InMemorySpanExporter()
|
exporter = InMemorySpanExporter()
|
||||||
|
litellm.set_verbose = True
|
||||||
litellm.callbacks = [OpenTelemetry(OpenTelemetryConfig(exporter=exporter))]
|
litellm.callbacks = [OpenTelemetry(OpenTelemetryConfig(exporter=exporter))]
|
||||||
|
|
||||||
litellm.completion(
|
|
||||||
model="gpt-3.5-turbo",
|
|
||||||
messages=[{"role": "user", "content": "hi"}],
|
|
||||||
)
|
|
||||||
|
|
||||||
asyncio.run(
|
asyncio.run(
|
||||||
litellm.acompletion(
|
litellm.acompletion(
|
||||||
model="gpt-3.5-turbo",
|
model="gpt-3.5-turbo",
|
||||||
messages=[{"role": "user", "content": "hi"}],
|
messages=[{"role": "user", "content": "hi"}],
|
||||||
|
temperature=0.1,
|
||||||
|
user="OTEL_USER",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
time.sleep(4)
|
time.sleep(4)
|
||||||
|
|
||||||
spans = exporter.get_finished_spans()
|
spans = exporter.get_finished_spans()
|
||||||
assert len(spans) == 1 + 1
|
print("spans", spans)
|
||||||
|
assert len(spans) == 2
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"model",
|
||||||
|
["anthropic/claude-3-opus-20240229"],
|
||||||
|
)
|
||||||
|
@pytest.mark.skip(reason="Local only test. WIP.")
|
||||||
|
def test_completion_claude_3_function_call_with_otel(model):
|
||||||
|
litellm.set_verbose = True
|
||||||
|
|
||||||
|
litellm.callbacks = [OpenTelemetry(OpenTelemetryConfig())]
|
||||||
|
tools = [
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"function": {
|
||||||
|
"name": "get_current_weather",
|
||||||
|
"description": "Get the current weather in a given location",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"location": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The city and state, e.g. San Francisco, CA",
|
||||||
|
},
|
||||||
|
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
|
||||||
|
},
|
||||||
|
"required": ["location"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
messages = [
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "What's the weather like in Boston today in Fahrenheit?",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
try:
|
||||||
|
# test without max tokens
|
||||||
|
response = litellm.completion(
|
||||||
|
model=model,
|
||||||
|
messages=messages,
|
||||||
|
tools=tools,
|
||||||
|
tool_choice={
|
||||||
|
"type": "function",
|
||||||
|
"function": {"name": "get_current_weather"},
|
||||||
|
},
|
||||||
|
drop_params=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
print("response from LiteLLM", response)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
pytest.fail(f"Error occurred: {e}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue