fix: langsmith callback 防覆盖 + 加 optional dep
This commit is contained in:
@@ -62,6 +62,8 @@ class LiteLLMProvider(LLMProvider):
|
|||||||
# Drop unsupported parameters for providers (e.g., gpt-5 rejects some params)
|
# Drop unsupported parameters for providers (e.g., gpt-5 rejects some params)
|
||||||
litellm.drop_params = True
|
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:
|
def _setup_env(self, api_key: str, api_base: str | None, model: str) -> None:
|
||||||
"""Set environment variables based on detected provider."""
|
"""Set environment variables based on detected provider."""
|
||||||
spec = self._gateway or find_by_model(model)
|
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)
|
# Apply model-specific overrides (e.g. kimi-k2.5 temperature)
|
||||||
self._apply_model_overrides(model, kwargs)
|
self._apply_model_overrides(model, kwargs)
|
||||||
|
|
||||||
# Use langsmith to view the conversation
|
if self._langsmith_enabled:
|
||||||
if os.getenv("LANGSMITH_API_KEY"):
|
kwargs.setdefault("callbacks", []).append("langsmith")
|
||||||
kwargs["callbacks"] = ["langsmith"]
|
|
||||||
|
|
||||||
# Pass api_key directly — more reliable than env vars alone
|
# Pass api_key directly — more reliable than env vars alone
|
||||||
if self.api_key:
|
if self.api_key:
|
||||||
kwargs["api_key"] = self.api_key
|
kwargs["api_key"] = self.api_key
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ matrix = [
|
|||||||
"mistune>=3.0.0,<4.0.0",
|
"mistune>=3.0.0,<4.0.0",
|
||||||
"nh3>=0.2.17,<1.0.0",
|
"nh3>=0.2.17,<1.0.0",
|
||||||
]
|
]
|
||||||
|
langsmith = [
|
||||||
|
"langsmith>=0.1.0",
|
||||||
|
]
|
||||||
dev = [
|
dev = [
|
||||||
"pytest>=9.0.0,<10.0.0",
|
"pytest>=9.0.0,<10.0.0",
|
||||||
"pytest-asyncio>=1.3.0,<2.0.0",
|
"pytest-asyncio>=1.3.0,<2.0.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user