Skip to content

Commit f2dab56

Browse files
authored
style: misc refs work (#33771)
1 parent 61196a8 commit f2dab56

File tree

9 files changed

+71
-63
lines changed

9 files changed

+71
-63
lines changed

libs/core/langchain_core/agents.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ class AgentActionMessageLog(AgentAction):
118118

119119

120120
class AgentStep(Serializable):
121-
"""Result of running an AgentAction."""
121+
"""Result of running an `AgentAction`."""
122122

123123
action: AgentAction
124-
"""The AgentAction that was executed."""
124+
"""The `AgentAction` that was executed."""
125125
observation: Any
126-
"""The result of the AgentAction."""
126+
"""The result of the `AgentAction`."""
127127

128128
@property
129129
def messages(self) -> Sequence[BaseMessage]:

libs/core/langchain_core/exceptions.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ class OutputParserException(ValueError, LangChainException): # noqa: N818
1616
"""Exception that output parsers should raise to signify a parsing error.
1717
1818
This exists to differentiate parsing errors from other code or execution errors
19-
that also may arise inside the output parser. `OutputParserException` will be
20-
available to catch and handle in ways to fix the parsing error, while other
21-
errors will be raised.
19+
that also may arise inside the output parser.
20+
21+
`OutputParserException` will be available to catch and handle in ways to fix the
22+
parsing error, while other errors will be raised.
2223
"""
2324

2425
def __init__(
@@ -32,18 +33,19 @@ def __init__(
3233
3334
Args:
3435
error: The error that's being re-raised or an error message.
35-
observation: String explanation of error which can be passed to a
36-
model to try and remediate the issue.
36+
observation: String explanation of error which can be passed to a model to
37+
try and remediate the issue.
3738
llm_output: String model output which is error-ing.
3839
3940
send_to_llm: Whether to send the observation and llm_output back to an Agent
4041
after an `OutputParserException` has been raised.
42+
4143
This gives the underlying model driving the agent the context that the
4244
previous output was improperly structured, in the hopes that it will
4345
update the output to the correct format.
4446
4547
Raises:
46-
ValueError: If `send_to_llm` is True but either observation or
48+
ValueError: If `send_to_llm` is `True` but either observation or
4749
`llm_output` are not provided.
4850
"""
4951
if isinstance(error, str):
@@ -66,11 +68,11 @@ class ErrorCode(Enum):
6668
"""Error codes."""
6769

6870
INVALID_PROMPT_INPUT = "INVALID_PROMPT_INPUT"
69-
INVALID_TOOL_RESULTS = "INVALID_TOOL_RESULTS"
71+
INVALID_TOOL_RESULTS = "INVALID_TOOL_RESULTS" # Used in JS; not Py (yet)
7072
MESSAGE_COERCION_FAILURE = "MESSAGE_COERCION_FAILURE"
71-
MODEL_AUTHENTICATION = "MODEL_AUTHENTICATION"
72-
MODEL_NOT_FOUND = "MODEL_NOT_FOUND"
73-
MODEL_RATE_LIMIT = "MODEL_RATE_LIMIT"
73+
MODEL_AUTHENTICATION = "MODEL_AUTHENTICATION" # Used in JS; not Py (yet)
74+
MODEL_NOT_FOUND = "MODEL_NOT_FOUND" # Used in JS; not Py (yet)
75+
MODEL_RATE_LIMIT = "MODEL_RATE_LIMIT" # Used in JS; not Py (yet)
7476
OUTPUT_PARSING_FAILURE = "OUTPUT_PARSING_FAILURE"
7577

7678

libs/core/langchain_core/vectorstores/base.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ def add_documents(self, documents: list[Document], **kwargs: Any) -> list[str]:
237237
Args:
238238
documents: Documents to add to the `VectorStore`.
239239
**kwargs: Additional keyword arguments.
240-
if kwargs contains IDs and documents contain ids,
241-
the IDs in the kwargs will receive precedence.
240+
241+
If kwargs contains IDs and documents contain ids, the IDs in the kwargs
242+
will receive precedence.
242243
243244
Returns:
244245
List of IDs of the added texts.
@@ -421,7 +422,7 @@ def similarity_search_with_score(
421422
**kwargs: Arguments to pass to the search method.
422423
423424
Returns:
424-
List of Tuples of `(doc, similarity_score)`.
425+
List of tuples of `(doc, similarity_score)`.
425426
"""
426427
raise NotImplementedError
427428

@@ -435,7 +436,7 @@ async def asimilarity_search_with_score(
435436
**kwargs: Arguments to pass to the search method.
436437
437438
Returns:
438-
List of Tuples of `(doc, similarity_score)`.
439+
List of tuples of `(doc, similarity_score)`.
439440
"""
440441
# This is a temporary workaround to make the similarity search
441442
# asynchronous. The proper solution is to make the similarity search
@@ -465,7 +466,7 @@ def _similarity_search_with_relevance_scores(
465466
to filter the resulting set of retrieved docs
466467
467468
Returns:
468-
List of Tuples of `(doc, similarity_score)`
469+
List of tuples of `(doc, similarity_score)`
469470
"""
470471
relevance_score_fn = self._select_relevance_score_fn()
471472
docs_and_scores = self.similarity_search_with_score(query, k, **kwargs)
@@ -492,7 +493,7 @@ async def _asimilarity_search_with_relevance_scores(
492493
to filter the resulting set of retrieved docs
493494
494495
Returns:
495-
List of Tuples of `(doc, similarity_score)`
496+
List of tuples of `(doc, similarity_score)`
496497
"""
497498
relevance_score_fn = self._select_relevance_score_fn()
498499
docs_and_scores = await self.asimilarity_search_with_score(query, k, **kwargs)
@@ -516,7 +517,7 @@ def similarity_search_with_relevance_scores(
516517
to filter the resulting set of retrieved docs
517518
518519
Returns:
519-
List of Tuples of `(doc, similarity_score)`.
520+
List of tuples of `(doc, similarity_score)`.
520521
"""
521522
score_threshold = kwargs.pop("score_threshold", None)
522523

@@ -565,7 +566,7 @@ async def asimilarity_search_with_relevance_scores(
565566
to filter the resulting set of retrieved docs
566567
567568
Returns:
568-
List of Tuples of `(doc, similarity_score)`
569+
List of tuples of `(doc, similarity_score)`
569570
"""
570571
score_threshold = kwargs.pop("score_threshold", None)
571572

@@ -667,7 +668,7 @@ def max_marginal_relevance_search(
667668
k: Number of `Document` objects to return.
668669
fetch_k: Number of `Document` objects to fetch to pass to MMR algorithm.
669670
lambda_mult: Number between `0` and `1` that determines the degree
670-
of diversity among the results with 0 corresponding
671+
of diversity among the results with `0` corresponding
671672
to maximum diversity and `1` to minimum diversity.
672673
**kwargs: Arguments to pass to the search method.
673674
@@ -694,7 +695,7 @@ async def amax_marginal_relevance_search(
694695
k: Number of `Document` objects to return.
695696
fetch_k: Number of `Document` objects to fetch to pass to MMR algorithm.
696697
lambda_mult: Number between `0` and `1` that determines the degree
697-
of diversity among the results with 0 corresponding
698+
of diversity among the results with `0` corresponding
698699
to maximum diversity and `1` to minimum diversity.
699700
**kwargs: Arguments to pass to the search method.
700701
@@ -732,7 +733,7 @@ def max_marginal_relevance_search_by_vector(
732733
k: Number of `Document` objects to return.
733734
fetch_k: Number of `Document` objects to fetch to pass to MMR algorithm.
734735
lambda_mult: Number between `0` and `1` that determines the degree
735-
of diversity among the results with 0 corresponding
736+
of diversity among the results with `0` corresponding
736737
to maximum diversity and `1` to minimum diversity.
737738
**kwargs: Arguments to pass to the search method.
738739
@@ -759,7 +760,7 @@ async def amax_marginal_relevance_search_by_vector(
759760
k: Number of `Document` objects to return.
760761
fetch_k: Number of `Document` objects to fetch to pass to MMR algorithm.
761762
lambda_mult: Number between `0` and `1` that determines the degree
762-
of diversity among the results with 0 corresponding
763+
of diversity among the results with `0` corresponding
763764
to maximum diversity and `1` to minimum diversity.
764765
**kwargs: Arguments to pass to the search method.
765766

libs/langchain/langchain_classic/agents/agent.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ class RunnableAgent(BaseSingleActionAgent):
403403
"""Whether to stream from the runnable or not.
404404
405405
If `True` then underlying LLM is invoked in a streaming fashion to make it possible
406-
to get access to the individual LLM tokens when using stream_log with the Agent
407-
Executor. If `False` then LLM is invoked in a non-streaming fashion and
406+
to get access to the individual LLM tokens when using stream_log with the
407+
`AgentExecutor`. If `False` then LLM is invoked in a non-streaming fashion and
408408
individual LLM tokens will not be available in stream_log.
409409
"""
410410

@@ -445,7 +445,7 @@ def plan(
445445
# Use streaming to make sure that the underlying LLM is invoked in a
446446
# streaming
447447
# fashion to make it possible to get access to the individual LLM tokens
448-
# when using stream_log with the Agent Executor.
448+
# when using stream_log with the AgentExecutor.
449449
# Because the response from the plan is not a generator, we need to
450450
# accumulate the output into final output and return that.
451451
for chunk in self.runnable.stream(inputs, config={"callbacks": callbacks}):
@@ -481,7 +481,7 @@ async def aplan(
481481
# Use streaming to make sure that the underlying LLM is invoked in a
482482
# streaming
483483
# fashion to make it possible to get access to the individual LLM tokens
484-
# when using stream_log with the Agent Executor.
484+
# when using stream_log with the AgentExecutor.
485485
# Because the response from the plan is not a generator, we need to
486486
# accumulate the output into final output and return that.
487487
async for chunk in self.runnable.astream(
@@ -511,8 +511,8 @@ class RunnableMultiActionAgent(BaseMultiActionAgent):
511511
"""Whether to stream from the runnable or not.
512512
513513
If `True` then underlying LLM is invoked in a streaming fashion to make it possible
514-
to get access to the individual LLM tokens when using stream_log with the Agent
515-
Executor. If `False` then LLM is invoked in a non-streaming fashion and
514+
to get access to the individual LLM tokens when using stream_log with the
515+
`AgentExecutor`. If `False` then LLM is invoked in a non-streaming fashion and
516516
individual LLM tokens will not be available in stream_log.
517517
"""
518518

@@ -557,7 +557,7 @@ def plan(
557557
# Use streaming to make sure that the underlying LLM is invoked in a
558558
# streaming
559559
# fashion to make it possible to get access to the individual LLM tokens
560-
# when using stream_log with the Agent Executor.
560+
# when using stream_log with the AgentExecutor.
561561
# Because the response from the plan is not a generator, we need to
562562
# accumulate the output into final output and return that.
563563
for chunk in self.runnable.stream(inputs, config={"callbacks": callbacks}):
@@ -593,7 +593,7 @@ async def aplan(
593593
# Use streaming to make sure that the underlying LLM is invoked in a
594594
# streaming
595595
# fashion to make it possible to get access to the individual LLM tokens
596-
# when using stream_log with the Agent Executor.
596+
# when using stream_log with the AgentExecutor.
597597
# Because the response from the plan is not a generator, we need to
598598
# accumulate the output into final output and return that.
599599
async for chunk in self.runnable.astream(

libs/langchain/langchain_classic/agents/agent_iterator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def __init__(
5353
include_run_info: bool = False,
5454
yield_actions: bool = False,
5555
):
56-
"""Initialize the AgentExecutorIterator.
56+
"""Initialize the `AgentExecutorIterator`.
5757
58-
Initialize the AgentExecutorIterator with the given AgentExecutor,
58+
Initialize the `AgentExecutorIterator` with the given `AgentExecutor`,
5959
inputs, and optional callbacks.
6060
6161
Args:
@@ -91,7 +91,7 @@ def __init__(
9191

9292
@property
9393
def inputs(self) -> dict[str, str]:
94-
"""The inputs to the AgentExecutor."""
94+
"""The inputs to the `AgentExecutor`."""
9595
return self._inputs
9696

9797
@inputs.setter
@@ -100,7 +100,7 @@ def inputs(self, inputs: Any) -> None:
100100

101101
@property
102102
def agent_executor(self) -> AgentExecutor:
103-
"""The AgentExecutor to iterate over."""
103+
"""The `AgentExecutor` to iterate over."""
104104
return self._agent_executor
105105

106106
@agent_executor.setter
@@ -171,7 +171,7 @@ def make_final_outputs(
171171
return prepared_outputs
172172

173173
def __iter__(self: AgentExecutorIterator) -> Iterator[AddableDict]:
174-
"""Create an async iterator for the AgentExecutor."""
174+
"""Create an async iterator for the `AgentExecutor`."""
175175
logger.debug("Initialising AgentExecutorIterator")
176176
self.reset()
177177
callback_manager = CallbackManager.configure(
@@ -235,7 +235,7 @@ def __iter__(self: AgentExecutorIterator) -> Iterator[AddableDict]:
235235
yield self._stop(run_manager)
236236

237237
async def __aiter__(self) -> AsyncIterator[AddableDict]:
238-
"""Create an async iterator for the AgentExecutor.
238+
"""Create an async iterator for the `AgentExecutor`.
239239
240240
N.B. __aiter__ must be a normal method, so need to initialize async run manager
241241
on first __anext__ call where we can await it.

libs/langchain/langchain_classic/agents/openai_assistant/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ def execute_agent(agent, tools, input):
231231
"""
232232

233233
client: Any = Field(default_factory=_get_openai_client)
234-
"""OpenAI or AzureOpenAI client."""
234+
"""`OpenAI` or `AzureOpenAI` client."""
235235
async_client: Any = None
236-
"""OpenAI or AzureOpenAI async client."""
236+
"""`OpenAI` or `AzureOpenAI` async client."""
237237
assistant_id: str
238238
"""OpenAI assistant id."""
239239
check_every_ms: float = 1_000.0
240240
"""Frequency with which to check run progress in ms."""
241241
as_agent: bool = False
242-
"""Use as a LangChain agent, compatible with the AgentExecutor."""
242+
"""Use as a LangChain agent, compatible with the `AgentExecutor`."""
243243

244244
@model_validator(mode="after")
245245
def _validate_async_client(self) -> Self:

libs/partners/nomic/langchain_nomic/embeddings.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class NomicEmbeddings(Embeddings):
14-
"""NomicEmbeddings embedding model.
14+
"""`NomicEmbeddings` embedding model.
1515
1616
Example:
1717
```python
@@ -66,8 +66,8 @@ def __init__(
6666
"""Initialize `NomicEmbeddings` model.
6767
6868
Args:
69-
model: model name
70-
nomic_api_key: optionally, set the Nomic API key. Uses the `NOMIC_API_KEY`
69+
model: Model name
70+
nomic_api_key: Optionally, set the Nomic API key. Uses the `NOMIC_API_KEY`
7171
environment variable by default.
7272
dimensionality: The embedding dimension, for use with Matryoshka-capable
7373
models. Defaults to full-size.
@@ -76,7 +76,12 @@ def __init__(
7676
device: The device to use for local embeddings. Choices include
7777
`'cpu'`, `'gpu'`, `'nvidia'`, `'amd'`, or a specific device
7878
name. See the docstring for `GPT4All.__init__` for more info.
79-
Typically defaults to `'cpu'`. Do not use on macOS.
79+
80+
Typically defaults to `'cpu'`.
81+
82+
!!! warning
83+
84+
Do not use on macOS.
8085
vision_model: The vision model to use for image embeddings.
8186
8287
"""
@@ -93,8 +98,8 @@ def embed(self, texts: list[str], *, task_type: str) -> list[list[float]]:
9398
"""Embed texts.
9499
95100
Args:
96-
texts: list of texts to embed
97-
task_type: the task type to use when embedding. One of `'search_query'`,
101+
texts: List of texts to embed
102+
task_type: The task type to use when embedding. One of `'search_query'`,
98103
`'search_document'`, `'classification'`, `'clustering'`
99104
100105
"""
@@ -112,7 +117,7 @@ def embed_documents(self, texts: list[str]) -> list[list[float]]:
112117
"""Embed search docs.
113118
114119
Args:
115-
texts: list of texts to embed as documents
120+
texts: List of texts to embed as documents
116121
117122
"""
118123
return self.embed(
@@ -124,7 +129,7 @@ def embed_query(self, text: str) -> list[float]:
124129
"""Embed query text.
125130
126131
Args:
127-
text: query text
132+
text: Query text
128133
129134
"""
130135
return self.embed(
@@ -136,7 +141,7 @@ def embed_image(self, uris: list[str]) -> list[list[float]]:
136141
"""Embed images.
137142
138143
Args:
139-
uris: list of image URIs to embed
144+
uris: List of image URIs to embed
140145
"""
141146
return embed.image(
142147
images=uris,

libs/partners/ollama/tests/integration_tests/chat_models/test_chat_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_init_model_not_found(mock_list: MagicMock) -> None:
4040

4141
@patch("langchain_ollama.chat_models.Client.list")
4242
def test_init_connection_error(mock_list: MagicMock) -> None:
43-
"""Test that a ValidationError is raised on connect failure during init."""
43+
"""Test that a `ValidationError` is raised on connect failure during init."""
4444
mock_list.side_effect = ConnectError("Test connection error")
4545

4646
with pytest.raises(ValidationError) as excinfo:

0 commit comments

Comments
 (0)