diff --git a/litellm/integrations/langsmith.py b/litellm/integrations/langsmith.py index e310c25670..afe8be28f5 100644 --- a/litellm/integrations/langsmith.py +++ b/litellm/integrations/langsmith.py @@ -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( diff --git a/litellm/tests/test_langsmith.py b/litellm/tests/test_langsmith.py index 24b327355f..a9a7768780 100644 --- a/litellm/tests/test_langsmith.py +++ b/litellm/tests/test_langsmith.py @@ -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)