mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
fix langsmith - don't log api_key
This commit is contained in:
parent
ee33a80486
commit
0119ca1ce1
1 changed files with 29 additions and 6 deletions
|
@ -1,14 +1,33 @@
|
|||
#### What this does ####
|
||||
# On success, logs events to Langsmith
|
||||
import dotenv, os # type: ignore
|
||||
import requests # type: ignore
|
||||
from datetime import datetime
|
||||
import traceback
|
||||
import asyncio
|
||||
import os
|
||||
import traceback
|
||||
import types
|
||||
from datetime import datetime
|
||||
from typing import Any, List, Optional
|
||||
|
||||
import dotenv # type: ignore
|
||||
import requests # type: ignore
|
||||
from pydantic import BaseModel # type: ignore
|
||||
|
||||
|
||||
class LangsmithInputs(BaseModel):
|
||||
model: Optional[str] = None
|
||||
messages: Optional[List[Any]] = None
|
||||
stream: Optional[bool] = None
|
||||
call_type: Optional[str] = None
|
||||
litellm_call_id: Optional[str] = None
|
||||
completion_start_time: Optional[datetime] = None
|
||||
temperature: Optional[float] = None
|
||||
max_tokens: Optional[int] = None
|
||||
custom_llm_provider: Optional[str] = None
|
||||
input: Optional[List[Any]] = None
|
||||
log_event_type: Optional[str] = None
|
||||
original_response: Optional[str] = None
|
||||
response_cost: Optional[float] = None
|
||||
|
||||
|
||||
def is_serializable(value):
|
||||
non_serializable_types = (
|
||||
types.CoroutineType,
|
||||
|
@ -52,10 +71,11 @@ class LangsmithLogger:
|
|||
print_verbose(
|
||||
f"Langsmith Logging - Enters logging function for model {kwargs}"
|
||||
)
|
||||
import requests
|
||||
import datetime
|
||||
from datetime import timezone
|
||||
|
||||
import requests
|
||||
|
||||
try:
|
||||
start_time = kwargs["start_time"].astimezone(timezone.utc).isoformat()
|
||||
end_time = kwargs["end_time"].astimezone(timezone.utc).isoformat()
|
||||
|
@ -64,6 +84,9 @@ class LangsmithLogger:
|
|||
end_time = datetime.datetime.utcnow().isoformat()
|
||||
|
||||
# filter out kwargs to not include any dicts, langsmith throws an erros when trying to log kwargs
|
||||
logged_kwargs = LangsmithInputs(**kwargs)
|
||||
kwargs = logged_kwargs.model_dump()
|
||||
|
||||
new_kwargs = {}
|
||||
for key in kwargs:
|
||||
value = kwargs[key]
|
||||
|
@ -103,7 +126,7 @@ class LangsmithLogger:
|
|||
else:
|
||||
print_verbose("Run successfully created")
|
||||
print_verbose(
|
||||
f"Langsmith Layer Logging - final response object: {response_obj}"
|
||||
f"Langsmith Layer Logging - final response object: {response_obj}. Response text from langsmith={response.text}"
|
||||
)
|
||||
except:
|
||||
print_verbose(f"Langsmith Layer Error - {traceback.format_exc()}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue