mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
langsmith use verbose logger
This commit is contained in:
parent
ba2f23de97
commit
c9b29d8c34
1 changed files with 22 additions and 24 deletions
|
@ -11,6 +11,8 @@ import dotenv # type: ignore
|
||||||
import requests # type: ignore
|
import requests # type: ignore
|
||||||
from pydantic import BaseModel # type: ignore
|
from pydantic import BaseModel # type: ignore
|
||||||
|
|
||||||
|
import litellm
|
||||||
|
from litellm._logging import verbose_logger
|
||||||
from litellm.integrations.custom_logger import CustomLogger
|
from litellm.integrations.custom_logger import CustomLogger
|
||||||
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
|
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
|
||||||
|
|
||||||
|
@ -59,9 +61,7 @@ class LangsmithLogger(CustomLogger):
|
||||||
)
|
)
|
||||||
self.async_httpx_client = AsyncHTTPHandler()
|
self.async_httpx_client = AsyncHTTPHandler()
|
||||||
|
|
||||||
def _prepare_log_data(
|
def _prepare_log_data(self, kwargs, response_obj, start_time, end_time):
|
||||||
self, kwargs, response_obj, start_time, end_time, print_verbose
|
|
||||||
):
|
|
||||||
import datetime
|
import datetime
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class LangsmithLogger(CustomLogger):
|
||||||
project_name = metadata.get("project_name", self.langsmith_project)
|
project_name = metadata.get("project_name", self.langsmith_project)
|
||||||
run_name = metadata.get("run_name", self.langsmith_default_run_name)
|
run_name = metadata.get("run_name", self.langsmith_default_run_name)
|
||||||
run_id = metadata.get("id", None)
|
run_id = metadata.get("id", None)
|
||||||
print_verbose(
|
verbose_logger.debug(
|
||||||
f"Langsmith Logging - project_name: {project_name}, run_name {run_name}"
|
f"Langsmith Logging - project_name: {project_name}, run_name {run_name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -120,15 +120,11 @@ class LangsmithLogger(CustomLogger):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
async def async_log_event(
|
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
|
||||||
self, kwargs, response_obj, start_time, end_time, print_verbose
|
|
||||||
):
|
|
||||||
try:
|
try:
|
||||||
data = self._prepare_log_data(
|
data = self._prepare_log_data(kwargs, response_obj, start_time, end_time)
|
||||||
kwargs, response_obj, start_time, end_time, print_verbose
|
|
||||||
)
|
|
||||||
url = f"{self.langsmith_base_url}/runs"
|
url = f"{self.langsmith_base_url}/runs"
|
||||||
print_verbose(f"Langsmith Logging - About to send data to {url} ...")
|
verbose_logger.debug(f"Langsmith Logging - About to send data to {url} ...")
|
||||||
|
|
||||||
headers = {"x-api-key": self.langsmith_api_key}
|
headers = {"x-api-key": self.langsmith_api_key}
|
||||||
response = await self.async_httpx_client.post(
|
response = await self.async_httpx_client.post(
|
||||||
|
@ -136,22 +132,24 @@ class LangsmithLogger(CustomLogger):
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.status_code >= 300:
|
if response.status_code >= 300:
|
||||||
print_verbose(f"Error: {response.status_code}")
|
verbose_logger.error(
|
||||||
|
f"Langmsith Error: {response.status_code} - {response.text}"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print_verbose("Run successfully created")
|
verbose_logger.debug(
|
||||||
print_verbose(
|
"Run successfully created, response=%s", response.text
|
||||||
|
)
|
||||||
|
verbose_logger.debug(
|
||||||
f"Langsmith Layer Logging - final response object: {response_obj}. Response text from langsmith={response.text}"
|
f"Langsmith Layer Logging - final response object: {response_obj}. Response text from langsmith={response.text}"
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
print_verbose(f"Langsmith Layer Error - {traceback.format_exc()}")
|
verbose_logger.error(f"Langsmith Layer Error - {traceback.format_exc()}")
|
||||||
|
|
||||||
def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose):
|
def log_success_event(self, kwargs, response_obj, start_time, end_time):
|
||||||
try:
|
try:
|
||||||
data = self._prepare_log_data(
|
data = self._prepare_log_data(kwargs, response_obj, start_time, end_time)
|
||||||
kwargs, response_obj, start_time, end_time, print_verbose
|
|
||||||
)
|
|
||||||
url = f"{self.langsmith_base_url}/runs"
|
url = f"{self.langsmith_base_url}/runs"
|
||||||
print_verbose(f"Langsmith Logging - About to send data to {url} ...")
|
verbose_logger.debug(f"Langsmith Logging - About to send data to {url} ...")
|
||||||
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=url,
|
url=url,
|
||||||
|
@ -160,14 +158,14 @@ class LangsmithLogger(CustomLogger):
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.status_code >= 300:
|
if response.status_code >= 300:
|
||||||
print_verbose(f"Error: {response.status_code}")
|
verbose_logger.error(f"Error: {response.status_code}")
|
||||||
else:
|
else:
|
||||||
print_verbose("Run successfully created")
|
verbose_logger.debug("Run successfully created")
|
||||||
print_verbose(
|
verbose_logger.debug(
|
||||||
f"Langsmith Layer Logging - final response object: {response_obj}. Response text from langsmith={response.text}"
|
f"Langsmith Layer Logging - final response object: {response_obj}. Response text from langsmith={response.text}"
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
print_verbose(f"Langsmith Layer Error - {traceback.format_exc()}")
|
verbose_logger.error(f"Langsmith Layer Error - {traceback.format_exc()}")
|
||||||
|
|
||||||
def get_run_by_id(self, run_id):
|
def get_run_by_id(self, run_id):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue