fix error when metadata is none, prevents logging silently

This commit is contained in:
Tim Asp 2024-01-19 11:37:45 -08:00
parent bacc54eea6
commit cfc998194c

View file

@ -21,9 +21,10 @@ class LangsmithLogger:
def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose): def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose):
# Method definition # Method definition
# inspired by Langsmith http api here: https://github.com/langchain-ai/langsmith-cookbook/blob/main/tracing-examples/rest/rest.ipynb # inspired by Langsmith http api here: https://github.com/langchain-ai/langsmith-cookbook/blob/main/tracing-examples/rest/rest.ipynb
metadata = {} metadata = kwargs.get('litellm_params', {}).get("metadata", {})
if "litellm_params" in kwargs: if metadata is None:
metadata = kwargs["litellm_params"].get("metadata", {}) metadata = {}
# set project name and run_name for langsmith logging # set project name and run_name for langsmith logging
# users can pass project_name and run name to litellm.completion() # users can pass project_name and run name to litellm.completion()
# Example: litellm.completion(model, messages, metadata={"project_name": "my-litellm-project", "run_name": "my-langsmith-run"}) # Example: litellm.completion(model, messages, metadata={"project_name": "my-litellm-project", "run_name": "my-langsmith-run"})