fix: langsmith callback 防覆盖 + 加 optional dep

This commit is contained in:
Xubin Ren
2026-03-13 04:54:22 +00:00
parent da325e4532
commit 20b4fb3bff
2 changed files with 8 additions and 4 deletions

View File

@@ -62,6 +62,8 @@ class LiteLLMProvider(LLMProvider):
# Drop unsupported parameters for providers (e.g., gpt-5 rejects some params)
litellm.drop_params = True
self._langsmith_enabled = bool(os.getenv("LANGSMITH_API_KEY"))
def _setup_env(self, api_key: str, api_base: str | None, model: str) -> None:
"""Set environment variables based on detected provider."""
spec = self._gateway or find_by_model(model)
@@ -250,10 +252,9 @@ class LiteLLMProvider(LLMProvider):
# Apply model-specific overrides (e.g. kimi-k2.5 temperature)
self._apply_model_overrides(model, kwargs)
# Use langsmith to view the conversation
if os.getenv("LANGSMITH_API_KEY"):
kwargs["callbacks"] = ["langsmith"]
if self._langsmith_enabled:
kwargs.setdefault("callbacks", []).append("langsmith")
# Pass api_key directly — more reliable than env vars alone
if self.api_key:
kwargs["api_key"] = self.api_key

View File

@@ -56,6 +56,9 @@ matrix = [
"mistune>=3.0.0,<4.0.0",
"nh3>=0.2.17,<1.0.0",
]
langsmith = [
"langsmith>=0.1.0",
]
dev = [
"pytest>=9.0.0,<10.0.0",
"pytest-asyncio>=1.3.0,<2.0.0",