Work with custom LANGSMITH_BASE_URL

This allows working with a custom Langsmith base URL. For example,
I can use this to test against a local Langsmith instance, running on
my laptop with Docker by adding this to the proxy config:

```yaml
litellm_settings:
  success_callback: ["langsmith"]

environment_variables:
  LANGSMITH_BASE_URL: "http://localhost:1984"
  LANGSMITH_PROJECT: "litellm-proxy"
```
This commit is contained in:
Marc Abramowitz 2024-05-16 17:01:14 -07:00
parent b170259a88
commit bf4f08ac30
2 changed files with 24 additions and 1 deletions

View file

@ -44,6 +44,8 @@ class LangsmithLogger:
print_verbose(
f"Langsmith Logging - project_name: {project_name}, run_name {run_name}"
)
langsmith_base_url = os.getenv("LANGSMITH_BASE_URL", "https://api.smith.langchain.com")
try:
print_verbose(
f"Langsmith Logging - Enters logging function for model {kwargs}"
@ -86,8 +88,12 @@ class LangsmithLogger:
"end_time": end_time,
}
url = f"{langsmith_base_url}/runs"
print_verbose(
f"Langsmith Logging - About to send data to {url} ..."
)
response = requests.post(
"https://api.smith.langchain.com/runs",
url=url,
json=data,
headers={"x-api-key": self.langsmith_api_key},
)