Skip to content

Commit

Permalink
Merge branch 'master' into fix-cosmosdb-hybrid-search
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMcH authored Jan 21, 2025
2 parents f178c33 + 1c4ce7b commit 0a035e3
Show file tree
Hide file tree
Showing 95 changed files with 365 additions and 458 deletions.
5 changes: 2 additions & 3 deletions libs/core/langchain_core/_api/beta_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def beta(
``@beta`` would mess up ``__init__`` inheritance when installing its
own (annotation-emitting) ``C.__init__``).
Arguments:
Args:
message : str, optional
Override the default beta message. The %(since)s,
%(name)s, %(alternative)s, %(obj_type)s, %(addendum)s,
Expand All @@ -63,8 +63,7 @@ def beta(
addendum : str, optional
Additional text appended directly to the final message.
Examples
--------
Examples:
.. code-block:: python
Expand Down
6 changes: 2 additions & 4 deletions libs/core/langchain_core/_api/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def deprecated(
defaults to 'class' if decorating a class, 'attribute' if decorating a
property, and 'function' otherwise.
Arguments:
Args:
since : str
The release at which this API became deprecated.
message : str, optional
Expand All @@ -122,8 +122,7 @@ def deprecated(
since. Set to other Falsy values to not schedule a removal
date. Cannot be used together with pending.
Examples
--------
Examples:
.. code-block:: python
Expand Down Expand Up @@ -183,7 +182,6 @@ def warning_emitting_wrapper(*args: Any, **kwargs: Any) -> Any:

async def awarning_emitting_wrapper(*args: Any, **kwargs: Any) -> Any:
"""Same as warning_emitting_wrapper, but for async functions."""

nonlocal warned
if not warned and not is_caller_internal():
warned = True
Expand Down
4 changes: 2 additions & 2 deletions libs/core/langchain_core/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def is_lc_serializable(cls) -> bool:
@classmethod
def get_lc_namespace(cls) -> list[str]:
"""Get the namespace of the langchain object.
Default is ["langchain", "schema", "agent"]."""
Default is ["langchain", "schema", "agent"].
"""
return ["langchain", "schema", "agent"]

@property
Expand Down Expand Up @@ -189,7 +190,6 @@ def _convert_agent_observation_to_messages(
Returns:
AIMessage that corresponds to the original tool invocation.
"""

if isinstance(agent_action, AgentActionMessageLog):
return [_create_function_message(agent_action, observation)]
else:
Expand Down
3 changes: 1 addition & 2 deletions libs/core/langchain_core/beta/runnables/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ async def ainvoke(


class Context:
"""
Context for a runnable.
"""Context for a runnable.
The `Context` class provides methods for creating context scopes,
getters, and setters within a runnable. It allows for managing
Expand Down
21 changes: 14 additions & 7 deletions libs/core/langchain_core/callbacks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def on_chain_end(
outputs (Dict[str, Any]): The outputs of the chain.
run_id (UUID): The run ID. This is the ID of the current run.
parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
kwargs (Any): Additional keyword arguments."""
kwargs (Any): Additional keyword arguments.
"""

def on_chain_error(
self,
Expand All @@ -147,7 +148,8 @@ def on_chain_error(
error (BaseException): The error that occurred.
run_id (UUID): The run ID. This is the ID of the current run.
parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
kwargs (Any): Additional keyword arguments."""
kwargs (Any): Additional keyword arguments.
"""

def on_agent_action(
self,
Expand All @@ -163,7 +165,8 @@ def on_agent_action(
action (AgentAction): The agent action.
run_id (UUID): The run ID. This is the ID of the current run.
parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
kwargs (Any): Additional keyword arguments."""
kwargs (Any): Additional keyword arguments.
"""

def on_agent_finish(
self,
Expand All @@ -179,7 +182,8 @@ def on_agent_finish(
finish (AgentFinish): The agent finish.
run_id (UUID): The run ID. This is the ID of the current run.
parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
kwargs (Any): Additional keyword arguments."""
kwargs (Any): Additional keyword arguments.
"""


class ToolManagerMixin:
Expand All @@ -199,7 +203,8 @@ def on_tool_end(
output (Any): The output of the tool.
run_id (UUID): The run ID. This is the ID of the current run.
parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
kwargs (Any): Additional keyword arguments."""
kwargs (Any): Additional keyword arguments.
"""

def on_tool_error(
self,
Expand All @@ -215,7 +220,8 @@ def on_tool_error(
error (BaseException): The error that occurred.
run_id (UUID): The run ID. This is the ID of the current run.
parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
kwargs (Any): Additional keyword arguments."""
kwargs (Any): Additional keyword arguments.
"""


class CallbackManagerMixin:
Expand Down Expand Up @@ -824,7 +830,8 @@ async def on_retriever_end(
run_id (UUID): The run ID. This is the ID of the current run.
parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
tags (Optional[List[str]]): The tags.
kwargs (Any): Additional keyword arguments."""
kwargs (Any): Additional keyword arguments.
"""

async def on_retriever_error(
self,
Expand Down
6 changes: 2 additions & 4 deletions libs/core/langchain_core/callbacks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ async def atrace_as_chain_group(
Defaults to None.
metadata (Dict[str, Any], optional): The metadata to apply to all runs.
Defaults to None.
Returns:
AsyncCallbackManager: The async callback manager for the chain group.
Expand Down Expand Up @@ -216,8 +217,7 @@ async def atrace_as_chain_group(


def shielded(func: Func) -> Func:
"""
Makes so an awaitable method is always shielded from cancellation.
"""Makes so an awaitable method is always shielded from cancellation.
Args:
func (Callable): The function to shield.
Expand Down Expand Up @@ -1310,7 +1310,6 @@ def on_chat_model_start(
List[CallbackManagerForLLMRun]: A callback manager for each
list of messages as an LLM run.
"""

managers = []
for message_list in messages:
if run_id is not None:
Expand Down Expand Up @@ -1729,7 +1728,6 @@ async def on_llm_start(
callback managers, one for each LLM Run corresponding
to each prompt.
"""

inline_tasks = []
non_inline_tasks = []
inline_handlers = [handler for handler in self.handlers if handler.run_inline]
Expand Down
5 changes: 2 additions & 3 deletions libs/core/langchain_core/chat_history.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""**Chat message history** stores a history of the message interactions in a chat.
**Class hierarchy:**
.. code-block::
Expand Down Expand Up @@ -187,10 +186,10 @@ async def aadd_messages(self, messages: Sequence[BaseMessage]) -> None:

@abstractmethod
def clear(self) -> None:
"""Remove all messages from the store"""
"""Remove all messages from the store."""

async def aclear(self) -> None:
"""Async remove all messages from the store"""
"""Async remove all messages from the store."""
from langchain_core.runnables.config import run_in_executor

await run_in_executor(None, self.clear)
Expand Down
3 changes: 2 additions & 1 deletion libs/core/langchain_core/chat_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class ChatSession(TypedDict, total=False):
"""Chat Session represents a single
conversation, channel, or other group of messages."""
conversation, channel, or other group of messages.
"""

messages: Sequence[BaseMessage]
"""A sequence of the LangChain chat messages loaded from the source."""
Expand Down
1 change: 0 additions & 1 deletion libs/core/langchain_core/document_loaders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def load_and_split(
Returns:
List of Documents.
"""

if text_splitter is None:
try:
from langchain_text_splitters import RecursiveCharacterTextSplitter
Expand Down
14 changes: 8 additions & 6 deletions libs/core/langchain_core/example_selectors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ def add_example(self, example: dict[str, str]) -> Any:
Args:
example: A dictionary with keys as input variables
and values as their values."""
and values as their values.
"""

async def aadd_example(self, example: dict[str, str]) -> Any:
"""Async add new example to store.
Args:
example: A dictionary with keys as input variables
and values as their values."""

and values as their values.
"""
return await run_in_executor(None, self.add_example, example)

@abstractmethod
Expand All @@ -32,13 +33,14 @@ def select_examples(self, input_variables: dict[str, str]) -> list[dict]:
Args:
input_variables: A dictionary with keys as input variables
and values as their values."""
and values as their values.
"""

async def aselect_examples(self, input_variables: dict[str, str]) -> list[dict]:
"""Async select which examples to use based on the inputs.
Args:
input_variables: A dictionary with keys as input variables
and values as their values."""

and values as their values.
"""
return await run_in_executor(None, self.select_examples, input_variables)
1 change: 0 additions & 1 deletion libs/core/langchain_core/example_selectors/length_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ async def aadd_example(self, example: dict[str, str]) -> None:
example: A dictionary with keys as input variables
and values as their values.
"""

self.add_example(example)

@model_validator(mode="after")
Expand Down
5 changes: 2 additions & 3 deletions libs/core/langchain_core/indexing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def index(
For the time being, documents are indexed using their hashes, and users
are not able to specify the uid of the document.
IMPORTANT:
Important:
* In full mode, the loader should be returning
the entire dataset, and not just a subset of the dataset.
Otherwise, the auto_cleanup will remove documents that it is not
Expand Down Expand Up @@ -546,7 +546,7 @@ async def aindex(
For the time being, documents are indexed using their hashes, and users
are not able to specify the uid of the document.
IMPORTANT:
Important:
* In full mode, the loader should be returning
the entire dataset, and not just a subset of the dataset.
Otherwise, the auto_cleanup will remove documents that it is not
Expand Down Expand Up @@ -614,7 +614,6 @@ async def aindex(
* Added `scoped_full` cleanup mode.
"""

if cleanup not in {"incremental", "full", "scoped_full", None}:
msg = (
f"cleanup should be one of 'incremental', 'full', 'scoped_full' or None. "
Expand Down
1 change: 0 additions & 1 deletion libs/core/langchain_core/indexing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ def update(
ids.
ValueError: If time_at_least is in the future.
"""

if group_ids and len(keys) != len(group_ids):
msg = "Length of keys must match length of group_ids"
raise ValueError(msg)
Expand Down
7 changes: 2 additions & 5 deletions libs/core/langchain_core/language_models/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def generate_from_stream(stream: Iterator[ChatGenerationChunk]) -> ChatResult:
Returns:
ChatResult: Chat result.
"""

generation = next(stream, None)
if generation:
generation += list(stream)
Expand Down Expand Up @@ -112,7 +111,6 @@ async def agenerate_from_stream(
Returns:
ChatResult: Chat result.
"""

chunks = [chunk async for chunk in stream]
return await run_in_executor(None, generate_from_stream, iter(chunks))

Expand Down Expand Up @@ -521,7 +519,6 @@ def _get_ls_params(
**kwargs: Any,
) -> LangSmithParams:
"""Get standard params for tracing."""

# get default provider from class name
default_provider = self.__class__.__name__
if default_provider.startswith("Chat"):
Expand Down Expand Up @@ -955,7 +952,7 @@ def _generate(
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> ChatResult:
"""Top Level call"""
"""Top Level call."""

async def _agenerate(
self,
Expand All @@ -964,7 +961,7 @@ async def _agenerate(
run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> ChatResult:
"""Top Level call"""
"""Top Level call."""
return await run_in_executor(
None,
self._generate,
Expand Down
4 changes: 2 additions & 2 deletions libs/core/langchain_core/language_models/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _call(
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> str:
"""Return next response"""
"""Return next response."""
response = self.responses[self.i]
if self.i < len(self.responses) - 1:
self.i += 1
Expand All @@ -57,7 +57,7 @@ async def _acall(
run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> str:
"""Return next response"""
"""Return next response."""
response = self.responses[self.i]
if self.i < len(self.responses) - 1:
self.i += 1
Expand Down
4 changes: 2 additions & 2 deletions libs/core/langchain_core/language_models/fake_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def _generate(
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> ChatResult:
"""Top Level call"""
"""Top Level call."""
message = next(self.messages)
message_ = AIMessage(content=message) if isinstance(message, str) else message
generation = ChatGeneration(message=message_)
Expand Down Expand Up @@ -342,7 +342,7 @@ def _generate(
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> ChatResult:
"""Top Level call"""
"""Top Level call."""
return ChatResult(generations=[ChatGeneration(message=messages[-1])])

@property
Expand Down
Loading

0 comments on commit 0a035e3

Please sign in to comment.