mirror of
https://github.com/hwchase17/langchain.git
synced 2026-04-17 18:33:17 +00:00
Compare commits
6 Commits
langchain-
...
bot/refres
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9622f6015 | ||
|
|
6fb37dba71 | ||
|
|
a029c7bf1d | ||
|
|
af0e174ef7 | ||
|
|
b00646d882 | ||
|
|
c04e05feb1 |
@@ -2,6 +2,7 @@ import re
|
||||
from collections.abc import Sequence
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Literal,
|
||||
TypedDict,
|
||||
TypeVar,
|
||||
@@ -14,6 +15,21 @@ from langchain_core.messages.content import (
|
||||
)
|
||||
|
||||
|
||||
def _filter_invocation_params_for_tracing(params: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Filter out large/inappropriate fields from invocation params for tracing.
|
||||
|
||||
Removes fields like tools, functions, messages, response_format that can be large.
|
||||
|
||||
Args:
|
||||
params: The invocation parameters to filter.
|
||||
|
||||
Returns:
|
||||
The filtered parameters with large fields removed.
|
||||
"""
|
||||
excluded_keys = {"tools", "functions", "messages", "response_format"}
|
||||
return {k: v for k, v in params.items() if k not in excluded_keys}
|
||||
|
||||
|
||||
def is_openai_data_block(
|
||||
block: dict, filter_: Literal["image", "audio", "file"] | None = None
|
||||
) -> bool:
|
||||
|
||||
@@ -25,6 +25,7 @@ from langchain_core.callbacks import (
|
||||
)
|
||||
from langchain_core.globals import get_llm_cache
|
||||
from langchain_core.language_models._utils import (
|
||||
_filter_invocation_params_for_tracing,
|
||||
_normalize_messages,
|
||||
_update_message_content_to_blocks,
|
||||
)
|
||||
@@ -567,6 +568,9 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
|
||||
self.tags,
|
||||
inheritable_metadata,
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
(run_manager,) = callback_manager.on_chat_model_start(
|
||||
self._serialized,
|
||||
@@ -695,6 +699,9 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
|
||||
self.tags,
|
||||
inheritable_metadata,
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
(run_manager,) = await callback_manager.on_chat_model_start(
|
||||
self._serialized,
|
||||
@@ -972,6 +979,9 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
|
||||
self.tags,
|
||||
inheritable_metadata,
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
messages_to_trace = [
|
||||
_format_for_tracing(message_list) for message_list in messages
|
||||
@@ -1095,6 +1105,9 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC):
|
||||
self.tags,
|
||||
inheritable_metadata,
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
|
||||
messages_to_trace = [
|
||||
|
||||
@@ -42,6 +42,7 @@ from langchain_core.callbacks import (
|
||||
Callbacks,
|
||||
)
|
||||
from langchain_core.globals import get_llm_cache
|
||||
from langchain_core.language_models._utils import _filter_invocation_params_for_tracing
|
||||
from langchain_core.language_models.base import (
|
||||
BaseLanguageModel,
|
||||
LangSmithParams,
|
||||
@@ -537,6 +538,9 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
self.tags,
|
||||
inheritable_metadata,
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
(run_manager,) = callback_manager.on_llm_start(
|
||||
self._serialized,
|
||||
@@ -607,6 +611,9 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
self.tags,
|
||||
inheritable_metadata,
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
(run_manager,) = await callback_manager.on_llm_start(
|
||||
self._serialized,
|
||||
@@ -950,6 +957,8 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
run_name_list = run_name or cast(
|
||||
"list[str | None]", ([None] * len(prompts))
|
||||
)
|
||||
params = self.dict()
|
||||
params["stop"] = stop
|
||||
callback_managers = [
|
||||
CallbackManager.configure(
|
||||
callback,
|
||||
@@ -959,6 +968,9 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
self.tags,
|
||||
meta,
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
for callback, tag, meta in zip(
|
||||
callbacks, tags_list, metadata_list, strict=False
|
||||
@@ -966,6 +978,8 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
]
|
||||
else:
|
||||
# We've received a single callbacks arg to apply to all inputs
|
||||
params = self.dict()
|
||||
params["stop"] = stop
|
||||
callback_managers = [
|
||||
CallbackManager.configure(
|
||||
cast("Callbacks", callbacks),
|
||||
@@ -975,12 +989,13 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
self.tags,
|
||||
cast("dict[str, Any]", metadata),
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
] * len(prompts)
|
||||
run_name_list = [cast("str | None", run_name)] * len(prompts)
|
||||
run_ids_list = self._get_run_ids_list(run_id, prompts)
|
||||
params = self.dict()
|
||||
params["stop"] = stop
|
||||
options = {"stop": stop}
|
||||
(
|
||||
existing_prompts,
|
||||
@@ -1214,6 +1229,8 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
run_name_list = run_name or cast(
|
||||
"list[str | None]", ([None] * len(prompts))
|
||||
)
|
||||
params = self.dict()
|
||||
params["stop"] = stop
|
||||
callback_managers = [
|
||||
AsyncCallbackManager.configure(
|
||||
callback,
|
||||
@@ -1223,6 +1240,9 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
self.tags,
|
||||
meta,
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
for callback, tag, meta in zip(
|
||||
callbacks, tags_list, metadata_list, strict=False
|
||||
@@ -1230,6 +1250,8 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
]
|
||||
else:
|
||||
# We've received a single callbacks arg to apply to all inputs
|
||||
params = self.dict()
|
||||
params["stop"] = stop
|
||||
callback_managers = [
|
||||
AsyncCallbackManager.configure(
|
||||
cast("Callbacks", callbacks),
|
||||
@@ -1239,12 +1261,13 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
self.tags,
|
||||
cast("dict[str, Any]", metadata),
|
||||
self.metadata,
|
||||
langsmith_inheritable_metadata=_filter_invocation_params_for_tracing(
|
||||
params
|
||||
),
|
||||
)
|
||||
] * len(prompts)
|
||||
run_name_list = [cast("str | None", run_name)] * len(prompts)
|
||||
run_ids_list = self._get_run_ids_list(run_id, prompts)
|
||||
params = self.dict()
|
||||
params["stop"] = stop
|
||||
options = {"stop": stop}
|
||||
(
|
||||
existing_prompts,
|
||||
|
||||
@@ -286,11 +286,17 @@ def ensure_config(config: RunnableConfig | None = None) -> RunnableConfig:
|
||||
for k, v in config.items():
|
||||
if k not in CONFIG_KEYS and v is not None:
|
||||
empty["configurable"][k] = v
|
||||
if (
|
||||
isinstance(model := empty.get("configurable", {}).get("model"), str)
|
||||
and "model" not in empty["metadata"]
|
||||
):
|
||||
empty["metadata"]["model"] = model
|
||||
for configurable_key in ("model", "checkpoint_ns"):
|
||||
if (
|
||||
isinstance(
|
||||
configurable_value := empty.get("configurable", {}).get(
|
||||
configurable_key
|
||||
),
|
||||
str,
|
||||
)
|
||||
and configurable_key not in empty["metadata"]
|
||||
):
|
||||
empty["metadata"][configurable_key] = configurable_value
|
||||
return empty
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""langchain-core version information and utilities."""
|
||||
|
||||
VERSION = "1.3.0a2"
|
||||
VERSION = "1.3.0a3"
|
||||
|
||||
@@ -21,7 +21,7 @@ classifiers = [
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
]
|
||||
|
||||
version = "1.3.0a2"
|
||||
version = "1.3.0a3"
|
||||
requires-python = ">=3.10.0,<4.0.0"
|
||||
dependencies = [
|
||||
"langsmith>=0.3.45,<1.0.0",
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
import uuid
|
||||
import warnings
|
||||
from collections.abc import AsyncIterator, Iterator
|
||||
from contextlib import contextmanager
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from pydantic import model_validator
|
||||
@@ -17,8 +19,14 @@ from langchain_core.language_models import (
|
||||
FakeListChatModel,
|
||||
ParrotFakeChatModel,
|
||||
)
|
||||
from langchain_core.language_models._utils import _normalize_messages
|
||||
from langchain_core.language_models.chat_models import _generate_response_from_error
|
||||
from langchain_core.language_models._utils import (
|
||||
_filter_invocation_params_for_tracing,
|
||||
_normalize_messages,
|
||||
)
|
||||
from langchain_core.language_models.chat_models import (
|
||||
SimpleChatModel,
|
||||
_generate_response_from_error,
|
||||
)
|
||||
from langchain_core.language_models.fake_chat_models import (
|
||||
FakeListChatModelError,
|
||||
GenericFakeChatModel,
|
||||
@@ -37,6 +45,7 @@ from langchain_core.tracers import LogStreamCallbackHandler
|
||||
from langchain_core.tracers.base import BaseTracer
|
||||
from langchain_core.tracers.context import collect_runs
|
||||
from langchain_core.tracers.event_stream import _AstreamEventsCallbackHandler
|
||||
from langchain_core.tracers.langchain import LangChainTracer
|
||||
from langchain_core.tracers.schemas import Run
|
||||
from tests.unit_tests.fake.callbacks import (
|
||||
BaseFakeCallbackHandler,
|
||||
@@ -321,6 +330,20 @@ class FakeTracer(BaseTracer):
|
||||
self.traced_run_ids.append(run.id)
|
||||
|
||||
|
||||
class LangChainTracerRunCollector:
|
||||
def __init__(self) -> None:
|
||||
self.tracer = LangChainTracer()
|
||||
self.runs: list[Run] = []
|
||||
|
||||
@contextmanager
|
||||
def tracing_callback(self) -> Iterator[LangChainTracer]:
|
||||
def collect_tracer_run(_: LangChainTracer, run: Run) -> None:
|
||||
self.runs.append(run)
|
||||
|
||||
with patch.object(LangChainTracer, "_persist_run", new=collect_tracer_run):
|
||||
yield self.tracer
|
||||
|
||||
|
||||
def test_pass_run_id() -> None:
|
||||
llm = FakeListChatModel(responses=["a", "b", "c"])
|
||||
cb = FakeTracer()
|
||||
@@ -1390,3 +1413,100 @@ def test_generate_response_from_error_handles_streaming_response_failure() -> No
|
||||
assert metadata["body"] is None
|
||||
assert metadata["headers"] == {"content-type": "application/json"}
|
||||
assert metadata["status_code"] == 400
|
||||
|
||||
|
||||
def test_filter_invocation_params_for_tracing() -> None:
|
||||
"""Test that large fields are filtered from invocation params for tracing."""
|
||||
params = {
|
||||
"temperature": 0.7,
|
||||
"tools": [{"name": "test_tool"}],
|
||||
"functions": [{"name": "test_function"}],
|
||||
"messages": [{"role": "system", "content": "test"}],
|
||||
"response_format": {"type": "json_object"},
|
||||
}
|
||||
filtered = _filter_invocation_params_for_tracing(params)
|
||||
|
||||
# Should include temperature
|
||||
assert "temperature" in filtered
|
||||
assert filtered["temperature"] == 0.7
|
||||
|
||||
# Should exclude these large fields
|
||||
assert "tools" not in filtered
|
||||
assert "functions" not in filtered
|
||||
assert "messages" not in filtered
|
||||
assert "response_format" not in filtered
|
||||
|
||||
|
||||
class FakeChatModelWithInvocationParams(SimpleChatModel):
|
||||
"""Fake chat model with invocation params for testing tracing."""
|
||||
|
||||
temperature: float = 0.7
|
||||
|
||||
@property
|
||||
@override
|
||||
def _llm_type(self) -> str:
|
||||
return "fake-chat-model-with-invocation-params"
|
||||
|
||||
@property
|
||||
@override
|
||||
def _identifying_params(self) -> dict[str, Any]:
|
||||
return {
|
||||
"temperature": self.temperature,
|
||||
"tools": [{"name": "test_tool"}],
|
||||
"functions": [{"name": "test_function"}],
|
||||
"messages": [{"role": "system", "content": "test"}],
|
||||
"response_format": {"type": "json_object"},
|
||||
}
|
||||
|
||||
@override
|
||||
def _call(
|
||||
self,
|
||||
messages: list[BaseMessage],
|
||||
stop: list[str] | None = None,
|
||||
run_manager: CallbackManagerForLLMRun | None = None,
|
||||
**kwargs: Any,
|
||||
) -> str:
|
||||
return "test response"
|
||||
|
||||
|
||||
def test_invocation_params_passed_to_tracer_metadata() -> None:
|
||||
"""Test that invocation params are passed to tracer metadata."""
|
||||
llm = FakeChatModelWithInvocationParams()
|
||||
collector = LangChainTracerRunCollector()
|
||||
|
||||
with collector.tracing_callback() as tracer:
|
||||
llm.invoke([HumanMessage(content="Hello")], config={"callbacks": [tracer]})
|
||||
|
||||
assert len(collector.runs) == 1
|
||||
run = collector.runs[0]
|
||||
|
||||
key = "LANGSMITH_LANGGRAPH_API_VARIANT"
|
||||
|
||||
if key in run.extra["metadata"]:
|
||||
del run.extra["metadata"][key]
|
||||
|
||||
assert run.extra == {
|
||||
"batch_size": 1,
|
||||
"invocation_params": {
|
||||
"_type": "fake-chat-model-with-invocation-params",
|
||||
"functions": [{"name": "test_function"}],
|
||||
"messages": [{"content": "test", "role": "system"}],
|
||||
"response_format": {"type": "json_object"},
|
||||
"stop": None,
|
||||
"temperature": 0.7,
|
||||
"tools": [{"name": "test_tool"}],
|
||||
},
|
||||
"metadata": {
|
||||
"_type": "fake-chat-model-with-invocation-params",
|
||||
"ls_integration": "langchain_chat_model",
|
||||
"ls_model_type": "chat",
|
||||
"ls_provider": "fakechatmodelwithinvocationparams",
|
||||
"ls_temperature": 0.7,
|
||||
"revision_id": run.extra["metadata"]["revision_id"],
|
||||
"stop": None,
|
||||
"temperature": 0.7,
|
||||
},
|
||||
"options": {"stop": None},
|
||||
"runtime": run.extra["runtime"],
|
||||
}
|
||||
assert run.metadata == run.extra["metadata"]
|
||||
|
||||
@@ -13,6 +13,7 @@ from langchain_core.language_models import (
|
||||
BaseLLM,
|
||||
FakeListLLM,
|
||||
)
|
||||
from langchain_core.language_models._utils import _filter_invocation_params_for_tracing
|
||||
from langchain_core.outputs import Generation, GenerationChunk, LLMResult
|
||||
from langchain_core.tracers.context import collect_runs
|
||||
from tests.unit_tests.fake.callbacks import (
|
||||
@@ -284,3 +285,94 @@ def test_get_ls_params() -> None:
|
||||
|
||||
ls_params = llm._get_ls_params(stop=["stop"])
|
||||
assert ls_params["ls_stop"] == ["stop"]
|
||||
|
||||
|
||||
def test_filter_invocation_params_for_tracing() -> None:
|
||||
"""Test that large fields are filtered from invocation params for tracing."""
|
||||
params = {
|
||||
"temperature": 0.7,
|
||||
"tools": [{"name": "test_tool"}],
|
||||
"functions": [{"name": "test_function"}],
|
||||
"messages": [{"role": "system", "content": "test"}],
|
||||
"response_format": {"type": "json_object"},
|
||||
}
|
||||
filtered = _filter_invocation_params_for_tracing(params)
|
||||
|
||||
# Should include temperature
|
||||
assert "temperature" in filtered
|
||||
assert filtered["temperature"] == 0.7
|
||||
|
||||
# Should exclude these large fields
|
||||
assert "tools" not in filtered
|
||||
assert "functions" not in filtered
|
||||
assert "messages" not in filtered
|
||||
assert "response_format" not in filtered
|
||||
|
||||
|
||||
class FakeLLMWithInvocationParams(BaseLLM):
|
||||
"""Fake LLM with invocation params for testing tracing."""
|
||||
|
||||
temperature: float = 0.7
|
||||
|
||||
@property
|
||||
@override
|
||||
def _llm_type(self) -> str:
|
||||
return "fake-llm-with-invocation-params"
|
||||
|
||||
@property
|
||||
@override
|
||||
def _identifying_params(self) -> dict[str, Any]:
|
||||
return {
|
||||
"temperature": self.temperature,
|
||||
"tools": [{"name": "test_tool"}],
|
||||
"functions": [{"name": "test_function"}],
|
||||
"messages": [{"role": "system", "content": "test"}],
|
||||
"response_format": {"type": "json_object"},
|
||||
}
|
||||
|
||||
@override
|
||||
def _generate(
|
||||
self,
|
||||
prompts: list[str],
|
||||
stop: list[str] | None = None,
|
||||
run_manager: CallbackManagerForLLMRun | None = None,
|
||||
**kwargs: Any,
|
||||
) -> LLMResult:
|
||||
generations = [[Generation(text="test response")]]
|
||||
return LLMResult(generations=generations)
|
||||
|
||||
@override
|
||||
async def _agenerate(
|
||||
self,
|
||||
prompts: list[str],
|
||||
stop: list[str] | None = None,
|
||||
run_manager: AsyncCallbackManagerForLLMRun | None = None,
|
||||
**kwargs: Any,
|
||||
) -> LLMResult:
|
||||
generations = [[Generation(text="test response")]]
|
||||
return LLMResult(generations=generations)
|
||||
|
||||
|
||||
async def test_llm_invocation_params_filtered_in_stream() -> None:
|
||||
"""Test that invocation params are filtered when streaming."""
|
||||
|
||||
# Create a custom LLM that supports streaming
|
||||
class FakeStreamingLLM(FakeLLMWithInvocationParams):
|
||||
@override
|
||||
def _stream(
|
||||
self,
|
||||
prompt: str,
|
||||
stop: list[str] | None = None,
|
||||
run_manager: CallbackManagerForLLMRun | None = None,
|
||||
**kwargs: Any,
|
||||
) -> Iterator[GenerationChunk]:
|
||||
yield GenerationChunk(text="test ")
|
||||
|
||||
streaming_llm = FakeStreamingLLM()
|
||||
|
||||
with collect_runs() as cb:
|
||||
list(streaming_llm.stream("Hello", config={"callbacks": [cb]}))
|
||||
assert len(cb.traced_runs) == 1
|
||||
run = cb.traced_runs[0]
|
||||
# Verify the run was traced
|
||||
assert run.extra is not None
|
||||
|
||||
@@ -95,7 +95,11 @@ def test_ensure_config_copies_model_to_metadata() -> None:
|
||||
}
|
||||
)
|
||||
|
||||
assert config["metadata"] == {"nooverride": 18, "model": "gpt-4o"}
|
||||
assert config["metadata"] == {
|
||||
"nooverride": 18,
|
||||
"model": "gpt-4o",
|
||||
"checkpoint_ns": "ns-1",
|
||||
}
|
||||
assert config["configurable"] == {
|
||||
"thread_id": "th-123",
|
||||
"checkpoint_id": "ckpt-1",
|
||||
@@ -157,6 +161,21 @@ def test_ensure_config_copies_top_level_model_to_metadata() -> None:
|
||||
assert config["configurable"] == {"model": "gpt-4o"}
|
||||
|
||||
|
||||
def test_ensure_config_copies_top_level_checkpoint_ns_to_metadata() -> None:
|
||||
config = ensure_config(
|
||||
cast(
|
||||
"RunnableConfig",
|
||||
{
|
||||
"checkpoint_ns": "ns-1",
|
||||
"metadata": {"nooverride": 18},
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
assert config["metadata"] == {"nooverride": 18, "checkpoint_ns": "ns-1"}
|
||||
assert config["configurable"] == {"checkpoint_ns": "ns-1"}
|
||||
|
||||
|
||||
def test_get_langsmith_inheritable_metadata_from_config_uses_previous_copy_rules() -> (
|
||||
None
|
||||
):
|
||||
|
||||
4
libs/core/uv.lock
generated
4
libs/core/uv.lock
generated
@@ -995,7 +995,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "langchain-core"
|
||||
version = "1.3.0a2"
|
||||
version = "1.3.0a3"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "jsonpatch" },
|
||||
@@ -1134,7 +1134,7 @@ typing = [
|
||||
|
||||
[[package]]
|
||||
name = "langchain-text-splitters"
|
||||
version = "1.1.1"
|
||||
version = "1.1.2"
|
||||
source = { directory = "../text-splitters" }
|
||||
dependencies = [
|
||||
{ name = "langchain-core" },
|
||||
|
||||
@@ -441,6 +441,31 @@ _PROFILES: dict[str, dict[str, Any]] = {
|
||||
"image_tool_message": True,
|
||||
"structured_output": False,
|
||||
},
|
||||
"claude-opus-4-7": {
|
||||
"name": "Claude Opus 4.7",
|
||||
"release_date": "2026-04-16",
|
||||
"last_updated": "2026-04-16",
|
||||
"open_weights": False,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"text_inputs": True,
|
||||
"image_inputs": True,
|
||||
"audio_inputs": False,
|
||||
"pdf_inputs": True,
|
||||
"video_inputs": False,
|
||||
"text_outputs": True,
|
||||
"image_outputs": False,
|
||||
"audio_outputs": False,
|
||||
"video_outputs": False,
|
||||
"reasoning_output": True,
|
||||
"tool_calling": True,
|
||||
"attachment": True,
|
||||
"temperature": False,
|
||||
"image_url_inputs": True,
|
||||
"pdf_tool_message": True,
|
||||
"image_tool_message": True,
|
||||
"structured_output": False,
|
||||
},
|
||||
"claude-sonnet-4-0": {
|
||||
"name": "Claude Sonnet 4 (latest)",
|
||||
"release_date": "2025-05-22",
|
||||
|
||||
@@ -65,6 +65,12 @@ class HuggingFaceEndpointEmbeddings(BaseModel, Embeddings):
|
||||
@model_validator(mode="after")
|
||||
def validate_environment(self) -> Self:
|
||||
"""Validate that api key and python package exists in environment."""
|
||||
for field_name in ("model", "repo_id"):
|
||||
value = getattr(self, field_name)
|
||||
if value and value.startswith(("http://", "https://")):
|
||||
msg = f"`{field_name}` must be a HuggingFace repo ID, not a URL."
|
||||
raise ValueError(msg)
|
||||
|
||||
huggingfacehub_api_token = self.huggingfacehub_api_token or os.getenv(
|
||||
"HF_TOKEN"
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ import logging
|
||||
import os
|
||||
from collections.abc import AsyncIterator, Iterator, Mapping
|
||||
from typing import Any
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from langchain_core.callbacks import (
|
||||
AsyncCallbackManagerForLLMRun,
|
||||
@@ -23,8 +24,12 @@ def _is_huggingface_hosted_url(url: str | None) -> bool:
|
||||
"""True if url is HF-hosted (huggingface.co or hf.space)."""
|
||||
if not url:
|
||||
return False
|
||||
url_lower = url.lower().strip()
|
||||
return "huggingface.co" in url_lower or "hf.space" in url_lower
|
||||
hostname = (urlparse(url).hostname or "").lower()
|
||||
return (
|
||||
hostname == "huggingface.co"
|
||||
or hostname == "hf.space"
|
||||
or hostname.endswith((".huggingface.co", ".hf.space"))
|
||||
)
|
||||
|
||||
|
||||
VALID_TASKS = (
|
||||
@@ -220,6 +225,13 @@ class HuggingFaceEndpoint(LLM):
|
||||
endpoint_url = values.get("endpoint_url")
|
||||
repo_id = values.get("repo_id")
|
||||
|
||||
if repo_id and repo_id.startswith(("http://", "https://")):
|
||||
msg = (
|
||||
"`repo_id` must be a HuggingFace repo ID, not a URL. "
|
||||
"Use `endpoint_url` for direct endpoints."
|
||||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
if sum([bool(model), bool(endpoint_url), bool(repo_id)]) > 1:
|
||||
msg = (
|
||||
"Please specify either a `model` OR an `endpoint_url` OR a `repo_id`,"
|
||||
|
||||
@@ -20,10 +20,10 @@ classifiers = [
|
||||
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
||||
]
|
||||
|
||||
version = "1.2.1"
|
||||
version = "1.2.2"
|
||||
requires-python = ">=3.10.0,<4.0.0"
|
||||
dependencies = [
|
||||
"langchain-core>=1.2.21,<2.0.0",
|
||||
"langchain-core>=1.2.31,<2.0.0",
|
||||
"tokenizers>=0.19.1,<1.0.0",
|
||||
"huggingface-hub>=0.33.4,<2.0.0",
|
||||
]
|
||||
|
||||
11
libs/partners/huggingface/uv.lock
generated
11
libs/partners/huggingface/uv.lock
generated
@@ -1,5 +1,5 @@
|
||||
version = 1
|
||||
revision = 3
|
||||
revision = 2
|
||||
requires-python = ">=3.10.0, <4.0.0"
|
||||
resolution-markers = [
|
||||
"python_full_version >= '3.13' and platform_python_implementation == 'PyPy'",
|
||||
@@ -613,6 +613,7 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/7d/ed/6bfa4109fcb23a58819600392564fea69cdc6551ffd5e69ccf1d52a40cbc/greenlet-3.2.4-cp310-cp310-macosx_11_0_universal2.whl", hash = "sha256:8c68325b0d0acf8d91dde4e6f930967dd52a5302cd4062932a6b2e7c2969f47c", size = 271061, upload-time = "2025-08-07T13:17:15.373Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2a/fc/102ec1a2fc015b3a7652abab7acf3541d58c04d3d17a8d3d6a44adae1eb1/greenlet-3.2.4-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:94385f101946790ae13da500603491f04a76b6e4c059dab271b3ce2e283b2590", size = 629475, upload-time = "2025-08-07T13:42:54.009Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c5/26/80383131d55a4ac0fb08d71660fd77e7660b9db6bdb4e8884f46d9f2cc04/greenlet-3.2.4-cp310-cp310-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:f10fd42b5ee276335863712fa3da6608e93f70629c631bf77145021600abc23c", size = 640802, upload-time = "2025-08-07T13:45:25.52Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9f/7c/e7833dbcd8f376f3326bd728c845d31dcde4c84268d3921afcae77d90d08/greenlet-3.2.4-cp310-cp310-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:c8c9e331e58180d0d83c5b7999255721b725913ff6bc6cf39fa2a45841a4fd4b", size = 636703, upload-time = "2025-08-07T13:53:12.622Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e9/49/547b93b7c0428ede7b3f309bc965986874759f7d89e4e04aeddbc9699acb/greenlet-3.2.4-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:58b97143c9cc7b86fc458f215bd0932f1757ce649e05b640fea2e79b54cedb31", size = 635417, upload-time = "2025-08-07T13:18:25.189Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7f/91/ae2eb6b7979e2f9b035a9f612cf70f1bf54aad4e1d125129bef1eae96f19/greenlet-3.2.4-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c2ca18a03a8cfb5b25bc1cbe20f3d9a4c80d8c3b13ba3df49ac3961af0b1018d", size = 584358, upload-time = "2025-08-07T13:18:23.708Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f7/85/433de0c9c0252b22b16d413c9407e6cb3b41df7389afc366ca204dbc1393/greenlet-3.2.4-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:9fe0a28a7b952a21e2c062cd5756d34354117796c6d9215a87f55e38d15402c5", size = 1113550, upload-time = "2025-08-07T13:42:37.467Z" },
|
||||
@@ -623,6 +624,7 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/a4/de/f28ced0a67749cac23fecb02b694f6473f47686dff6afaa211d186e2ef9c/greenlet-3.2.4-cp311-cp311-macosx_11_0_universal2.whl", hash = "sha256:96378df1de302bc38e99c3a9aa311967b7dc80ced1dcc6f171e99842987882a2", size = 272305, upload-time = "2025-08-07T13:15:41.288Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/09/16/2c3792cba130000bf2a31c5272999113f4764fd9d874fb257ff588ac779a/greenlet-3.2.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:1ee8fae0519a337f2329cb78bd7a8e128ec0f881073d43f023c7b8d4831d5246", size = 632472, upload-time = "2025-08-07T13:42:55.044Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ae/8f/95d48d7e3d433e6dae5b1682e4292242a53f22df82e6d3dda81b1701a960/greenlet-3.2.4-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:94abf90142c2a18151632371140b3dba4dee031633fe614cb592dbb6c9e17bc3", size = 644646, upload-time = "2025-08-07T13:45:26.523Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d5/5e/405965351aef8c76b8ef7ad370e5da58d57ef6068df197548b015464001a/greenlet-3.2.4-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:4d1378601b85e2e5171b99be8d2dc85f594c79967599328f95c1dc1a40f1c633", size = 640519, upload-time = "2025-08-07T13:53:13.928Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/25/5d/382753b52006ce0218297ec1b628e048c4e64b155379331f25a7316eb749/greenlet-3.2.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:0db5594dce18db94f7d1650d7489909b57afde4c580806b8d9203b6e79cdc079", size = 639707, upload-time = "2025-08-07T13:18:27.146Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1f/8e/abdd3f14d735b2929290a018ecf133c901be4874b858dd1c604b9319f064/greenlet-3.2.4-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2523e5246274f54fdadbce8494458a2ebdcdbc7b802318466ac5606d3cded1f8", size = 587684, upload-time = "2025-08-07T13:18:25.164Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/5d/65/deb2a69c3e5996439b0176f6651e0052542bb6c8f8ec2e3fba97c9768805/greenlet-3.2.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:1987de92fec508535687fb807a5cea1560f6196285a4cde35c100b8cd632cc52", size = 1116647, upload-time = "2025-08-07T13:42:38.655Z" },
|
||||
@@ -633,6 +635,7 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/44/69/9b804adb5fd0671f367781560eb5eb586c4d495277c93bde4307b9e28068/greenlet-3.2.4-cp312-cp312-macosx_11_0_universal2.whl", hash = "sha256:3b67ca49f54cede0186854a008109d6ee71f66bd57bb36abd6d0a0267b540cdd", size = 274079, upload-time = "2025-08-07T13:15:45.033Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/46/e9/d2a80c99f19a153eff70bc451ab78615583b8dac0754cfb942223d2c1a0d/greenlet-3.2.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:ddf9164e7a5b08e9d22511526865780a576f19ddd00d62f8a665949327fde8bb", size = 640997, upload-time = "2025-08-07T13:42:56.234Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/3b/16/035dcfcc48715ccd345f3a93183267167cdd162ad123cd93067d86f27ce4/greenlet-3.2.4-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:f28588772bb5fb869a8eb331374ec06f24a83a9c25bfa1f38b6993afe9c1e968", size = 655185, upload-time = "2025-08-07T13:45:27.624Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/31/da/0386695eef69ffae1ad726881571dfe28b41970173947e7c558d9998de0f/greenlet-3.2.4-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:5c9320971821a7cb77cfab8d956fa8e39cd07ca44b6070db358ceb7f8797c8c9", size = 649926, upload-time = "2025-08-07T13:53:15.251Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/68/88/69bf19fd4dc19981928ceacbc5fd4bb6bc2215d53199e367832e98d1d8fe/greenlet-3.2.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c60a6d84229b271d44b70fb6e5fa23781abb5d742af7b808ae3f6efd7c9c60f6", size = 651839, upload-time = "2025-08-07T13:18:30.281Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/19/0d/6660d55f7373b2ff8152401a83e02084956da23ae58cddbfb0b330978fe9/greenlet-3.2.4-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3b3812d8d0c9579967815af437d96623f45c0f2ae5f04e366de62a12d83a8fb0", size = 607586, upload-time = "2025-08-07T13:18:28.544Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8e/1a/c953fdedd22d81ee4629afbb38d2f9d71e37d23caace44775a3a969147d4/greenlet-3.2.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:abbf57b5a870d30c4675928c37278493044d7c14378350b3aa5d484fa65575f0", size = 1123281, upload-time = "2025-08-07T13:42:39.858Z" },
|
||||
@@ -643,6 +646,7 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/49/e8/58c7f85958bda41dafea50497cbd59738c5c43dbbea5ee83d651234398f4/greenlet-3.2.4-cp313-cp313-macosx_11_0_universal2.whl", hash = "sha256:1a921e542453fe531144e91e1feedf12e07351b1cf6c9e8a3325ea600a715a31", size = 272814, upload-time = "2025-08-07T13:15:50.011Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/62/dd/b9f59862e9e257a16e4e610480cfffd29e3fae018a68c2332090b53aac3d/greenlet-3.2.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:cd3c8e693bff0fff6ba55f140bf390fa92c994083f838fece0f63be121334945", size = 641073, upload-time = "2025-08-07T13:42:57.23Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f7/0b/bc13f787394920b23073ca3b6c4a7a21396301ed75a655bcb47196b50e6e/greenlet-3.2.4-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:710638eb93b1fa52823aa91bf75326f9ecdfd5e0466f00789246a5280f4ba0fc", size = 655191, upload-time = "2025-08-07T13:45:29.752Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f2/d6/6adde57d1345a8d0f14d31e4ab9c23cfe8e2cd39c3baf7674b4b0338d266/greenlet-3.2.4-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:c5111ccdc9c88f423426df3fd1811bfc40ed66264d35aa373420a34377efc98a", size = 649516, upload-time = "2025-08-07T13:53:16.314Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/7f/3b/3a3328a788d4a473889a2d403199932be55b1b0060f4ddd96ee7cdfcad10/greenlet-3.2.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:d76383238584e9711e20ebe14db6c88ddcedc1829a9ad31a584389463b5aa504", size = 652169, upload-time = "2025-08-07T13:18:32.861Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/ee/43/3cecdc0349359e1a527cbf2e3e28e5f8f06d3343aaf82ca13437a9aa290f/greenlet-3.2.4-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:23768528f2911bcd7e475210822ffb5254ed10d71f4028387e5a99b4c6699671", size = 610497, upload-time = "2025-08-07T13:18:31.636Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b8/19/06b6cf5d604e2c382a6f31cafafd6f33d5dea706f4db7bdab184bad2b21d/greenlet-3.2.4-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:00fadb3fedccc447f517ee0d3fd8fe49eae949e1cd0f6a611818f4f6fb7dc83b", size = 1121662, upload-time = "2025-08-07T13:42:41.117Z" },
|
||||
@@ -653,6 +657,7 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/22/5c/85273fd7cc388285632b0498dbbab97596e04b154933dfe0f3e68156c68c/greenlet-3.2.4-cp314-cp314-macosx_11_0_universal2.whl", hash = "sha256:49a30d5fda2507ae77be16479bdb62a660fa51b1eb4928b524975b3bde77b3c0", size = 273586, upload-time = "2025-08-07T13:16:08.004Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/d1/75/10aeeaa3da9332c2e761e4c50d4c3556c21113ee3f0afa2cf5769946f7a3/greenlet-3.2.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:299fd615cd8fc86267b47597123e3f43ad79c9d8a22bebdce535e53550763e2f", size = 686346, upload-time = "2025-08-07T13:42:59.944Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c0/aa/687d6b12ffb505a4447567d1f3abea23bd20e73a5bed63871178e0831b7a/greenlet-3.2.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:c17b6b34111ea72fc5a4e4beec9711d2226285f0386ea83477cbb97c30a3f3a5", size = 699218, upload-time = "2025-08-07T13:45:30.969Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/dc/8b/29aae55436521f1d6f8ff4e12fb676f3400de7fcf27fccd1d4d17fd8fecd/greenlet-3.2.4-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:b4a1870c51720687af7fa3e7cda6d08d801dae660f75a76f3845b642b4da6ee1", size = 694659, upload-time = "2025-08-07T13:53:17.759Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/92/2e/ea25914b1ebfde93b6fc4ff46d6864564fba59024e928bdc7de475affc25/greenlet-3.2.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:061dc4cf2c34852b052a8620d40f36324554bc192be474b9e9770e8c042fd735", size = 695355, upload-time = "2025-08-07T13:18:34.517Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/72/60/fc56c62046ec17f6b0d3060564562c64c862948c9d4bc8aa807cf5bd74f4/greenlet-3.2.4-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:44358b9bf66c8576a9f57a590d5f5d6e72fa4228b763d0e43fee6d3b06d3a337", size = 657512, upload-time = "2025-08-07T13:18:33.969Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/23/6e/74407aed965a4ab6ddd93a7ded3180b730d281c77b765788419484cdfeef/greenlet-3.2.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:2917bdf657f5859fbf3386b12d68ede4cf1f04c90c3a6bc1f013dd68a22e2269", size = 1612508, upload-time = "2025-11-04T12:42:23.427Z" },
|
||||
@@ -1044,7 +1049,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "langchain-core"
|
||||
version = "1.3.0a2"
|
||||
version = "1.3.0a3"
|
||||
source = { editable = "../../core" }
|
||||
dependencies = [
|
||||
{ name = "jsonpatch" },
|
||||
@@ -1104,7 +1109,7 @@ typing = [
|
||||
|
||||
[[package]]
|
||||
name = "langchain-huggingface"
|
||||
version = "1.2.1"
|
||||
version = "1.2.2"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "huggingface-hub" },
|
||||
|
||||
@@ -167,6 +167,28 @@ _PROFILES: dict[str, dict[str, Any]] = {
|
||||
"attachment": True,
|
||||
"temperature": True,
|
||||
},
|
||||
"anthropic/claude-opus-4.7": {
|
||||
"name": "Claude Opus 4.7",
|
||||
"release_date": "2026-04-16",
|
||||
"last_updated": "2026-04-16",
|
||||
"open_weights": False,
|
||||
"max_input_tokens": 1000000,
|
||||
"max_output_tokens": 128000,
|
||||
"text_inputs": True,
|
||||
"image_inputs": True,
|
||||
"audio_inputs": False,
|
||||
"pdf_inputs": True,
|
||||
"video_inputs": False,
|
||||
"text_outputs": True,
|
||||
"image_outputs": False,
|
||||
"audio_outputs": False,
|
||||
"video_outputs": False,
|
||||
"reasoning_output": True,
|
||||
"tool_calling": True,
|
||||
"structured_output": True,
|
||||
"attachment": True,
|
||||
"temperature": False,
|
||||
},
|
||||
"anthropic/claude-sonnet-4": {
|
||||
"name": "Claude Sonnet 4",
|
||||
"release_date": "2025-05-22",
|
||||
|
||||
Reference in New Issue
Block a user