From e023201d4214bf06904ac3cb4a2855516456b0ce Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Thu, 6 Nov 2025 23:50:46 -0500 Subject: [PATCH] style: some cleanup (#33857) --- .../example_selectors/length_based.py | 2 +- .../langchain_core/language_models/base.py | 5 ++ .../language_models/chat_models.py | 24 ++--- libs/core/langchain_core/runnables/base.py | 88 ++++++++++++------- libs/core/pyproject.toml | 11 +-- libs/core/tests/unit_tests/pydantic_utils.py | 2 +- .../langchain_classic/agents/agent.py | 27 ++---- .../agent_token_buffer_memory.py | 5 +- .../langchain_classic/chains/api/base.py | 20 ++--- .../chains/combine_documents/base.py | 26 ++---- .../chains/combine_documents/map_reduce.py | 5 +- .../chains/combine_documents/map_rerank.py | 5 +- .../chains/combine_documents/refine.py | 5 +- .../chains/conversation/base.py | 4 +- .../chains/conversational_retrieval/base.py | 5 +- .../chains/elasticsearch_database/base.py | 14 +-- .../langchain/langchain_classic/chains/llm.py | 12 +-- .../chains/llm_checker/base.py | 14 +-- .../langchain_classic/chains/llm_math/base.py | 14 +-- .../chains/llm_summarization_checker/base.py | 14 +-- .../langchain_classic/chains/mapreduce.py | 14 +-- .../langchain_classic/chains/moderation.py | 18 ++-- .../langchain_classic/chains/natbot/base.py | 18 ++-- .../chains/qa_with_sources/base.py | 25 ++---- .../chains/retrieval_qa/base.py | 14 +-- .../langchain_classic/chains/router/base.py | 10 +-- .../chains/router/embedding_router.py | 5 +- .../chains/router/llm_router.py | 5 +- .../langchain_classic/chains/sequential.py | 26 ++---- .../langchain_classic/chains/transform.py | 15 +--- .../langchain_classic/chat_models/base.py | 2 +- .../agents/trajectory_eval_chain.py | 2 +- .../evaluation/comparison/eval_chain.py | 2 +- .../evaluation/criteria/eval_chain.py | 2 +- .../evaluation/qa/eval_chain.py | 2 +- .../evaluation/scoring/eval_chain.py | 2 +- .../langchain_classic/memory/buffer.py | 14 +-- .../langchain_classic/memory/buffer_window.py | 7 +- .../langchain_classic/memory/entity.py | 5 +- .../langchain_classic/memory/summary.py | 7 +- .../memory/summary_buffer.py | 5 +- .../langchain_classic/memory/token_buffer.py | 5 +- .../langchain_classic/memory/vectorstore.py | 2 +- .../output_parsers/regex_dict.py | 2 +- libs/langchain/pyproject.toml | 11 +-- .../langchain/chat_models/base.py | 2 +- libs/langchain_v1/pyproject.toml | 12 +-- libs/model-profiles/pyproject.toml | 12 +-- .../langchain_anthropic/chat_models.py | 27 +++--- .../anthropic/langchain_anthropic/llms.py | 15 ++-- libs/partners/anthropic/pyproject.toml | 11 +-- .../langchain_deepseek/chat_models.py | 22 +++-- libs/partners/deepseek/pyproject.toml | 11 +-- .../langchain_fireworks/chat_models.py | 43 ++++++--- .../langchain_fireworks/embeddings.py | 4 +- libs/partners/fireworks/pyproject.toml | 11 +-- .../groq/langchain_groq/chat_models.py | 52 ++++++++--- libs/partners/groq/pyproject.toml | 11 +-- .../chat_models/huggingface.py | 20 +++-- .../embeddings/huggingface_endpoint.py | 10 ++- .../llms/huggingface_endpoint.py | 28 +++++- .../llms/huggingface_pipeline.py | 6 +- libs/partners/huggingface/pyproject.toml | 11 +-- .../langchain_mistralai/chat_models.py | 38 +++++--- .../langchain_mistralai/embeddings.py | 11 ++- libs/partners/mistralai/pyproject.toml | 11 +-- .../ollama/langchain_ollama/chat_models.py | 22 +++-- libs/partners/ollama/pyproject.toml | 11 +-- .../langchain_openai/chat_models/azure.py | 22 +++-- .../langchain_openai/chat_models/base.py | 78 ++++++++++++---- .../langchain_openai/embeddings/base.py | 34 ++++++- .../openai/langchain_openai/llms/base.py | 33 ++++++- libs/partners/openai/pyproject.toml | 11 +-- .../langchain_perplexity/chat_models.py | 25 ++++-- libs/partners/perplexity/pyproject.toml | 11 +-- .../partners/xai/langchain_xai/chat_models.py | 23 ++--- libs/partners/xai/pyproject.toml | 11 +-- libs/standard-tests/pyproject.toml | 11 +-- libs/text-splitters/pyproject.toml | 11 +-- 79 files changed, 662 insertions(+), 531 deletions(-) diff --git a/libs/core/langchain_core/example_selectors/length_based.py b/libs/core/langchain_core/example_selectors/length_based.py index 296db6c1c60..9424e645bf5 100644 --- a/libs/core/langchain_core/example_selectors/length_based.py +++ b/libs/core/langchain_core/example_selectors/length_based.py @@ -29,7 +29,7 @@ class LengthBasedExampleSelector(BaseExampleSelector, BaseModel): max_length: int = 2048 """Max length for the prompt, beyond which examples are cut.""" - example_text_lengths: list[int] = Field(default_factory=list) # :meta private: + example_text_lengths: list[int] = Field(default_factory=list) """Length of each example.""" def add_example(self, example: dict[str, str]) -> None: diff --git a/libs/core/langchain_core/language_models/base.py b/libs/core/langchain_core/language_models/base.py index 958a03dd13d..58c6d4abf7e 100644 --- a/libs/core/langchain_core/language_models/base.py +++ b/libs/core/langchain_core/language_models/base.py @@ -131,14 +131,19 @@ class BaseLanguageModel( Caching is not currently supported for streaming methods of models. """ + verbose: bool = Field(default_factory=_get_verbosity, exclude=True, repr=False) """Whether to print out response text.""" + callbacks: Callbacks = Field(default=None, exclude=True) """Callbacks to add to the run trace.""" + tags: list[str] | None = Field(default=None, exclude=True) """Tags to add to the run trace.""" + metadata: dict[str, Any] | None = Field(default=None, exclude=True) """Metadata to add to the run trace.""" + custom_get_token_ids: Callable[[str], list[int]] | None = Field( default=None, exclude=True ) diff --git a/libs/core/langchain_core/language_models/chat_models.py b/libs/core/langchain_core/language_models/chat_models.py index bbd7cb56857..f37113b4661 100644 --- a/libs/core/langchain_core/language_models/chat_models.py +++ b/libs/core/langchain_core/language_models/chat_models.py @@ -1515,10 +1515,10 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC): Args: schema: The output schema. Can be passed in as: - - an OpenAI function/tool schema, - - a JSON Schema, - - a `TypedDict` class, - - or a Pydantic class. + - An OpenAI function/tool schema, + - A JSON Schema, + - A `TypedDict` class, + - Or a Pydantic class. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -1530,11 +1530,15 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC): when specifying a Pydantic or `TypedDict` class. include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. @@ -1640,7 +1644,7 @@ class BaseChatModel(BaseLanguageModel[AIMessage], ABC): ``` !!! warning "Behavior changed in `langchain-core` 0.2.26" - Added support for TypedDict class. + Added support for `TypedDict` class. """ # noqa: E501 _ = kwargs.pop("method", None) diff --git a/libs/core/langchain_core/runnables/base.py b/libs/core/langchain_core/runnables/base.py index 26432f05a7b..8c60cb39121 100644 --- a/libs/core/langchain_core/runnables/base.py +++ b/libs/core/langchain_core/runnables/base.py @@ -829,8 +829,9 @@ class Runnable(ABC, Generic[Input, Output]): The config supports standard keys like `'tags'`, `'metadata'` for tracing purposes, `'max_concurrency'` for controlling how much work to - do in parallel, and other keys. Please refer to the `RunnableConfig` - for more details. + do in parallel, and other keys. + + Please refer to `RunnableConfig` for more details. Returns: The output of the `Runnable`. @@ -850,8 +851,9 @@ class Runnable(ABC, Generic[Input, Output]): The config supports standard keys like `'tags'`, `'metadata'` for tracing purposes, `'max_concurrency'` for controlling how much work to - do in parallel, and other keys. Please refer to the `RunnableConfig` - for more details. + do in parallel, and other keys. + + Please refer to `RunnableConfig` for more details. Returns: The output of the `Runnable`. @@ -878,8 +880,9 @@ class Runnable(ABC, Generic[Input, Output]): config: A config to use when invoking the `Runnable`. The config supports standard keys like `'tags'`, `'metadata'` for tracing purposes, `'max_concurrency'` for controlling how much work - to do in parallel, and other keys. Please refer to the - `RunnableConfig` for more details. + to do in parallel, and other keys. + + Please refer to `RunnableConfig` for more details. return_exceptions: Whether to return exceptions instead of raising them. **kwargs: Additional keyword arguments to pass to the `Runnable`. @@ -945,8 +948,9 @@ class Runnable(ABC, Generic[Input, Output]): The config supports standard keys like `'tags'`, `'metadata'` for tracing purposes, `'max_concurrency'` for controlling how much work to - do in parallel, and other keys. Please refer to the `RunnableConfig` - for more details. + do in parallel, and other keys. + + Please refer to `RunnableConfig` for more details. return_exceptions: Whether to return exceptions instead of raising them. **kwargs: Additional keyword arguments to pass to the `Runnable`. @@ -1012,8 +1016,9 @@ class Runnable(ABC, Generic[Input, Output]): The config supports standard keys like `'tags'`, `'metadata'` for tracing purposes, `'max_concurrency'` for controlling how much work to - do in parallel, and other keys. Please refer to the `RunnableConfig` - for more details. + do in parallel, and other keys. + + Please refer to `RunnableConfig` for more details. return_exceptions: Whether to return exceptions instead of raising them. **kwargs: Additional keyword arguments to pass to the `Runnable`. @@ -1076,8 +1081,9 @@ class Runnable(ABC, Generic[Input, Output]): The config supports standard keys like `'tags'`, `'metadata'` for tracing purposes, `'max_concurrency'` for controlling how much work to - do in parallel, and other keys. Please refer to the `RunnableConfig` - for more details. + do in parallel, and other keys. + + Please refer to `RunnableConfig` for more details. return_exceptions: Whether to return exceptions instead of raising them. **kwargs: Additional keyword arguments to pass to the `Runnable`. @@ -1755,46 +1761,52 @@ class Runnable(ABC, Generic[Input, Output]): import time import asyncio + def format_t(timestamp: float) -> str: return datetime.fromtimestamp(timestamp, tz=timezone.utc).isoformat() + async def test_runnable(time_to_sleep: int): print(f"Runnable[{time_to_sleep}s]: starts at {format_t(time.time())}") await asyncio.sleep(time_to_sleep) print(f"Runnable[{time_to_sleep}s]: ends at {format_t(time.time())}") + async def fn_start(run_obj: Runnable): print(f"on start callback starts at {format_t(time.time())}") await asyncio.sleep(3) print(f"on start callback ends at {format_t(time.time())}") + async def fn_end(run_obj: Runnable): print(f"on end callback starts at {format_t(time.time())}") await asyncio.sleep(2) print(f"on end callback ends at {format_t(time.time())}") + runnable = RunnableLambda(test_runnable).with_alisteners( - on_start=fn_start, - on_end=fn_end + on_start=fn_start, on_end=fn_end ) + + async def concurrent_runs(): await asyncio.gather(runnable.ainvoke(2), runnable.ainvoke(3)) - asyncio.run(concurrent_runs()) - Result: - on start callback starts at 2025-03-01T07:05:22.875378+00:00 - on start callback starts at 2025-03-01T07:05:22.875495+00:00 - on start callback ends at 2025-03-01T07:05:25.878862+00:00 - on start callback ends at 2025-03-01T07:05:25.878947+00:00 - Runnable[2s]: starts at 2025-03-01T07:05:25.879392+00:00 - Runnable[3s]: starts at 2025-03-01T07:05:25.879804+00:00 - Runnable[2s]: ends at 2025-03-01T07:05:27.881998+00:00 - on end callback starts at 2025-03-01T07:05:27.882360+00:00 - Runnable[3s]: ends at 2025-03-01T07:05:28.881737+00:00 - on end callback starts at 2025-03-01T07:05:28.882428+00:00 - on end callback ends at 2025-03-01T07:05:29.883893+00:00 - on end callback ends at 2025-03-01T07:05:30.884831+00:00 + asyncio.run(concurrent_runs()) + # Result: + # on start callback starts at 2025-03-01T07:05:22.875378+00:00 + # on start callback starts at 2025-03-01T07:05:22.875495+00:00 + # on start callback ends at 2025-03-01T07:05:25.878862+00:00 + # on start callback ends at 2025-03-01T07:05:25.878947+00:00 + # Runnable[2s]: starts at 2025-03-01T07:05:25.879392+00:00 + # Runnable[3s]: starts at 2025-03-01T07:05:25.879804+00:00 + # Runnable[2s]: ends at 2025-03-01T07:05:27.881998+00:00 + # on end callback starts at 2025-03-01T07:05:27.882360+00:00 + # Runnable[3s]: ends at 2025-03-01T07:05:28.881737+00:00 + # on end callback starts at 2025-03-01T07:05:28.882428+00:00 + # on end callback ends at 2025-03-01T07:05:29.883893+00:00 + # on end callback ends at 2025-03-01T07:05:30.884831+00:00 ``` """ return RunnableBinding( @@ -1856,7 +1868,7 @@ class Runnable(ABC, Generic[Input, Output]): `exp_base`, and `jitter` (all `float` values). Returns: - A new Runnable that retries the original Runnable on exceptions. + A new `Runnable` that retries the original `Runnable` on exceptions. Example: ```python @@ -1940,7 +1952,9 @@ class Runnable(ABC, Generic[Input, Output]): exceptions_to_handle: A tuple of exception types to handle. exception_key: If `string` is specified then handled exceptions will be passed to fallbacks as part of the input under the specified key. + If `None`, exceptions will not be passed to fallbacks. + If used, the base `Runnable` and its fallbacks must accept a dictionary as input. @@ -1976,7 +1990,9 @@ class Runnable(ABC, Generic[Input, Output]): exceptions_to_handle: A tuple of exception types to handle. exception_key: If `string` is specified then handled exceptions will be passed to fallbacks as part of the input under the specified key. + If `None`, exceptions will not be passed to fallbacks. + If used, the base `Runnable` and its fallbacks must accept a dictionary as input. @@ -2442,10 +2458,14 @@ class Runnable(ABC, Generic[Input, Output]): `as_tool` will instantiate a `BaseTool` with a name, description, and `args_schema` from a `Runnable`. Where possible, schemas are inferred - from `runnable.get_input_schema`. Alternatively (e.g., if the - `Runnable` takes a dict as input and the specific dict keys are not typed), - the schema can be specified directly with `args_schema`. You can also - pass `arg_types` to just specify the required arguments and their types. + from `runnable.get_input_schema`. + + Alternatively (e.g., if the `Runnable` takes a dict as input and the specific + `dict` keys are not typed), the schema can be specified directly with + `args_schema`. + + You can also pass `arg_types` to just specify the required arguments and their + types. Args: args_schema: The schema for the tool. @@ -2514,7 +2534,7 @@ class Runnable(ABC, Generic[Input, Output]): as_tool.invoke({"a": 3, "b": [1, 2]}) ``` - String input: + `str` input: ```python from langchain_core.runnables import RunnableLambda diff --git a/libs/core/pyproject.toml b/libs/core/pyproject.toml index 004018914d6..6fb85621b5b 100644 --- a/libs/core/pyproject.toml +++ b/libs/core/pyproject.toml @@ -3,8 +3,13 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-core" +description = "Building applications with LLMs through composability" license = {text = "MIT"} +readme = "README.md" +authors = [] + +version = "1.0.3" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langsmith>=0.3.45,<1.0.0", @@ -15,10 +20,6 @@ dependencies = [ "packaging>=23.2.0,<26.0.0", "pydantic>=2.7.4,<3.0.0", ] -name = "langchain-core" -version = "1.0.3" -description = "Building applications with LLMs through composability" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/" diff --git a/libs/core/tests/unit_tests/pydantic_utils.py b/libs/core/tests/unit_tests/pydantic_utils.py index 1429e1e9a41..b8235415343 100644 --- a/libs/core/tests/unit_tests/pydantic_utils.py +++ b/libs/core/tests/unit_tests/pydantic_utils.py @@ -105,7 +105,7 @@ def _remove_additionalproperties(schema: dict) -> dict[str, Any]: generating JSON schemas for dict properties with `Any` or `object` values. Pydantic 2.12 and later versions include `"additionalProperties": True` when - generating JSON schemas for TypedDict. + generating JSON schemas for `TypedDict`. """ if isinstance(schema, dict): if ( diff --git a/libs/langchain/langchain_classic/agents/agent.py b/libs/langchain/langchain_classic/agents/agent.py index bd0c8e74121..6c98fa13809 100644 --- a/libs/langchain/langchain_classic/agents/agent.py +++ b/libs/langchain/langchain_classic/agents/agent.py @@ -105,10 +105,7 @@ class BaseSingleActionAgent(BaseModel): @property @abstractmethod def input_keys(self) -> list[str]: - """Return the input keys. - - :meta private: - """ + """Return the input keys.""" def return_stopped_response( self, @@ -278,10 +275,7 @@ class BaseMultiActionAgent(BaseModel): @property @abstractmethod def input_keys(self) -> list[str]: - """Return the input keys. - - :meta private: - """ + """Return the input keys.""" def return_stopped_response( self, @@ -819,10 +813,7 @@ class Agent(BaseSingleActionAgent): @property def input_keys(self) -> list[str]: - """Return the input keys. - - :meta private: - """ + """Return the input keys.""" return list(set(self.llm_chain.input_keys) - {"agent_scratchpad"}) @model_validator(mode="after") @@ -837,7 +828,7 @@ class Agent(BaseSingleActionAgent): Raises: ValueError: If `agent_scratchpad` is not in prompt.input_variables - and prompt is not a FewShotPromptTemplate or a PromptTemplate. + and prompt is not a FewShotPromptTemplate or a PromptTemplate. """ prompt = self.llm_chain.prompt if "agent_scratchpad" not in prompt.input_variables: @@ -1220,18 +1211,12 @@ class AgentExecutor(Chain): @property def input_keys(self) -> list[str]: - """Return the input keys. - - :meta private: - """ + """Return the input keys.""" return self._action_agent.input_keys @property def output_keys(self) -> list[str]: - """Return the singular output key. - - :meta private: - """ + """Return the singular output key.""" if self.return_intermediate_steps: return [*self._action_agent.return_values, "intermediate_steps"] return self._action_agent.return_values diff --git a/libs/langchain/langchain_classic/agents/openai_functions_agent/agent_token_buffer_memory.py b/libs/langchain/langchain_classic/agents/openai_functions_agent/agent_token_buffer_memory.py index 666e6b8c75b..f6f1307cfc9 100644 --- a/libs/langchain/langchain_classic/agents/openai_functions_agent/agent_token_buffer_memory.py +++ b/libs/langchain/langchain_classic/agents/openai_functions_agent/agent_token_buffer_memory.py @@ -49,10 +49,7 @@ class AgentTokenBufferMemory(BaseChatMemory): @property def memory_variables(self) -> list[str]: - """Always return list of memory variables. - - :meta private: - """ + """Always return list of memory variables.""" return [self.memory_key] @override diff --git a/libs/langchain/langchain_classic/chains/api/base.py b/libs/langchain/langchain_classic/chains/api/base.py index df6a9025c33..d0009dca6dd 100644 --- a/libs/langchain/langchain_classic/chains/api/base.py +++ b/libs/langchain/langchain_classic/chains/api/base.py @@ -197,11 +197,17 @@ try: """ api_request_chain: LLMChain + api_answer_chain: LLMChain + requests_wrapper: TextRequestsWrapper = Field(exclude=True) + api_docs: str - question_key: str = "question" #: :meta private: - output_key: str = "output" #: :meta private: + + question_key: str = "question" + + output_key: str = "output" + limit_to_domains: Sequence[str] | None = Field(default_factory=list) """Use to limit the domains that can be accessed by the API chain. @@ -217,18 +223,12 @@ try: @property def input_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" return [self.question_key] @property def output_keys(self) -> list[str]: - """Expect output key. - - :meta private: - """ + """Expect output key.""" return [self.output_key] @model_validator(mode="after") diff --git a/libs/langchain/langchain_classic/chains/combine_documents/base.py b/libs/langchain/langchain_classic/chains/combine_documents/base.py index ee672ea1001..96b6fdf46ed 100644 --- a/libs/langchain/langchain_classic/chains/combine_documents/base.py +++ b/libs/langchain/langchain_classic/chains/combine_documents/base.py @@ -44,8 +44,8 @@ class BaseCombineDocumentsChain(Chain, ABC): that will be longer than the context length). """ - input_key: str = "input_documents" #: :meta private: - output_key: str = "output_text" #: :meta private: + input_key: str = "input_documents" + output_key: str = "output_text" @override def get_input_schema( @@ -69,18 +69,12 @@ class BaseCombineDocumentsChain(Chain, ABC): @property def input_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Return output key. - - :meta private: - """ + """Return output key.""" return [self.output_key] def prompt_length(self, docs: list[Document], **kwargs: Any) -> int | None: # noqa: ARG002 @@ -234,24 +228,18 @@ class AnalyzeDocumentChain(Chain): ``` """ - input_key: str = "input_document" #: :meta private: + input_key: str = "input_document" text_splitter: TextSplitter = Field(default_factory=RecursiveCharacterTextSplitter) combine_docs_chain: BaseCombineDocumentsChain @property def input_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Return output key. - - :meta private: - """ + """Return output key.""" return self.combine_docs_chain.output_keys @override diff --git a/libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py b/libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py index 2cf9190db96..4c5cf66913b 100644 --- a/libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py +++ b/libs/langchain/langchain_classic/chains/combine_documents/map_reduce.py @@ -125,10 +125,7 @@ class MapReduceDocumentsChain(BaseCombineDocumentsChain): @property def output_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" _output_keys = super().output_keys if self.return_intermediate_steps: _output_keys = [*_output_keys, "intermediate_steps"] diff --git a/libs/langchain/langchain_classic/chains/combine_documents/map_rerank.py b/libs/langchain/langchain_classic/chains/combine_documents/map_rerank.py index f37c66c2c83..d7889c72cf7 100644 --- a/libs/langchain/langchain_classic/chains/combine_documents/map_rerank.py +++ b/libs/langchain/langchain_classic/chains/combine_documents/map_rerank.py @@ -108,10 +108,7 @@ class MapRerankDocumentsChain(BaseCombineDocumentsChain): @property def output_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" _output_keys = super().output_keys if self.return_intermediate_steps: _output_keys = [*_output_keys, "intermediate_steps"] diff --git a/libs/langchain/langchain_classic/chains/combine_documents/refine.py b/libs/langchain/langchain_classic/chains/combine_documents/refine.py index 033b0ac0ef7..0e66b5690d1 100644 --- a/libs/langchain/langchain_classic/chains/combine_documents/refine.py +++ b/libs/langchain/langchain_classic/chains/combine_documents/refine.py @@ -96,10 +96,7 @@ class RefineDocumentsChain(BaseCombineDocumentsChain): @property def output_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" _output_keys = super().output_keys if self.return_intermediate_steps: _output_keys = [*_output_keys, "intermediate_steps"] diff --git a/libs/langchain/langchain_classic/chains/conversation/base.py b/libs/langchain/langchain_classic/chains/conversation/base.py index 46454690086..98a73a97299 100644 --- a/libs/langchain/langchain_classic/chains/conversation/base.py +++ b/libs/langchain/langchain_classic/chains/conversation/base.py @@ -108,8 +108,8 @@ class ConversationChain(LLMChain): prompt: BasePromptTemplate = PROMPT """Default conversation prompt to use.""" - input_key: str = "input" #: :meta private: - output_key: str = "response" #: :meta private: + input_key: str = "input" + output_key: str = "response" model_config = ConfigDict( arbitrary_types_allowed=True, diff --git a/libs/langchain/langchain_classic/chains/conversational_retrieval/base.py b/libs/langchain/langchain_classic/chains/conversational_retrieval/base.py index fe40c51e911..db8bd9daf31 100644 --- a/libs/langchain/langchain_classic/chains/conversational_retrieval/base.py +++ b/libs/langchain/langchain_classic/chains/conversational_retrieval/base.py @@ -122,10 +122,7 @@ class BaseConversationalRetrievalChain(Chain): @property def output_keys(self) -> list[str]: - """Return the output keys. - - :meta private: - """ + """Return the output keys.""" _output_keys = [self.output_key] if self.return_source_documents: _output_keys = [*_output_keys, "source_documents"] diff --git a/libs/langchain/langchain_classic/chains/elasticsearch_database/base.py b/libs/langchain/langchain_classic/chains/elasticsearch_database/base.py index f61065c476a..e041de38351 100644 --- a/libs/langchain/langchain_classic/chains/elasticsearch_database/base.py +++ b/libs/langchain/langchain_classic/chains/elasticsearch_database/base.py @@ -49,8 +49,8 @@ class ElasticsearchDatabaseChain(Chain): """Number of results to return from the query""" ignore_indices: list[str] | None = None include_indices: list[str] | None = None - input_key: str = "question" #: :meta private: - output_key: str = "result" #: :meta private: + input_key: str = "question" + output_key: str = "result" sample_documents_in_index_info: int = 3 return_intermediate_steps: bool = False """Whether or not to return the intermediate steps along with the final answer.""" @@ -69,18 +69,12 @@ class ElasticsearchDatabaseChain(Chain): @property def input_keys(self) -> list[str]: - """Return the singular input key. - - :meta private: - """ + """Return the singular input key.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Return the singular output key. - - :meta private: - """ + """Return the singular output key.""" if not self.return_intermediate_steps: return [self.output_key] return [self.output_key, INTERMEDIATE_STEPS_KEY] diff --git a/libs/langchain/langchain_classic/chains/llm.py b/libs/langchain/langchain_classic/chains/llm.py index 0d3bfb3878d..274fd1d0d83 100644 --- a/libs/langchain/langchain_classic/chains/llm.py +++ b/libs/langchain/langchain_classic/chains/llm.py @@ -82,7 +82,7 @@ class LLMChain(Chain): """Prompt object to use.""" llm: Runnable[LanguageModelInput, str] | Runnable[LanguageModelInput, BaseMessage] """Language model to call.""" - output_key: str = "text" #: :meta private: + output_key: str = "text" output_parser: BaseLLMOutputParser = Field(default_factory=StrOutputParser) """Output parser to use. Defaults to one that takes the most likely string but does not change it @@ -99,18 +99,12 @@ class LLMChain(Chain): @property def input_keys(self) -> list[str]: - """Will be whatever keys the prompt expects. - - :meta private: - """ + """Will be whatever keys the prompt expects.""" return self.prompt.input_variables @property def output_keys(self) -> list[str]: - """Will always return text key. - - :meta private: - """ + """Will always return text key.""" if self.return_final_only: return [self.output_key] return [self.output_key, "full_generation"] diff --git a/libs/langchain/langchain_classic/chains/llm_checker/base.py b/libs/langchain/langchain_classic/chains/llm_checker/base.py index 05417d5d872..9db3194fb3d 100644 --- a/libs/langchain/langchain_classic/chains/llm_checker/base.py +++ b/libs/langchain/langchain_classic/chains/llm_checker/base.py @@ -97,8 +97,8 @@ class LLMCheckerChain(Chain): """[Deprecated]""" revised_answer_prompt: PromptTemplate = REVISED_ANSWER_PROMPT """[Deprecated] Prompt to use when questioning the documents.""" - input_key: str = "query" #: :meta private: - output_key: str = "result" #: :meta private: + input_key: str = "query" + output_key: str = "result" model_config = ConfigDict( arbitrary_types_allowed=True, @@ -138,18 +138,12 @@ class LLMCheckerChain(Chain): @property def input_keys(self) -> list[str]: - """Return the singular input key. - - :meta private: - """ + """Return the singular input key.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Return the singular output key. - - :meta private: - """ + """Return the singular output key.""" return [self.output_key] def _call( diff --git a/libs/langchain/langchain_classic/chains/llm_math/base.py b/libs/langchain/langchain_classic/chains/llm_math/base.py index 286c682f302..b8b038d5201 100644 --- a/libs/langchain/langchain_classic/chains/llm_math/base.py +++ b/libs/langchain/langchain_classic/chains/llm_math/base.py @@ -156,8 +156,8 @@ class LLMMathChain(Chain): """[Deprecated] LLM wrapper to use.""" prompt: BasePromptTemplate = PROMPT """[Deprecated] Prompt to use to translate to python if necessary.""" - input_key: str = "question" #: :meta private: - output_key: str = "answer" #: :meta private: + input_key: str = "question" + output_key: str = "answer" model_config = ConfigDict( arbitrary_types_allowed=True, @@ -189,18 +189,12 @@ class LLMMathChain(Chain): @property def input_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Expect output key. - - :meta private: - """ + """Expect output key.""" return [self.output_key] def _evaluate_expression(self, expression: str) -> str: diff --git a/libs/langchain/langchain_classic/chains/llm_summarization_checker/base.py b/libs/langchain/langchain_classic/chains/llm_summarization_checker/base.py index d126178b211..e5d86dd2f03 100644 --- a/libs/langchain/langchain_classic/chains/llm_summarization_checker/base.py +++ b/libs/langchain/langchain_classic/chains/llm_summarization_checker/base.py @@ -101,8 +101,8 @@ class LLMSummarizationCheckerChain(Chain): are_all_true_prompt: PromptTemplate = ARE_ALL_TRUE_PROMPT """[Deprecated]""" - input_key: str = "query" #: :meta private: - output_key: str = "result" #: :meta private: + input_key: str = "query" + output_key: str = "result" max_checks: int = 2 """Maximum number of times to check the assertions. Default to double-checking.""" @@ -134,18 +134,12 @@ class LLMSummarizationCheckerChain(Chain): @property def input_keys(self) -> list[str]: - """Return the singular input key. - - :meta private: - """ + """Return the singular input key.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Return the singular output key. - - :meta private: - """ + """Return the singular output key.""" return [self.output_key] def _call( diff --git a/libs/langchain/langchain_classic/chains/mapreduce.py b/libs/langchain/langchain_classic/chains/mapreduce.py index 81dc9731906..1845439f7a6 100644 --- a/libs/langchain/langchain_classic/chains/mapreduce.py +++ b/libs/langchain/langchain_classic/chains/mapreduce.py @@ -44,8 +44,8 @@ class MapReduceChain(Chain): """Chain to use to combine documents.""" text_splitter: TextSplitter """Text splitter to use.""" - input_key: str = "input_text" #: :meta private: - output_key: str = "output_text" #: :meta private: + input_key: str = "input_text" + output_key: str = "output_text" @classmethod def from_params( @@ -88,18 +88,12 @@ class MapReduceChain(Chain): @property def input_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Return output key. - - :meta private: - """ + """Return output key.""" return [self.output_key] def _call( diff --git a/libs/langchain/langchain_classic/chains/moderation.py b/libs/langchain/langchain_classic/chains/moderation.py index 1a7e9aa5002..f4c80e4cdb3 100644 --- a/libs/langchain/langchain_classic/chains/moderation.py +++ b/libs/langchain/langchain_classic/chains/moderation.py @@ -30,14 +30,14 @@ class OpenAIModerationChain(Chain): ``` """ - client: Any = None #: :meta private: - async_client: Any = None #: :meta private: + client: Any = None + async_client: Any = None model_name: str | None = None """Moderation model name to use.""" error: bool = False """Whether or not to error if bad content was found.""" - input_key: str = "input" #: :meta private: - output_key: str = "output" #: :meta private: + input_key: str = "input" + output_key: str = "output" openai_api_key: str | None = None openai_organization: str | None = None openai_pre_1_0: bool = Field(default=False) @@ -84,18 +84,12 @@ class OpenAIModerationChain(Chain): @property def input_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Return output key. - - :meta private: - """ + """Return output key.""" return [self.output_key] def _moderate(self, text: str, results: Any) -> str: diff --git a/libs/langchain/langchain_classic/chains/natbot/base.py b/libs/langchain/langchain_classic/chains/natbot/base.py index bde0f90abd7..d36033525c3 100644 --- a/libs/langchain/langchain_classic/chains/natbot/base.py +++ b/libs/langchain/langchain_classic/chains/natbot/base.py @@ -55,10 +55,10 @@ class NatBotChain(Chain): """Objective that NatBot is tasked with completing.""" llm: BaseLanguageModel | None = None """[Deprecated] LLM wrapper to use.""" - input_url_key: str = "url" #: :meta private: - input_browser_content_key: str = "browser_content" #: :meta private: - previous_command: str = "" #: :meta private: - output_key: str = "command" #: :meta private: + input_url_key: str = "url" + input_browser_content_key: str = "browser_content" + previous_command: str = "" + output_key: str = "command" model_config = ConfigDict( arbitrary_types_allowed=True, @@ -102,18 +102,12 @@ class NatBotChain(Chain): @property def input_keys(self) -> list[str]: - """Expect url and browser content. - - :meta private: - """ + """Expect url and browser content.""" return [self.input_url_key, self.input_browser_content_key] @property def output_keys(self) -> list[str]: - """Return command. - - :meta private: - """ + """Return command.""" return [self.output_key] def _call( diff --git a/libs/langchain/langchain_classic/chains/qa_with_sources/base.py b/libs/langchain/langchain_classic/chains/qa_with_sources/base.py index 30966c177c2..3edd695157d 100644 --- a/libs/langchain/langchain_classic/chains/qa_with_sources/base.py +++ b/libs/langchain/langchain_classic/chains/qa_with_sources/base.py @@ -48,10 +48,10 @@ class BaseQAWithSourcesChain(Chain, ABC): combine_documents_chain: BaseCombineDocumentsChain """Chain to use to combine documents.""" - question_key: str = "question" #: :meta private: - input_docs_key: str = "docs" #: :meta private: - answer_key: str = "answer" #: :meta private: - sources_answer_key: str = "sources" #: :meta private: + question_key: str = "question" + input_docs_key: str = "docs" + answer_key: str = "answer" + sources_answer_key: str = "sources" return_source_documents: bool = False """Return the source documents.""" @@ -109,18 +109,12 @@ class BaseQAWithSourcesChain(Chain, ABC): @property def input_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" return [self.question_key] @property def output_keys(self) -> list[str]: - """Return output key. - - :meta private: - """ + """Return output key.""" _output_keys = [self.answer_key, self.sources_answer_key] if self.return_source_documents: _output_keys = [*_output_keys, "source_documents"] @@ -233,14 +227,11 @@ class BaseQAWithSourcesChain(Chain, ABC): class QAWithSourcesChain(BaseQAWithSourcesChain): """Question answering with sources over documents.""" - input_docs_key: str = "docs" #: :meta private: + input_docs_key: str = "docs" @property def input_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" return [self.input_docs_key, self.question_key] @override diff --git a/libs/langchain/langchain_classic/chains/retrieval_qa/base.py b/libs/langchain/langchain_classic/chains/retrieval_qa/base.py index 01961254e07..ec62a77eaa2 100644 --- a/libs/langchain/langchain_classic/chains/retrieval_qa/base.py +++ b/libs/langchain/langchain_classic/chains/retrieval_qa/base.py @@ -42,8 +42,8 @@ class BaseRetrievalQA(Chain): combine_documents_chain: BaseCombineDocumentsChain """Chain to use to combine the documents.""" - input_key: str = "query" #: :meta private: - output_key: str = "result" #: :meta private: + input_key: str = "query" + output_key: str = "result" return_source_documents: bool = False """Return the source documents or not.""" @@ -55,18 +55,12 @@ class BaseRetrievalQA(Chain): @property def input_keys(self) -> list[str]: - """Input keys. - - :meta private: - """ + """Input keys.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Output keys. - - :meta private: - """ + """Output keys.""" _output_keys = [self.output_key] if self.return_source_documents: _output_keys = [*_output_keys, "source_documents"] diff --git a/libs/langchain/langchain_classic/chains/router/base.py b/libs/langchain/langchain_classic/chains/router/base.py index 8122a90b65c..0a0ca8cc024 100644 --- a/libs/langchain/langchain_classic/chains/router/base.py +++ b/libs/langchain/langchain_classic/chains/router/base.py @@ -82,18 +82,12 @@ class MultiRouteChain(Chain): @property def input_keys(self) -> list[str]: - """Will be whatever keys the router chain prompt expects. - - :meta private: - """ + """Will be whatever keys the router chain prompt expects.""" return self.router_chain.input_keys @property def output_keys(self) -> list[str]: - """Will always return text key. - - :meta private: - """ + """Will always return text key.""" return [] def _call( diff --git a/libs/langchain/langchain_classic/chains/router/embedding_router.py b/libs/langchain/langchain_classic/chains/router/embedding_router.py index a519fabc2a3..60d986c1468 100644 --- a/libs/langchain/langchain_classic/chains/router/embedding_router.py +++ b/libs/langchain/langchain_classic/chains/router/embedding_router.py @@ -29,10 +29,7 @@ class EmbeddingRouterChain(RouterChain): @property def input_keys(self) -> list[str]: - """Will be whatever keys the LLM chain prompt expects. - - :meta private: - """ + """Will be whatever keys the LLM chain prompt expects.""" return self.routing_keys @override diff --git a/libs/langchain/langchain_classic/chains/router/llm_router.py b/libs/langchain/langchain_classic/chains/router/llm_router.py index c90685e6b5d..8d93789a1b6 100644 --- a/libs/langchain/langchain_classic/chains/router/llm_router.py +++ b/libs/langchain/langchain_classic/chains/router/llm_router.py @@ -118,10 +118,7 @@ class LLMRouterChain(RouterChain): @property def input_keys(self) -> list[str]: - """Will be whatever keys the LLM chain prompt expects. - - :meta private: - """ + """Will be whatever keys the LLM chain prompt expects.""" return self.llm_chain.input_keys def _validate_outputs(self, outputs: dict[str, Any]) -> None: diff --git a/libs/langchain/langchain_classic/chains/sequential.py b/libs/langchain/langchain_classic/chains/sequential.py index 78b576fc6a1..3d333b52b53 100644 --- a/libs/langchain/langchain_classic/chains/sequential.py +++ b/libs/langchain/langchain_classic/chains/sequential.py @@ -18,7 +18,7 @@ class SequentialChain(Chain): chains: list[Chain] input_variables: list[str] - output_variables: list[str] #: :meta private: + output_variables: list[str] return_all: bool = False model_config = ConfigDict( @@ -28,18 +28,12 @@ class SequentialChain(Chain): @property def input_keys(self) -> list[str]: - """Return expected input keys to the chain. - - :meta private: - """ + """Return expected input keys to the chain.""" return self.input_variables @property def output_keys(self) -> list[str]: - """Return output key. - - :meta private: - """ + """Return output key.""" return self.output_variables @model_validator(mode="before") @@ -131,8 +125,8 @@ class SimpleSequentialChain(Chain): chains: list[Chain] strip_outputs: bool = False - input_key: str = "input" #: :meta private: - output_key: str = "output" #: :meta private: + input_key: str = "input" + output_key: str = "output" model_config = ConfigDict( arbitrary_types_allowed=True, @@ -141,18 +135,12 @@ class SimpleSequentialChain(Chain): @property def input_keys(self) -> list[str]: - """Expect input key. - - :meta private: - """ + """Expect input key.""" return [self.input_key] @property def output_keys(self) -> list[str]: - """Return output key. - - :meta private: - """ + """Return output key.""" return [self.output_key] @model_validator(mode="after") diff --git a/libs/langchain/langchain_classic/chains/transform.py b/libs/langchain/langchain_classic/chains/transform.py index 709ec348dde..a56273f1e50 100644 --- a/libs/langchain/langchain_classic/chains/transform.py +++ b/libs/langchain/langchain_classic/chains/transform.py @@ -43,26 +43,17 @@ class TransformChain(Chain): @staticmethod @functools.lru_cache def _log_once(msg: str) -> None: - """Log a message once. - - :meta private: - """ + """Log a message once.""" logger.warning(msg) @property def input_keys(self) -> list[str]: - """Expect input keys. - - :meta private: - """ + """Expect input keys.""" return self.input_variables @property def output_keys(self) -> list[str]: - """Return output keys. - - :meta private: - """ + """Return output keys.""" return self.output_variables @override diff --git a/libs/langchain/langchain_classic/chat_models/base.py b/libs/langchain/langchain_classic/chat_models/base.py index 8c7f0249d7b..b22b74ae306 100644 --- a/libs/langchain/langchain_classic/chat_models/base.py +++ b/libs/langchain/langchain_classic/chat_models/base.py @@ -654,7 +654,7 @@ class _ConfigurableModel(Runnable[LanguageModelInput, Any]): config: RunnableConfig | None = None, **kwargs: Any, ) -> _ConfigurableModel: - """Bind config to a Runnable, returning a new Runnable.""" + """Bind config to a `Runnable`, returning a new `Runnable`.""" config = RunnableConfig(**(config or {}), **cast("RunnableConfig", kwargs)) model_params = self._model_params(config) remaining_config = {k: v for k, v in config.items() if k != "configurable"} diff --git a/libs/langchain/langchain_classic/evaluation/agents/trajectory_eval_chain.py b/libs/langchain/langchain_classic/evaluation/agents/trajectory_eval_chain.py index 6e72d243960..f3828257785 100644 --- a/libs/langchain/langchain_classic/evaluation/agents/trajectory_eval_chain.py +++ b/libs/langchain/langchain_classic/evaluation/agents/trajectory_eval_chain.py @@ -148,7 +148,7 @@ class TrajectoryEvalChain(AgentTrajectoryEvaluator, LLMEvalChain): default_factory=TrajectoryOutputParser, ) """The output parser used to parse the output.""" - return_reasoning: bool = False # :meta private: + return_reasoning: bool = False """DEPRECATED. Reasoning always returned.""" model_config = ConfigDict( diff --git a/libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py b/libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py index 298dbe3767c..03599b59b41 100644 --- a/libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py +++ b/libs/langchain/langchain_classic/evaluation/comparison/eval_chain.py @@ -188,7 +188,7 @@ class PairwiseStringEvalChain(PairwiseStringEvaluator, LLMEvalChain, LLMChain): """ - output_key: str = "results" #: :meta private: + output_key: str = "results" output_parser: BaseOutputParser = Field( default_factory=PairwiseStringResultOutputParser, ) diff --git a/libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py b/libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py index 64c2cc0d6cf..5d90659caa7 100644 --- a/libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py +++ b/libs/langchain/langchain_classic/evaluation/criteria/eval_chain.py @@ -228,7 +228,7 @@ class CriteriaEvalChain(StringEvaluator, LLMEvalChain, LLMChain): """The parser to use to map the output to a structured result.""" criterion_name: str """The name of the criterion being evaluated.""" - output_key: str = "results" #: :meta private: + output_key: str = "results" @classmethod @override diff --git a/libs/langchain/langchain_classic/evaluation/qa/eval_chain.py b/libs/langchain/langchain_classic/evaluation/qa/eval_chain.py index b1388fc3808..f87cb1b7488 100644 --- a/libs/langchain/langchain_classic/evaluation/qa/eval_chain.py +++ b/libs/langchain/langchain_classic/evaluation/qa/eval_chain.py @@ -77,7 +77,7 @@ def _parse_string_eval_output(text: str) -> dict: class QAEvalChain(LLMChain, StringEvaluator, LLMEvalChain): """LLM Chain for evaluating question answering.""" - output_key: str = "results" #: :meta private: + output_key: str = "results" model_config = ConfigDict( extra="ignore", diff --git a/libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py b/libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py index fd7d8867784..f5ac405ac83 100644 --- a/libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py +++ b/libs/langchain/langchain_classic/evaluation/scoring/eval_chain.py @@ -173,7 +173,7 @@ class ScoreStringEvalChain(StringEvaluator, LLMEvalChain, LLMChain): """ - output_key: str = "results" #: :meta private: + output_key: str = "results" output_parser: BaseOutputParser = Field( default_factory=ScoreStringResultOutputParser, ) diff --git a/libs/langchain/langchain_classic/memory/buffer.py b/libs/langchain/langchain_classic/memory/buffer.py index 5a08db95c74..ab177fe3837 100644 --- a/libs/langchain/langchain_classic/memory/buffer.py +++ b/libs/langchain/langchain_classic/memory/buffer.py @@ -30,7 +30,7 @@ class ConversationBufferMemory(BaseChatMemory): human_prefix: str = "Human" ai_prefix: str = "AI" - memory_key: str = "history" #: :meta private: + memory_key: str = "history" @property def buffer(self) -> Any: @@ -73,10 +73,7 @@ class ConversationBufferMemory(BaseChatMemory): @property def memory_variables(self) -> list[str]: - """Will always return list of memory variables. - - :meta private: - """ + """Will always return list of memory variables.""" return [self.memory_key] @override @@ -118,7 +115,7 @@ class ConversationStringBufferMemory(BaseMemory): buffer: str = "" output_key: str | None = None input_key: str | None = None - memory_key: str = "history" #: :meta private: + memory_key: str = "history" @pre_init def validate_chains(cls, values: dict) -> dict: @@ -130,10 +127,7 @@ class ConversationStringBufferMemory(BaseMemory): @property def memory_variables(self) -> list[str]: - """Will always return list of memory variables. - - :meta private: - """ + """Will always return list of memory variables.""" return [self.memory_key] @override diff --git a/libs/langchain/langchain_classic/memory/buffer_window.py b/libs/langchain/langchain_classic/memory/buffer_window.py index 264a836caa4..97e0d9cbb7c 100644 --- a/libs/langchain/langchain_classic/memory/buffer_window.py +++ b/libs/langchain/langchain_classic/memory/buffer_window.py @@ -24,7 +24,7 @@ class ConversationBufferWindowMemory(BaseChatMemory): human_prefix: str = "Human" ai_prefix: str = "AI" - memory_key: str = "history" #: :meta private: + memory_key: str = "history" k: int = 5 """Number of messages to store in buffer.""" @@ -50,10 +50,7 @@ class ConversationBufferWindowMemory(BaseChatMemory): @property def memory_variables(self) -> list[str]: - """Will always return list of memory variables. - - :meta private: - """ + """Will always return list of memory variables.""" return [self.memory_key] @override diff --git a/libs/langchain/langchain_classic/memory/entity.py b/libs/langchain/langchain_classic/memory/entity.py index 3b45140792d..be0679e4557 100644 --- a/libs/langchain/langchain_classic/memory/entity.py +++ b/libs/langchain/langchain_classic/memory/entity.py @@ -496,10 +496,7 @@ class ConversationEntityMemory(BaseChatMemory): @property def memory_variables(self) -> list[str]: - """Will always return list of memory variables. - - :meta private: - """ + """Will always return list of memory variables.""" return ["entities", self.chat_history_key] def load_memory_variables(self, inputs: dict[str, Any]) -> dict[str, Any]: diff --git a/libs/langchain/langchain_classic/memory/summary.py b/libs/langchain/langchain_classic/memory/summary.py index 5b2ed54e56a..bd3d6e86895 100644 --- a/libs/langchain/langchain_classic/memory/summary.py +++ b/libs/langchain/langchain_classic/memory/summary.py @@ -97,7 +97,7 @@ class ConversationSummaryMemory(BaseChatMemory, SummarizerMixin): """ buffer: str = "" - memory_key: str = "history" #: :meta private: + memory_key: str = "history" @classmethod def from_messages( @@ -129,10 +129,7 @@ class ConversationSummaryMemory(BaseChatMemory, SummarizerMixin): @property def memory_variables(self) -> list[str]: - """Will always return list of memory variables. - - :meta private: - """ + """Will always return list of memory variables.""" return [self.memory_key] @override diff --git a/libs/langchain/langchain_classic/memory/summary_buffer.py b/libs/langchain/langchain_classic/memory/summary_buffer.py index fffcceb27bb..40c8ba168cf 100644 --- a/libs/langchain/langchain_classic/memory/summary_buffer.py +++ b/libs/langchain/langchain_classic/memory/summary_buffer.py @@ -41,10 +41,7 @@ class ConversationSummaryBufferMemory(BaseChatMemory, SummarizerMixin): @property def memory_variables(self) -> list[str]: - """Will always return list of memory variables. - - :meta private: - """ + """Will always return list of memory variables.""" return [self.memory_key] @override diff --git a/libs/langchain/langchain_classic/memory/token_buffer.py b/libs/langchain/langchain_classic/memory/token_buffer.py index caa0f78bcef..665da3c23dd 100644 --- a/libs/langchain/langchain_classic/memory/token_buffer.py +++ b/libs/langchain/langchain_classic/memory/token_buffer.py @@ -50,10 +50,7 @@ class ConversationTokenBufferMemory(BaseChatMemory): @property def memory_variables(self) -> list[str]: - """Will always return list of memory variables. - - :meta private: - """ + """Will always return list of memory variables.""" return [self.memory_key] @override diff --git a/libs/langchain/langchain_classic/memory/vectorstore.py b/libs/langchain/langchain_classic/memory/vectorstore.py index 3f6eef1916e..fc6e07fe929 100644 --- a/libs/langchain/langchain_classic/memory/vectorstore.py +++ b/libs/langchain/langchain_classic/memory/vectorstore.py @@ -30,7 +30,7 @@ class VectorStoreRetrieverMemory(BaseMemory): retriever: VectorStoreRetriever = Field(exclude=True) """VectorStoreRetriever object to connect to.""" - memory_key: str = "history" #: :meta private: + memory_key: str = "history" """Key name to locate the memories in the result of load_memory_variables.""" input_key: str | None = None diff --git a/libs/langchain/langchain_classic/output_parsers/regex_dict.py b/libs/langchain/langchain_classic/output_parsers/regex_dict.py index 5bcafb37156..f0052958c33 100644 --- a/libs/langchain/langchain_classic/output_parsers/regex_dict.py +++ b/libs/langchain/langchain_classic/output_parsers/regex_dict.py @@ -8,7 +8,7 @@ from langchain_core.output_parsers import BaseOutputParser class RegexDictParser(BaseOutputParser[dict[str, str]]): """Parse the output of an LLM call into a Dictionary using a regex.""" - regex_pattern: str = r"{}:\s?([^.'\n']*)\.?" # : :meta private: + regex_pattern: str = r"{}:\s?([^.'\n']*)\.?" """The regex pattern to use to parse the output.""" output_key_to_format: dict[str, str] """The keys to use for the output.""" diff --git a/libs/langchain/pyproject.toml b/libs/langchain/pyproject.toml index 6316b97ab18..f259e7d7044 100644 --- a/libs/langchain/pyproject.toml +++ b/libs/langchain/pyproject.toml @@ -3,8 +3,13 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-classic" +description = "Building applications with LLMs through composability" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.0" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.0,<2.0.0", @@ -16,10 +21,6 @@ dependencies = [ "PyYAML>=5.3.0,<7.0.0", "async-timeout>=4.0.0,<5.0.0; python_version < \"3.11\"", ] -name = "langchain-classic" -version = "1.0.0" -description = "Building applications with LLMs through composability" -readme = "README.md" [project.optional-dependencies] #community = ["langchain-community"] diff --git a/libs/langchain_v1/langchain/chat_models/base.py b/libs/langchain_v1/langchain/chat_models/base.py index beeae9acabd..d481eda62a2 100644 --- a/libs/langchain_v1/langchain/chat_models/base.py +++ b/libs/langchain_v1/langchain/chat_models/base.py @@ -602,7 +602,7 @@ class _ConfigurableModel(Runnable[LanguageModelInput, Any]): config: RunnableConfig | None = None, **kwargs: Any, ) -> _ConfigurableModel: - """Bind config to a Runnable, returning a new Runnable.""" + """Bind config to a `Runnable`, returning a new `Runnable`.""" config = RunnableConfig(**(config or {}), **cast("RunnableConfig", kwargs)) model_params = self._model_params(config) remaining_config = {k: v for k, v in config.items() if k != "configurable"} diff --git a/libs/langchain_v1/pyproject.toml b/libs/langchain_v1/pyproject.toml index af6af79aef1..4a458d4f550 100644 --- a/libs/langchain_v1/pyproject.toml +++ b/libs/langchain_v1/pyproject.toml @@ -3,8 +3,13 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain" +description = "Building applications with LLMs through composability" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.4" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.0,<2.0.0", @@ -12,11 +17,6 @@ dependencies = [ "pydantic>=2.7.4,<3.0.0", ] -name = "langchain" -version = "1.0.4" -description = "Building applications with LLMs through composability" -readme = "README.md" - [project.optional-dependencies] model-profiles = ["langchain-model-profiles"] community = ["langchain-community"] diff --git a/libs/model-profiles/pyproject.toml b/libs/model-profiles/pyproject.toml index 662b1f6735c..3d569ba88d3 100644 --- a/libs/model-profiles/pyproject.toml +++ b/libs/model-profiles/pyproject.toml @@ -3,19 +3,19 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-model-profiles" +description = "Centralized reference of LLM capabilities." +readme = "README.md" license = { text = "MIT" } +authors = [] + +version = "0.0.3" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "tomli>=2.0.0,<3.0.0; python_version < '3.11'", "typing-extensions>=4.7.0,<5.0.0", ] -name = "langchain-model-profiles" -version = "0.0.3" -description = "Centralized reference of LLM capabilities." -readme = "README.md" - [project.urls] Homepage = "https://docs.langchain.com/" Documentation = "https://reference.langchain.com/python/langchain_model_profiles/" diff --git a/libs/partners/anthropic/langchain_anthropic/chat_models.py b/libs/partners/anthropic/langchain_anthropic/chat_models.py index e2f0aa3fbe0..f93456d88dc 100644 --- a/libs/partners/anthropic/langchain_anthropic/chat_models.py +++ b/libs/partners/anthropic/langchain_anthropic/chat_models.py @@ -91,8 +91,11 @@ class AnthropicTool(TypedDict): """Anthropic tool definition.""" name: str + input_schema: dict[str, Any] + description: NotRequired[str] + cache_control: NotRequired[dict[str, str]] @@ -2189,11 +2192,11 @@ class ChatAnthropic(BaseChatModel): Args: schema: The output schema. Can be passed in as: - - an Anthropic tool schema, - - an OpenAI function/tool schema, - - a JSON Schema, - - a `TypedDict` class, - - or a Pydantic class. + - An Anthropic tool schema, + - An OpenAI function/tool schema, + - A JSON Schema, + - A `TypedDict` class, + - Or a Pydantic class. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -2204,11 +2207,15 @@ class ChatAnthropic(BaseChatModel): more on how to properly specify types and descriptions of schema fields when specifying a Pydantic or `TypedDict` class. include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. diff --git a/libs/partners/anthropic/langchain_anthropic/llms.py b/libs/partners/anthropic/langchain_anthropic/llms.py index 341e7fb3b05..d9f794cd2ac 100644 --- a/libs/partners/anthropic/langchain_anthropic/llms.py +++ b/libs/partners/anthropic/langchain_anthropic/llms.py @@ -1,4 +1,4 @@ -"""Anthropic LLM wrapper. Chat models are in chat_models.py.""" +"""Anthropic LLM wrapper. Chat models are in `chat_models.py`.""" from __future__ import annotations @@ -23,8 +23,10 @@ from typing_extensions import Self class _AnthropicCommon(BaseLanguageModel): - client: Any = None #: :meta private: - async_client: Any = None #: :meta private: + client: Any = None + + async_client: Any = None + model: str = Field(default="claude-sonnet-4-5", alias="model_name") """Model name to use.""" @@ -70,8 +72,11 @@ class _AnthropicCommon(BaseLanguageModel): """Automatically read from env var `ANTHROPIC_API_KEY` if not provided.""" HUMAN_PROMPT: str | None = None + AI_PROMPT: str | None = None + count_tokens: Callable[[str], int] | None = None + model_kwargs: dict[str, Any] = Field(default_factory=dict) @model_validator(mode="before") @@ -127,7 +132,7 @@ class _AnthropicCommon(BaseLanguageModel): class AnthropicLLM(LLM, _AnthropicCommon): - """Anthropic large language model. + """Anthropic text completion large language model (legacy LLM). To use, you should have the environment variable `ANTHROPIC_API_KEY` set with your API key, or pass it as a named parameter to the constructor. @@ -136,7 +141,7 @@ class AnthropicLLM(LLM, _AnthropicCommon): ```python from langchain_anthropic import AnthropicLLM - model = AnthropicLLM() + model = AnthropicLLM(model="claude-sonnet-4-5") ``` """ diff --git a/libs/partners/anthropic/pyproject.toml b/libs/partners/anthropic/pyproject.toml index 9ba168d5780..283a100679b 100644 --- a/libs/partners/anthropic/pyproject.toml +++ b/libs/partners/anthropic/pyproject.toml @@ -3,18 +3,19 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-anthropic" +description = "Integration package connecting Claude (Anthropic) APIs and LangChain" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.1" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "anthropic>=0.69.0,<1.0.0", "langchain-core>=1.0.0,<2.0.0", "pydantic>=2.7.4,<3.0.0", ] -name = "langchain-anthropic" -version = "1.0.1" -description = "Integration package connecting Claude (Anthropic) APIs and LangChain" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/anthropic" diff --git a/libs/partners/deepseek/langchain_deepseek/chat_models.py b/libs/partners/deepseek/langchain_deepseek/chat_models.py index 3659ec51166..df34c21bc08 100644 --- a/libs/partners/deepseek/langchain_deepseek/chat_models.py +++ b/libs/partners/deepseek/langchain_deepseek/chat_models.py @@ -386,10 +386,10 @@ class ChatDeepSeek(BaseChatOpenAI): Args: schema: The output schema. Can be passed in as: - - an OpenAI function/tool schema, - - a JSON Schema, - - a `TypedDict` class, - - or a Pydantic class. + - An OpenAI function/tool schema, + - A JSON Schema, + - A `TypedDict` class, + - Or a Pydantic class. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -408,11 +408,15 @@ class ChatDeepSeek(BaseChatOpenAI): Uses DeepSeek's [JSON mode feature](https://api-docs.deepseek.com/guides/json_mode). include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. diff --git a/libs/partners/deepseek/pyproject.toml b/libs/partners/deepseek/pyproject.toml index b1139d96110..5bd91f882d1 100644 --- a/libs/partners/deepseek/pyproject.toml +++ b/libs/partners/deepseek/pyproject.toml @@ -3,17 +3,18 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-deepseek" +description = "An integration package connecting DeepSeek and LangChain" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.0" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.0,<2.0.0", "langchain-openai>=1.0.0,<2.0.0", ] -name = "langchain-deepseek" -version = "1.0.0" -description = "An integration package connecting DeepSeek and LangChain" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/deepseek" diff --git a/libs/partners/fireworks/langchain_fireworks/chat_models.py b/libs/partners/fireworks/langchain_fireworks/chat_models.py index e89da1df73d..c8e3b18dfb2 100644 --- a/libs/partners/fireworks/langchain_fireworks/chat_models.py +++ b/libs/partners/fireworks/langchain_fireworks/chat_models.py @@ -306,16 +306,22 @@ class ChatFireworks(BaseChatModel): """Return whether this model can be serialized by LangChain.""" return True - client: Any = Field(default=None, exclude=True) #: :meta private: - async_client: Any = Field(default=None, exclude=True) #: :meta private: + client: Any = Field(default=None, exclude=True) + + async_client: Any = Field(default=None, exclude=True) + model_name: str = Field(alias="model") """Model name to use.""" + temperature: float | None = None """What sampling temperature to use.""" + stop: str | list[str] | None = Field(default=None, alias="stop_sequences") """Default stop sequences.""" + model_kwargs: dict[str, Any] = Field(default_factory=dict) """Holds any model parameters valid for `create` call not explicitly specified.""" + fireworks_api_key: SecretStr = Field( alias="api_key", default_factory=secret_from_env( @@ -336,18 +342,25 @@ class ChatFireworks(BaseChatModel): alias="base_url", default_factory=from_env("FIREWORKS_API_BASE", default=None) ) """Base URL path for API requests, leave blank if not using a proxy or service - emulator.""" + emulator. + """ + request_timeout: float | tuple[float, float] | Any | None = Field( default=None, alias="timeout" ) """Timeout for requests to Fireworks completion API. Can be `float`, - `httpx.Timeout` or `None`.""" + `httpx.Timeout` or `None`. + """ + streaming: bool = False """Whether to stream the results or not.""" + n: int = 1 """Number of chat completions to generate for each prompt.""" + max_tokens: int | None = None """Maximum number of tokens to generate.""" + max_retries: int | None = None """Maximum number of retries to make when generating.""" @@ -685,10 +698,10 @@ class ChatFireworks(BaseChatModel): Args: schema: The output schema. Can be passed in as: - - an OpenAI function/tool schema, - - a JSON Schema, - - a `TypedDict` class, - - or a Pydantic class. + - An OpenAI function/tool schema, + - A JSON Schema, + - A `TypedDict` class, + - Or a Pydantic class. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -712,11 +725,15 @@ class ChatFireworks(BaseChatModel): Added support for `'json_schema'`. include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. diff --git a/libs/partners/fireworks/langchain_fireworks/embeddings.py b/libs/partners/fireworks/langchain_fireworks/embeddings.py index c8eacbe6150..cd83e70d8f1 100644 --- a/libs/partners/fireworks/langchain_fireworks/embeddings.py +++ b/libs/partners/fireworks/langchain_fireworks/embeddings.py @@ -65,7 +65,8 @@ class FireworksEmbeddings(BaseModel, Embeddings): ``` """ - client: OpenAI = Field(default=None, exclude=True) # type: ignore[assignment] # :meta private: + client: OpenAI = Field(default=None, exclude=True) # type: ignore[assignment] + fireworks_api_key: SecretStr = Field( alias="api_key", default_factory=secret_from_env( @@ -77,6 +78,7 @@ class FireworksEmbeddings(BaseModel, Embeddings): Automatically read from env variable `FIREWORKS_API_KEY` if not provided. """ + model: str = "nomic-ai/nomic-embed-text-v1.5" model_config = ConfigDict( diff --git a/libs/partners/fireworks/pyproject.toml b/libs/partners/fireworks/pyproject.toml index 5fb87ec1312..6b7df1d5cf2 100644 --- a/libs/partners/fireworks/pyproject.toml +++ b/libs/partners/fireworks/pyproject.toml @@ -3,8 +3,13 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-fireworks" +description = "An integration package connecting Fireworks and LangChain" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.0" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.0,<2.0.0", @@ -13,10 +18,6 @@ dependencies = [ "requests>=2.0.0,<3.0.0", "aiohttp>=3.9.1,<4.0.0", ] -name = "langchain-fireworks" -version = "1.0.0" -description = "An integration package connecting Fireworks and LangChain" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/fireworks" diff --git a/libs/partners/groq/langchain_groq/chat_models.py b/libs/partners/groq/langchain_groq/chat_models.py index 3a1bf9ff1f0..3d82fe5ac85 100644 --- a/libs/partners/groq/langchain_groq/chat_models.py +++ b/libs/partners/groq/langchain_groq/chat_models.py @@ -300,14 +300,19 @@ class ChatGroq(BaseChatModel): ``` """ # noqa: E501 - client: Any = Field(default=None, exclude=True) #: :meta private: - async_client: Any = Field(default=None, exclude=True) #: :meta private: + client: Any = Field(default=None, exclude=True) + + async_client: Any = Field(default=None, exclude=True) + model_name: str = Field(alias="model") """Model name to use.""" + temperature: float = 0.7 """What sampling temperature to use.""" + stop: list[str] | str | None = Field(default=None, alias="stop_sequences") """Default stop sequences.""" + reasoning_format: Literal["parsed", "raw", "hidden"] | None = Field(default=None) """The format for reasoning output. Groq will default to raw if left undefined. @@ -323,6 +328,7 @@ class ChatGroq(BaseChatModel): See the [Groq documentation](https://console.groq.com/docs/reasoning#reasoning) for more details and a list of supported models. """ + reasoning_effort: str | None = Field(default=None) """The level of effort the model will put into reasoning. Groq will default to enabling reasoning if left undefined. @@ -331,32 +337,44 @@ class ChatGroq(BaseChatModel): for more details and a list of options and models that support setting a reasoning effort. """ + model_kwargs: dict[str, Any] = Field(default_factory=dict) """Holds any model parameters valid for `create` call not explicitly specified.""" + groq_api_key: SecretStr | None = Field( alias="api_key", default_factory=secret_from_env("GROQ_API_KEY", default=None) ) """Automatically inferred from env var `GROQ_API_KEY` if not provided.""" + groq_api_base: str | None = Field( alias="base_url", default_factory=from_env("GROQ_API_BASE", default=None) ) """Base URL path for API requests. Leave blank if not using a proxy or service - emulator.""" + emulator. + """ + # to support explicit proxy for Groq groq_proxy: str | None = Field(default_factory=from_env("GROQ_PROXY", default=None)) + request_timeout: float | tuple[float, float] | Any | None = Field( default=None, alias="timeout" ) """Timeout for requests to Groq completion API. Can be float, `httpx.Timeout` or - None.""" + `None`. + """ + max_retries: int = 2 """Maximum number of retries to make when generating.""" + streaming: bool = False """Whether to stream the results or not.""" + n: int = 1 """Number of chat completions to generate for each prompt.""" + max_tokens: int | None = None """Maximum number of tokens to generate.""" + service_tier: Literal["on_demand", "flex", "auto"] = Field(default="on_demand") """Optional parameter that you can include to specify the service tier you'd like to use for requests. @@ -371,12 +389,16 @@ class ChatGroq(BaseChatModel): See the [Groq documentation](https://console.groq.com/docs/flex-processing) for more details and a list of service tiers and descriptions. """ + default_headers: Mapping[str, str] | None = None + default_query: Mapping[str, object] | None = None + # Configure a custom httpx client. See the # [httpx documentation](https://www.python-httpx.org/api/#client) for more details. http_client: Any | None = None """Optional `httpx.Client`.""" + http_async_client: Any | None = None """Optional `httpx.AsyncClient`. Only used for async invocations. Must specify `http_client` as well if you'd like a custom client for sync invocations.""" @@ -826,10 +848,10 @@ class ChatGroq(BaseChatModel): Args: schema: The output schema. Can be passed in as: - - an OpenAI function/tool schema, - - a JSON Schema, - - a `TypedDict` class, - - or a Pydantic class. + - An OpenAI function/tool schema, + - A JSON Schema, + - A `TypedDict` class, + - Or a Pydantic class. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -877,11 +899,15 @@ class ChatGroq(BaseChatModel): `'json_mode'` does not support streaming responses stop sequences. include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. diff --git a/libs/partners/groq/pyproject.toml b/libs/partners/groq/pyproject.toml index ff2a8a742fe..c4a657e1833 100644 --- a/libs/partners/groq/pyproject.toml +++ b/libs/partners/groq/pyproject.toml @@ -3,17 +3,18 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-groq" +description = "An integration package connecting Groq and LangChain" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.0" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.0,<2.0.0", "groq>=0.30.0,<1.0.0" ] -name = "langchain-groq" -version = "1.0.0" -description = "An integration package connecting Groq and LangChain" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/groq" diff --git a/libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py b/libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py index 5316951a052..77f4a6f7afc 100644 --- a/libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py +++ b/libs/partners/huggingface/langchain_huggingface/chat_models/huggingface.py @@ -940,9 +940,9 @@ class ChatHuggingFace(BaseChatModel): Args: schema: The output schema. Can be passed in as: - - an OpenAI function/tool schema, - - a JSON Schema, - - a `TypedDict` class + - An OpenAI function/tool schema, + - A JSON Schema, + - A `TypedDict` class Pydantic class is currently supported. @@ -953,11 +953,15 @@ class ChatHuggingFace(BaseChatModel): - `'json_mode'`: uses JSON mode. include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. diff --git a/libs/partners/huggingface/langchain_huggingface/embeddings/huggingface_endpoint.py b/libs/partners/huggingface/langchain_huggingface/embeddings/huggingface_endpoint.py index 69d9fdf8844..e61c2292122 100644 --- a/libs/partners/huggingface/langchain_huggingface/embeddings/huggingface_endpoint.py +++ b/libs/partners/huggingface/langchain_huggingface/embeddings/huggingface_endpoint.py @@ -32,18 +32,24 @@ class HuggingFaceEndpointEmbeddings(BaseModel, Embeddings): ``` """ - client: Any = None #: :meta private: - async_client: Any = None #: :meta private: + client: Any = None + + async_client: Any = None + model: str | None = None """Model name to use.""" + provider: str | None = None """Name of the provider to use for inference with the model specified in `repo_id`. e.g. "sambanova". if not specified, defaults to HF Inference API. available providers can be found in the [huggingface_hub documentation](https://huggingface.co/docs/huggingface_hub/guides/inference#supported-providers-and-tasks).""" + repo_id: str | None = None """Huggingfacehub repository id, for backward compatibility.""" + task: str | None = "feature-extraction" """Task to call the model with.""" + model_kwargs: dict | None = None """Keyword arguments to pass to the model.""" diff --git a/libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py b/libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py index 1fa41ffed3d..f082aa0ae69 100644 --- a/libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py +++ b/libs/partners/huggingface/langchain_huggingface/llms/huggingface_endpoint.py @@ -81,58 +81,82 @@ class HuggingFaceEndpoint(LLM): endpoint_url: str | None = None """Endpoint URL to use. If repo_id is not specified then this needs to given or should be pass as env variable in `HF_INFERENCE_ENDPOINT`""" + repo_id: str | None = None """Repo to use. If endpoint_url is not specified then this needs to given""" + provider: str | None = None """Name of the provider to use for inference with the model specified in `repo_id`. e.g. "cerebras". if not specified, Defaults to "auto" i.e. the first of the providers available for the model, sorted by the user's order in https://hf.co/settings/inference-providers. available providers can be found in the [huggingface_hub documentation](https://huggingface.co/docs/huggingface_hub/guides/inference#supported-providers-and-tasks).""" + huggingfacehub_api_token: str | None = Field( default_factory=from_env("HUGGINGFACEHUB_API_TOKEN", default=None) ) + max_new_tokens: int = 512 """Maximum number of generated tokens""" + top_k: int | None = None """The number of highest probability vocabulary tokens to keep for top-k-filtering.""" + top_p: float | None = 0.95 """If set to < 1, only the smallest set of most probable tokens with probabilities that add up to `top_p` or higher are kept for generation.""" + typical_p: float | None = 0.95 """Typical Decoding mass. See [Typical Decoding for Natural Language Generation](https://arxiv.org/abs/2202.00666) for more information.""" + temperature: float | None = 0.8 """The value used to module the logits distribution.""" + repetition_penalty: float | None = None """The parameter for repetition penalty. 1.0 means no penalty. See [this paper](https://arxiv.org/pdf/1909.05858.pdf) for more details.""" + return_full_text: bool = False """Whether to prepend the prompt to the generated text""" + truncate: int | None = None """Truncate inputs tokens to the given size""" + stop_sequences: list[str] = Field(default_factory=list) """Stop generating tokens if a member of `stop_sequences` is generated""" + seed: int | None = None """Random sampling seed""" + inference_server_url: str = "" """text-generation-inference instance base url""" + timeout: int = 120 """Timeout in seconds""" + streaming: bool = False """Whether to generate a stream of tokens asynchronously""" + do_sample: bool = False """Activate logits sampling""" + watermark: bool = False """Watermarking with [A Watermark for Large Language Models] (https://arxiv.org/abs/2301.10226)""" + server_kwargs: dict[str, Any] = Field(default_factory=dict) """Holds any text-generation-inference server parameters not explicitly specified""" + model_kwargs: dict[str, Any] = Field(default_factory=dict) """Holds any model parameters valid for `call` not explicitly specified""" + model: str - client: Any = None #: :meta private: - async_client: Any = None #: :meta private: + + client: Any = None + + async_client: Any = None + task: str | None = None """Task to call the model with. Should be a task that returns `generated_text`.""" diff --git a/libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py b/libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py index f6edf545536..ba646f1309f 100644 --- a/libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py +++ b/libs/partners/huggingface/langchain_huggingface/llms/huggingface_pipeline.py @@ -71,15 +71,19 @@ class HuggingFacePipeline(BaseLLM): ``` """ - pipeline: Any = None #: :meta private: + pipeline: Any = None + model_id: str | None = None """The model name. If not set explicitly by the user, it will be inferred from the provided pipeline (if available). If neither is provided, the DEFAULT_MODEL_ID will be used.""" + model_kwargs: dict | None = None """Keyword arguments passed to the model.""" + pipeline_kwargs: dict | None = None """Keyword arguments passed to the pipeline.""" + batch_size: int = DEFAULT_BATCH_SIZE """Batch size to use when passing multiple documents to generate.""" diff --git a/libs/partners/huggingface/pyproject.toml b/libs/partners/huggingface/pyproject.toml index 203f85eb839..28c00e661e2 100644 --- a/libs/partners/huggingface/pyproject.toml +++ b/libs/partners/huggingface/pyproject.toml @@ -3,18 +3,19 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-huggingface" +description = "An integration package connecting Hugging Face and LangChain." license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.1" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.3,<2.0.0", "tokenizers>=0.19.1,<1.0.0", "huggingface-hub>=0.33.4,<1.0.0", ] -name = "langchain-huggingface" -version = "1.0.1" -description = "An integration package connecting Hugging Face and LangChain." -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/huggingface" diff --git a/libs/partners/mistralai/langchain_mistralai/chat_models.py b/libs/partners/mistralai/langchain_mistralai/chat_models.py index 9240dba23b8..660c38614c2 100644 --- a/libs/partners/mistralai/langchain_mistralai/chat_models.py +++ b/libs/partners/mistralai/langchain_mistralai/chat_models.py @@ -452,27 +452,41 @@ class ChatMistralAI(BaseChatModel): client: httpx.Client = Field( # type: ignore[assignment] # : meta private: default=None, exclude=True ) + async_client: httpx.AsyncClient = Field( # type: ignore[assignment] # : meta private: default=None, exclude=True - ) #: :meta private: + ) + mistral_api_key: SecretStr | None = Field( alias="api_key", default_factory=secret_from_env("MISTRAL_API_KEY", default=None), ) + endpoint: str | None = Field(default=None, alias="base_url") + max_retries: int = 5 + timeout: int = 120 + max_concurrent_requests: int = 64 + model: str = Field(default="mistral-small", alias="model_name") + temperature: float = 0.7 + max_tokens: int | None = None + top_p: float = 1 """Decode using nucleus sampling: consider the smallest set of tokens whose probability sum is at least `top_p`. Must be in the closed interval `[0.0, 1.0]`.""" + random_seed: int | None = None + safe_mode: bool | None = None + streaming: bool = False + model_kwargs: dict[str, Any] = Field(default_factory=dict) """Holds any invocation parameters not explicitly specified.""" @@ -803,10 +817,10 @@ class ChatMistralAI(BaseChatModel): Args: schema: The output schema. Can be passed in as: - - an OpenAI function/tool schema, - - a JSON Schema, - - a `TypedDict` class, - - or a Pydantic class. + - An OpenAI function/tool schema, + - A JSON Schema, + - A `TypedDict` class, + - Or a Pydantic class. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -836,11 +850,15 @@ class ChatMistralAI(BaseChatModel): Added method="json_schema" include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. diff --git a/libs/partners/mistralai/langchain_mistralai/embeddings.py b/libs/partners/mistralai/langchain_mistralai/embeddings.py index f8fd08dc72d..7c0ad474c68 100644 --- a/libs/partners/mistralai/langchain_mistralai/embeddings.py +++ b/libs/partners/mistralai/langchain_mistralai/embeddings.py @@ -124,20 +124,27 @@ class MistralAIEmbeddings(BaseModel, Embeddings): # The type for client and async_client is ignored because the type is not # an Optional after the model is initialized and the model_validator # is run. - client: httpx.Client = Field(default=None) # type: ignore[assignment] # :meta private: + client: httpx.Client = Field(default=None) # type: ignore[assignment] - async_client: httpx.AsyncClient = Field( # type: ignore[assignment] # :meta private: + async_client: httpx.AsyncClient = Field( # type: ignore[assignment] default=None ) + mistral_api_key: SecretStr = Field( alias="api_key", default_factory=secret_from_env("MISTRAL_API_KEY", default=""), ) + endpoint: str = "https://api.mistral.ai/v1/" + max_retries: int | None = 5 + timeout: int = 120 + wait_time: int | None = 30 + max_concurrent_requests: int = 64 + tokenizer: Tokenizer = Field(default=None) model: str = "mistral-embed" diff --git a/libs/partners/mistralai/pyproject.toml b/libs/partners/mistralai/pyproject.toml index 069ea54640a..5221a40ac6a 100644 --- a/libs/partners/mistralai/pyproject.toml +++ b/libs/partners/mistralai/pyproject.toml @@ -3,8 +3,13 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-mistralai" +description = "An integration package connecting Mistral and LangChain" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.1" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.0,<2.0.0", @@ -13,10 +18,6 @@ dependencies = [ "httpx-sse>=0.3.1,<1.0.0", "pydantic>=2.0.0,<3.0.0", ] -name = "langchain-mistralai" -version = "1.0.1" -description = "An integration package connecting Mistral and LangChain" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/mistralai" diff --git a/libs/partners/ollama/langchain_ollama/chat_models.py b/libs/partners/ollama/langchain_ollama/chat_models.py index e13901d4965..21567e73eca 100644 --- a/libs/partners/ollama/langchain_ollama/chat_models.py +++ b/libs/partners/ollama/langchain_ollama/chat_models.py @@ -1258,10 +1258,10 @@ class ChatOllama(BaseChatModel): Args: schema: The output schema. Can be passed in as: - - an OpenAI function/tool schema. - - a JSON Schema, - - a `TypedDict` class, - - or a Pydantic class. + - An OpenAI function/tool schema. + - A JSON Schema, + - A `TypedDict` class, + - Or a Pydantic class. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -1284,11 +1284,15 @@ class ChatOllama(BaseChatModel): desired schema into the model call. include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. diff --git a/libs/partners/ollama/pyproject.toml b/libs/partners/ollama/pyproject.toml index 16507cab8ba..94af7cb89c4 100644 --- a/libs/partners/ollama/pyproject.toml +++ b/libs/partners/ollama/pyproject.toml @@ -3,17 +3,18 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-ollama" +description = "An integration package connecting Ollama and LangChain" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.0" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "ollama>=0.6.0,<1.0.0", "langchain-core>=1.0.0,<2.0.0", ] -name = "langchain-ollama" -version = "1.0.0" -description = "An integration package connecting Ollama and LangChain" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/ollama" diff --git a/libs/partners/openai/langchain_openai/chat_models/azure.py b/libs/partners/openai/langchain_openai/chat_models/azure.py index eec47611578..183e27fa681 100644 --- a/libs/partners/openai/langchain_openai/chat_models/azure.py +++ b/libs/partners/openai/langchain_openai/chat_models/azure.py @@ -837,10 +837,10 @@ class AzureChatOpenAI(BaseChatOpenAI): Args: schema: The output schema. Can be passed in as: - - a JSON Schema, - - a `TypedDict` class, - - a Pydantic class, - - or an OpenAI function/tool schema. + - A JSON Schema, + - A `TypedDict` class, + - A Pydantic class, + - Or an OpenAI function/tool schema. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -869,11 +869,15 @@ class AzureChatOpenAI(BaseChatOpenAI): support which methods [here](https://platform.openai.com/docs/guides/structured-outputs/function-calling-vs-response-format). include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. diff --git a/libs/partners/openai/langchain_openai/chat_models/base.py b/libs/partners/openai/langchain_openai/chat_models/base.py index a43045bc564..a694d68e35a 100644 --- a/libs/partners/openai/langchain_openai/chat_models/base.py +++ b/libs/partners/openai/langchain_openai/chat_models/base.py @@ -463,16 +463,23 @@ _DictOrPydantic: TypeAlias = dict | _BM class BaseChatOpenAI(BaseChatModel): """Base wrapper around OpenAI large language models for chat.""" - client: Any = Field(default=None, exclude=True) #: :meta private: - async_client: Any = Field(default=None, exclude=True) #: :meta private: - root_client: Any = Field(default=None, exclude=True) #: :meta private: - root_async_client: Any = Field(default=None, exclude=True) #: :meta private: + client: Any = Field(default=None, exclude=True) + + async_client: Any = Field(default=None, exclude=True) + + root_client: Any = Field(default=None, exclude=True) + + root_async_client: Any = Field(default=None, exclude=True) + model_name: str = Field(default="gpt-3.5-turbo", alias="model") """Model name to use.""" + temperature: float | None = None """What sampling temperature to use.""" + model_kwargs: dict[str, Any] = Field(default_factory=dict) """Holds any model parameters valid for `create` call not explicitly specified.""" + openai_api_key: ( SecretStr | None | Callable[[], str] | Callable[[], Awaitable[str]] ) = Field( @@ -524,19 +531,24 @@ class BaseChatOpenAI(BaseChatModel): model = ChatOpenAI(model="gpt-5-nano", api_key=get_api_key) ``` """ + openai_api_base: str | None = Field(default=None, alias="base_url") """Base URL path for API requests, leave blank if not using a proxy or service emulator.""" # noqa: E501 + openai_organization: str | None = Field(default=None, alias="organization") """Automatically inferred from env var `OPENAI_ORG_ID` if not provided.""" + # to support explicit proxy for OpenAI openai_proxy: str | None = Field( default_factory=from_env("OPENAI_PROXY", default=None) ) + request_timeout: float | tuple[float, float] | Any | None = Field( default=None, alias="timeout" ) """Timeout for requests to OpenAI completion API. Can be float, `httpx.Timeout` or `None`.""" + stream_usage: bool | None = None """Whether to include usage metadata in streaming output. If enabled, an additional message chunk will be generated during the stream including usage metadata. @@ -550,30 +562,42 @@ class BaseChatOpenAI(BaseChatModel): !!! warning "Behavior changed in `langchain-openai` 0.3.35" Enabled for default base URL and client. """ + max_retries: int | None = None """Maximum number of retries to make when generating.""" + presence_penalty: float | None = None """Penalizes repeated tokens.""" + frequency_penalty: float | None = None """Penalizes repeated tokens according to frequency.""" + seed: int | None = None """Seed for generation""" + logprobs: bool | None = None """Whether to return logprobs.""" + top_logprobs: int | None = None """Number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to true if this parameter is used.""" + logit_bias: dict[int, int] | None = None """Modify the likelihood of specified tokens appearing in the completion.""" + streaming: bool = False """Whether to stream the results or not.""" + n: int | None = None """Number of chat completions to generate for each prompt.""" + top_p: float | None = None """Total probability mass of tokens to consider at each step.""" + max_tokens: int | None = Field(default=None) """Maximum number of tokens to generate.""" + reasoning_effort: str | None = None """Constrains effort on reasoning for reasoning models. For use with the Chat Completions API. @@ -584,6 +608,7 @@ class BaseChatOpenAI(BaseChatModel): `'high'`. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response. """ + reasoning: dict[str, Any] | None = None """Reasoning parameters for reasoning models. For use with the Responses API. @@ -596,6 +621,7 @@ class BaseChatOpenAI(BaseChatModel): !!! version-added "Added in `langchain-openai` 0.3.24" """ + verbosity: str | None = None """Controls the verbosity level of responses for reasoning models. For use with the Responses API. @@ -604,6 +630,7 @@ class BaseChatOpenAI(BaseChatModel): !!! version-added "Added in `langchain-openai` 0.3.28" """ + tiktoken_model_name: str | None = None """The model name to pass to tiktoken when using this class. Tiktoken is used to count the number of tokens in documents to constrain @@ -614,19 +641,25 @@ class BaseChatOpenAI(BaseChatModel): when using one of the many model providers that expose an OpenAI-like API but with different models. In those cases, in order to avoid erroring when tiktoken is called, you can specify a model name to use here.""" + default_headers: Mapping[str, str] | None = None + default_query: Mapping[str, object] | None = None + # Configure a custom httpx client. See the # [httpx documentation](https://www.python-httpx.org/api/#client) for more details. http_client: Any | None = Field(default=None, exclude=True) """Optional `httpx.Client`. Only used for sync invocations. Must specify `http_async_client` as well if you'd like a custom client for async invocations. """ + http_async_client: Any | None = Field(default=None, exclude=True) """Optional `httpx.AsyncClient`. Only used for async invocations. Must specify `http_client` as well if you'd like a custom client for sync invocations.""" + stop: list[str] | str | None = Field(default=None, alias="stop_sequences") """Default stop sequences.""" + extra_body: Mapping[str, Any] | None = None """Optional additional JSON properties to include in the request parameters when making requests to OpenAI compatible APIs, such as vLLM, LM Studio, or other @@ -649,6 +682,7 @@ class BaseChatOpenAI(BaseChatModel): include_response_headers: bool = False """Whether to include response headers in the output message `response_metadata`.""" + disabled_params: dict[str, Any] | None = Field(default=None) """Parameters of the OpenAI client or `chat.completions` endpoint that should be disabled for the given model. @@ -1823,10 +1857,10 @@ class BaseChatOpenAI(BaseChatModel): Args: schema: The output schema. Can be passed in as: - - an OpenAI function/tool schema, - - a JSON Schema, - - a `TypedDict` class, - - or a Pydantic class. + - An OpenAI function/tool schema, + - A JSON Schema, + - A `TypedDict` class, + - Or a Pydantic class. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -1850,11 +1884,15 @@ class BaseChatOpenAI(BaseChatModel): formatting the output into the desired schema into the model call include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. @@ -2957,11 +2995,15 @@ class ChatOpenAI(BaseChatOpenAI): # type: ignore[override] Learn more about the [differences between methods](https://platform.openai.com/docs/guides/structured-outputs/function-calling-vs-response-format). include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. diff --git a/libs/partners/openai/langchain_openai/embeddings/base.py b/libs/partners/openai/langchain_openai/embeddings/base.py index bd3dbf3416f..c2a87fe06b4 100644 --- a/libs/partners/openai/langchain_openai/embeddings/base.py +++ b/libs/partners/openai/langchain_openai/embeddings/base.py @@ -159,44 +159,55 @@ class OpenAIEmbeddings(BaseModel, Embeddings): ``` """ - client: Any = Field(default=None, exclude=True) #: :meta private: - async_client: Any = Field(default=None, exclude=True) #: :meta private: + client: Any = Field(default=None, exclude=True) + + async_client: Any = Field(default=None, exclude=True) + model: str = "text-embedding-ada-002" + dimensions: int | None = None """The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models. """ + # to support Azure OpenAI Service custom deployment names deployment: str | None = model + # TODO: Move to AzureOpenAIEmbeddings. openai_api_version: str | None = Field( default_factory=from_env("OPENAI_API_VERSION", default=None), alias="api_version", ) """Automatically inferred from env var `OPENAI_API_VERSION` if not provided.""" + # to support Azure OpenAI Service custom endpoints openai_api_base: str | None = Field( alias="base_url", default_factory=from_env("OPENAI_API_BASE", default=None) ) """Base URL path for API requests, leave blank if not using a proxy or service emulator.""" + # to support Azure OpenAI Service custom endpoints openai_api_type: str | None = Field( default_factory=from_env("OPENAI_API_TYPE", default=None) ) + # to support explicit proxy for OpenAI openai_proxy: str | None = Field( default_factory=from_env("OPENAI_PROXY", default=None) ) + embedding_ctx_length: int = 8191 """The maximum number of tokens to embed at once.""" + openai_api_key: ( SecretStr | None | Callable[[], str] | Callable[[], Awaitable[str]] ) = Field( alias="api_key", default_factory=secret_from_env("OPENAI_API_KEY", default=None) ) """Automatically inferred from env var `OPENAI_API_KEY` if not provided.""" + openai_organization: str | None = Field( alias="organization", default_factory=from_env( @@ -204,21 +215,29 @@ class OpenAIEmbeddings(BaseModel, Embeddings): ), ) """Automatically inferred from env var `OPENAI_ORG_ID` if not provided.""" + allowed_special: Literal["all"] | set[str] | None = None + disallowed_special: Literal["all"] | set[str] | Sequence[str] | None = None + chunk_size: int = 1000 """Maximum number of texts to embed in each batch""" + max_retries: int = 2 """Maximum number of retries to make when generating.""" + request_timeout: float | tuple[float, float] | Any | None = Field( default=None, alias="timeout" ) """Timeout for requests to OpenAI completion API. Can be float, `httpx.Timeout` or None.""" + headers: Any = None + tiktoken_enabled: bool = True """Set this to False for non-OpenAI implementations of the embeddings API, e.g. the `--extensions openai` extension for `text-generation-webui`""" + tiktoken_model_name: str | None = None """The model name to pass to tiktoken when using this class. Tiktoken is used to count the number of tokens in documents to constrain @@ -229,28 +248,39 @@ class OpenAIEmbeddings(BaseModel, Embeddings): when using one of the many model providers that expose an OpenAI-like API but with different models. In those cases, in order to avoid erroring when tiktoken is called, you can specify a model name to use here.""" + show_progress_bar: bool = False """Whether to show a progress bar when embedding.""" + model_kwargs: dict[str, Any] = Field(default_factory=dict) """Holds any model parameters valid for `create` call not explicitly specified.""" + skip_empty: bool = False """Whether to skip empty strings when embedding or raise an error.""" + default_headers: Mapping[str, str] | None = None + default_query: Mapping[str, object] | None = None + # Configure a custom httpx client. See the # [httpx documentation](https://www.python-httpx.org/api/#client) for more details. + retry_min_seconds: int = 4 """Min number of seconds to wait between retries""" + retry_max_seconds: int = 20 """Max number of seconds to wait between retries""" + http_client: Any | None = None """Optional `httpx.Client`. Only used for sync invocations. Must specify `http_async_client` as well if you'd like a custom client for async invocations. """ + http_async_client: Any | None = None """Optional `httpx.AsyncClient`. Only used for async invocations. Must specify `http_client` as well if you'd like a custom client for sync invocations.""" + check_embedding_ctx_length: bool = True """Whether to check the token length of inputs and automatically split inputs longer than embedding_ctx_length.""" diff --git a/libs/partners/openai/langchain_openai/llms/base.py b/libs/partners/openai/langchain_openai/llms/base.py index 08f4dc458f1..edd5c837e62 100644 --- a/libs/partners/openai/langchain_openai/llms/base.py +++ b/libs/partners/openai/langchain_openai/llms/base.py @@ -164,37 +164,50 @@ class BaseOpenAI(BaseLLM): """ - client: Any = Field(default=None, exclude=True) #: :meta private: - async_client: Any = Field(default=None, exclude=True) #: :meta private: + client: Any = Field(default=None, exclude=True) + + async_client: Any = Field(default=None, exclude=True) + model_name: str = Field(default="gpt-3.5-turbo-instruct", alias="model") """Model name to use.""" + temperature: float = 0.7 """What sampling temperature to use.""" + max_tokens: int = 256 """The maximum number of tokens to generate in the completion. -1 returns as many tokens as possible given the prompt and the models maximal context size.""" + top_p: float = 1 """Total probability mass of tokens to consider at each step.""" + frequency_penalty: float = 0 """Penalizes repeated tokens according to frequency.""" + presence_penalty: float = 0 """Penalizes repeated tokens.""" + n: int = 1 """How many completions to generate for each prompt.""" + best_of: int = 1 """Generates best_of completions server-side and returns the "best".""" + model_kwargs: dict[str, Any] = Field(default_factory=dict) """Holds any model parameters valid for `create` call not explicitly specified.""" + openai_api_key: SecretStr | None | Callable[[], str] = Field( alias="api_key", default_factory=secret_from_env("OPENAI_API_KEY", default=None) ) """Automatically inferred from env var `OPENAI_API_KEY` if not provided.""" + openai_api_base: str | None = Field( alias="base_url", default_factory=from_env("OPENAI_API_BASE", default=None) ) """Base URL path for API requests, leave blank if not using a proxy or service emulator.""" + openai_organization: str | None = Field( alias="organization", default_factory=from_env( @@ -202,32 +215,43 @@ class BaseOpenAI(BaseLLM): ), ) """Automatically inferred from env var `OPENAI_ORG_ID` if not provided.""" + # to support explicit proxy for OpenAI openai_proxy: str | None = Field( default_factory=from_env("OPENAI_PROXY", default=None) ) + batch_size: int = 20 """Batch size to use when passing multiple documents to generate.""" + request_timeout: float | tuple[float, float] | Any | None = Field( default=None, alias="timeout" ) """Timeout for requests to OpenAI completion API. Can be float, `httpx.Timeout` or None.""" + logit_bias: dict[str, float] | None = None """Adjust the probability of specific tokens being generated.""" + max_retries: int = 2 """Maximum number of retries to make when generating.""" + seed: int | None = None """Seed for generation""" + logprobs: int | None = None """Include the log probabilities on the logprobs most likely output tokens, as well the chosen tokens.""" + streaming: bool = False """Whether to stream the results or not.""" + allowed_special: Literal["all"] | set[str] = set() """Set of special tokens that are allowed。""" + disallowed_special: Literal["all"] | Collection[str] = "all" """Set of special tokens that are not allowed。""" + tiktoken_model_name: str | None = None """The model name to pass to tiktoken when using this class. Tiktoken is used to count the number of tokens in documents to constrain @@ -238,8 +262,11 @@ class BaseOpenAI(BaseLLM): when using one of the many model providers that expose an OpenAI-like API but with different models. In those cases, in order to avoid erroring when tiktoken is called, you can specify a model name to use here.""" + default_headers: Mapping[str, str] | None = None + default_query: Mapping[str, object] | None = None + # Configure a custom httpx client. See the # [httpx documentation](https://www.python-httpx.org/api/#client) for more details. http_client: Any | None = None @@ -247,9 +274,11 @@ class BaseOpenAI(BaseLLM): `http_async_client` as well if you'd like a custom client for async invocations. """ + http_async_client: Any | None = None """Optional `httpx.AsyncClient`. Only used for async invocations. Must specify `http_client` as well if you'd like a custom client for sync invocations.""" + extra_body: Mapping[str, Any] | None = None """Optional additional JSON properties to include in the request parameters when making requests to OpenAI compatible APIs, such as vLLM.""" diff --git a/libs/partners/openai/pyproject.toml b/libs/partners/openai/pyproject.toml index fbf1707c623..362f6db73b4 100644 --- a/libs/partners/openai/pyproject.toml +++ b/libs/partners/openai/pyproject.toml @@ -3,18 +3,19 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-openai" +description = "An integration package connecting OpenAI and LangChain" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.2" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.2,<2.0.0", "openai>=1.109.1,<3.0.0", "tiktoken>=0.7.0,<1.0.0", ] -name = "langchain-openai" -version = "1.0.2" -description = "An integration package connecting OpenAI and LangChain" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/openai" diff --git a/libs/partners/perplexity/langchain_perplexity/chat_models.py b/libs/partners/perplexity/langchain_perplexity/chat_models.py index 4321c057552..601e7c32dc2 100644 --- a/libs/partners/perplexity/langchain_perplexity/chat_models.py +++ b/libs/partners/perplexity/langchain_perplexity/chat_models.py @@ -165,24 +165,32 @@ class ChatPerplexity(BaseChatModel): ``` """ # noqa: E501 - client: Any = None #: :meta private: + client: Any = None + model: str = "sonar" """Model name.""" + temperature: float = 0.7 """What sampling temperature to use.""" + model_kwargs: dict[str, Any] = Field(default_factory=dict) """Holds any model parameters valid for `create` call not explicitly specified.""" + pplx_api_key: SecretStr | None = Field( default_factory=secret_from_env("PPLX_API_KEY", default=None), alias="api_key" ) """Base URL path for API requests, leave blank if not using a proxy or service emulator.""" + request_timeout: float | tuple[float, float] | None = Field(None, alias="timeout") """Timeout for requests to PerplexityChat completion API.""" + max_retries: int = 6 """Maximum number of retries to make when generating.""" + streaming: bool = False """Whether to stream the results or not.""" + max_tokens: int | None = None """Maximum number of tokens to generate.""" @@ -459,15 +467,18 @@ class ChatPerplexity(BaseChatModel): include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. - strict: Unsupported: whether to enable strict schema adherence when generating the output. This parameter is included for compatibility with other diff --git a/libs/partners/perplexity/pyproject.toml b/libs/partners/perplexity/pyproject.toml index 72e9f926189..5d082d456af 100644 --- a/libs/partners/perplexity/pyproject.toml +++ b/libs/partners/perplexity/pyproject.toml @@ -3,17 +3,18 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-perplexity" +description = "An integration package connecting Perplexity and LangChain" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.0" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.0,<2.0.0", "openai>=2.0.0,<3.0.0", ] -name = "langchain-perplexity" -version = "1.0.0" -description = "An integration package connecting Perplexity and LangChain" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/perplexity" diff --git a/libs/partners/xai/langchain_xai/chat_models.py b/libs/partners/xai/langchain_xai/chat_models.py index d717e7bf459..c407bbfd730 100644 --- a/libs/partners/xai/langchain_xai/chat_models.py +++ b/libs/partners/xai/langchain_xai/chat_models.py @@ -600,10 +600,10 @@ class ChatXAI(BaseChatOpenAI): # type: ignore[override] Args: schema: The output schema. Can be passed in as: - - an OpenAI function/tool schema, - - a JSON Schema, - - a `TypedDict` class, - - or a Pydantic class. + - An OpenAI function/tool schema, + - A JSON Schema, + - A `TypedDict` class, + - Or a Pydantic class. If `schema` is a Pydantic class then the model output will be a Pydantic instance of that class, and the model-generated fields will be @@ -624,15 +624,18 @@ class ChatXAI(BaseChatOpenAI): # type: ignore[override] Uses xAI's JSON mode feature. include_raw: - If `False` then only the parsed structured output is returned. If - an error occurs during model output parsing it will be raised. If `True` - then both the raw model response (a `BaseMessage`) and the parsed model - response will be returned. If an error occurs during output parsing it - will be caught and returned as well. + If `False` then only the parsed structured output is returned. + + If an error occurs during model output parsing it will be raised. + + If `True` then both the raw model response (a `BaseMessage`) and the + parsed model response will be returned. + + If an error occurs during output parsing it will be caught and returned + as well. The final output is always a `dict` with keys `'raw'`, `'parsed'`, and `'parsing_error'`. - strict: - `True`: Model output is guaranteed to exactly match the schema. diff --git a/libs/partners/xai/pyproject.toml b/libs/partners/xai/pyproject.toml index dad6f3ccd43..bbe4682fa40 100644 --- a/libs/partners/xai/pyproject.toml +++ b/libs/partners/xai/pyproject.toml @@ -3,8 +3,13 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-xai" +description = "An integration package connecting xAI and LangChain" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.0" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-openai>=1.0.0,<2.0.0", @@ -12,10 +17,6 @@ dependencies = [ "requests>=2.0.0,<3.0.0", "aiohttp>=3.9.1,<4.0.0", ] -name = "langchain-xai" -version = "1.0.0" -description = "An integration package connecting xAI and LangChain" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/oss/python/integrations/providers/xai" diff --git a/libs/standard-tests/pyproject.toml b/libs/standard-tests/pyproject.toml index 2d3465df7a6..86beacc93cb 100644 --- a/libs/standard-tests/pyproject.toml +++ b/libs/standard-tests/pyproject.toml @@ -3,8 +3,13 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [{ name = "Erick Friis", email = "erick@langchain.dev" }] +name = "langchain-tests" +description = "Standard tests for LangChain implementations" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.1" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.3,<2.0.0", @@ -20,10 +25,6 @@ dependencies = [ "numpy>=1.26.2; python_version<'3.13'", "numpy>=2.1.0; python_version>='3.13'", ] -name = "langchain-tests" -version = "1.0.1" -description = "Standard tests for LangChain implementations" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/" diff --git a/libs/text-splitters/pyproject.toml b/libs/text-splitters/pyproject.toml index b513dafacbf..1e2ce10ab1c 100644 --- a/libs/text-splitters/pyproject.toml +++ b/libs/text-splitters/pyproject.toml @@ -3,16 +3,17 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] -authors = [] +name = "langchain-text-splitters" +description = "LangChain text splitting utilities" license = { text = "MIT" } +readme = "README.md" +authors = [] + +version = "1.0.0" requires-python = ">=3.10.0,<4.0.0" dependencies = [ "langchain-core>=1.0.0,<2.0.0", ] -name = "langchain-text-splitters" -version = "1.0.0" -description = "LangChain text splitting utilities" -readme = "README.md" [project.urls] Homepage = "https://docs.langchain.com/"