mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
test streaming logs to langsmith
This commit is contained in:
parent
4e18b8c0b6
commit
f90b7ae0b0
2 changed files with 34 additions and 4 deletions
|
@ -119,9 +119,13 @@ class LangsmithLogger(CustomLogger):
|
|||
"session_name": project_name,
|
||||
"start_time": start_time,
|
||||
"end_time": end_time,
|
||||
"id": run_id,
|
||||
}
|
||||
|
||||
if run_id:
|
||||
data["id"] = run_id
|
||||
|
||||
verbose_logger.debug("Langsmith Logging data on langsmith: %s", data)
|
||||
|
||||
return data
|
||||
|
||||
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
|
||||
|
@ -172,7 +176,7 @@ class LangsmithLogger(CustomLogger):
|
|||
)
|
||||
|
||||
if response.status_code >= 300:
|
||||
verbose_logger.error(f"Error: {response.status_code}")
|
||||
verbose_logger.error(f"Error: {response.status_code} - {response.text}")
|
||||
else:
|
||||
verbose_logger.debug("Run successfully created")
|
||||
verbose_logger.debug(
|
||||
|
|
|
@ -6,6 +6,7 @@ sys.path.insert(0, os.path.abspath("../.."))
|
|||
|
||||
import asyncio
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -25,7 +26,6 @@ test_langsmith_logger = LangsmithLogger()
|
|||
@pytest.mark.asyncio()
|
||||
async def test_langsmith_logging():
|
||||
try:
|
||||
import uuid
|
||||
|
||||
run_id = str(uuid.uuid4())
|
||||
litellm.set_verbose = True
|
||||
|
@ -98,6 +98,7 @@ def test_langsmith_logging_with_metadata():
|
|||
time.sleep(3)
|
||||
|
||||
except Exception as e:
|
||||
pytest.fail(f"Error occurred: {e}")
|
||||
print(e)
|
||||
|
||||
|
||||
|
@ -105,15 +106,40 @@ def test_langsmith_logging_with_streaming_and_metadata():
|
|||
try:
|
||||
litellm.success_callback = ["langsmith"]
|
||||
litellm.set_verbose = True
|
||||
run_id = str(uuid.uuid4())
|
||||
|
||||
messages = [{"role": "user", "content": "what llm are u"}]
|
||||
response = completion(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[{"role": "user", "content": "what llm are u"}],
|
||||
messages=messages,
|
||||
max_tokens=10,
|
||||
temperature=0.2,
|
||||
stream=True,
|
||||
metadata={"id": run_id},
|
||||
)
|
||||
for chunk in response:
|
||||
continue
|
||||
time.sleep(3)
|
||||
|
||||
print("run_id", run_id)
|
||||
logged_run_on_langsmith = test_langsmith_logger.get_run_by_id(run_id=run_id)
|
||||
|
||||
print("logged_run_on_langsmith", logged_run_on_langsmith)
|
||||
|
||||
print("fields in logged_run_on_langsmith", logged_run_on_langsmith.keys())
|
||||
|
||||
input_fields_on_langsmith = logged_run_on_langsmith.get("inputs")
|
||||
|
||||
extra_fields_on_langsmith = logged_run_on_langsmith.get("extra").get(
|
||||
"invocation_params"
|
||||
)
|
||||
|
||||
assert logged_run_on_langsmith.get("run_type") == "llm"
|
||||
print("\nLogged INPUT ON LANGSMITH", input_fields_on_langsmith)
|
||||
|
||||
print("\nextra fields on langsmith", extra_fields_on_langsmith)
|
||||
|
||||
assert isinstance(input_fields_on_langsmith, dict)
|
||||
except Exception as e:
|
||||
pytest.fail(f"Error occurred: {e}")
|
||||
print(e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue