Skip to content

Commit ee4d84d

Browse files
authored
style(core): typo/docs lint pass (#33093)
1 parent 092dd5e commit ee4d84d

File tree

19 files changed

+387
-341
lines changed

19 files changed

+387
-341
lines changed

docs/docs/how_to/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ See [supported integrations](/docs/integrations/chat/) for details on getting st
7272

7373
### Example selectors
7474

75-
[Example Selectors](/docs/concepts/example_selectors) are responsible for selecting the correct few shot examples to pass to the prompt.
75+
[Example Selectors](/docs/concepts/example_selectors) are responsible for selecting the correct few-shot examples to pass to the prompt.
7676

7777
- [How to: use example selectors](/docs/how_to/example_selectors)
7878
- [How to: select examples by length](/docs/how_to/example_selectors_length_based)
@@ -168,7 +168,7 @@ See [supported integrations](/docs/integrations/vectorstores/) for details on ge
168168

169169
Indexing is the process of keeping your vectorstore in-sync with the underlying data source.
170170

171-
- [How to: reindex data to keep your vectorstore in sync with the underlying data source](/docs/how_to/indexing)
171+
- [How to: reindex data to keep your vectorstore in-sync with the underlying data source](/docs/how_to/indexing)
172172

173173
### Tools
174174

libs/core/langchain_core/language_models/chat_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def stream(
471471
**kwargs: Any,
472472
) -> Iterator[BaseMessageChunk]:
473473
if not self._should_stream(async_api=False, **{**kwargs, "stream": True}):
474-
# model doesn't implement streaming, so use default implementation
474+
# Model doesn't implement streaming, so use default implementation
475475
yield cast(
476476
"BaseMessageChunk",
477477
self.invoke(input, config=config, stop=stop, **kwargs),

libs/core/langchain_core/language_models/fake_chat_models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
class FakeMessagesListChatModel(BaseChatModel):
22-
"""Fake ChatModel for testing purposes."""
22+
"""Fake ``ChatModel`` for testing purposes."""
2323

2424
responses: list[BaseMessage]
2525
"""List of responses to **cycle** through in order."""
@@ -212,10 +212,11 @@ class GenericFakeChatModel(BaseChatModel):
212212
"""Generic fake chat model that can be used to test the chat model interface.
213213
214214
* Chat model should be usable in both sync and async tests
215-
* Invokes on_llm_new_token to allow for testing of callback related code for new
215+
* Invokes ``on_llm_new_token`` to allow for testing of callback related code for new
216216
tokens.
217217
* Includes logic to break messages into message chunk to facilitate testing of
218218
streaming.
219+
219220
"""
220221

221222
messages: Iterator[Union[AIMessage, str]]
@@ -230,6 +231,7 @@ class GenericFakeChatModel(BaseChatModel):
230231
.. warning::
231232
Streaming is not implemented yet. We should try to implement it in the future by
232233
delegating to invoke and then breaking the resulting output into message chunks.
234+
233235
"""
234236

235237
@override
@@ -351,6 +353,7 @@ class ParrotFakeChatModel(BaseChatModel):
351353
"""Generic fake chat model that can be used to test the chat model interface.
352354
353355
* Chat model should be usable in both sync and async tests
356+
354357
"""
355358

356359
@override

libs/core/langchain_core/messages/ai.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class InputTokenDetails(TypedDict, total=False):
4545
Does *not* need to sum to full input token count. Does *not* need to have all keys.
4646
4747
Example:
48-
4948
.. code-block:: python
5049
5150
{
@@ -72,6 +71,7 @@ class InputTokenDetails(TypedDict, total=False):
7271
7372
Since there was a cache hit, the tokens were read from the cache. More precisely,
7473
the model state given these tokens was read from the cache.
74+
7575
"""
7676

7777

@@ -81,7 +81,6 @@ class OutputTokenDetails(TypedDict, total=False):
8181
Does *not* need to sum to full output token count. Does *not* need to have all keys.
8282
8383
Example:
84-
8584
.. code-block:: python
8685
8786
{
@@ -100,6 +99,7 @@ class OutputTokenDetails(TypedDict, total=False):
10099
101100
Tokens generated by the model in a chain of thought process (i.e. by OpenAI's o1
102101
models) that are not returned as part of model output.
102+
103103
"""
104104

105105

@@ -109,7 +109,6 @@ class UsageMetadata(TypedDict):
109109
This is a standard representation of token usage that is consistent across models.
110110
111111
Example:
112-
113112
.. code-block:: python
114113
115114
{
@@ -148,6 +147,7 @@ class UsageMetadata(TypedDict):
148147
"""Breakdown of output token counts.
149148
150149
Does *not* need to sum to full output token count. Does *not* need to have all keys.
150+
151151
"""
152152

153153

@@ -159,12 +159,14 @@ class AIMessage(BaseMessage):
159159
This message represents the output of the model and consists of both
160160
the raw output as returned by the model together standardized fields
161161
(e.g., tool calls, usage metadata) added by the LangChain framework.
162+
162163
"""
163164

164165
example: bool = False
165166
"""Use to denote that a message is part of an example conversation.
166167
167168
At the moment, this is ignored by most models. Usage is discouraged.
169+
168170
"""
169171

170172
tool_calls: list[ToolCall] = []
@@ -175,15 +177,18 @@ class AIMessage(BaseMessage):
175177
"""If provided, usage metadata for a message, such as token counts.
176178
177179
This is a standard representation of token usage that is consistent across models.
180+
178181
"""
179182

180183
type: Literal["ai"] = "ai"
181-
"""The type of the message (used for deserialization). Defaults to "ai"."""
184+
"""The type of the message (used for deserialization). Defaults to ``'ai'``."""
182185

183186
def __init__(
184-
self, content: Union[str, list[Union[str, dict]]], **kwargs: Any
187+
self,
188+
content: Union[str, list[Union[str, dict]]],
189+
**kwargs: Any,
185190
) -> None:
186-
"""Pass in content as positional arg.
191+
"""Initialize ``AIMessage``.
187192
188193
Args:
189194
content: The content of the message.
@@ -254,6 +259,7 @@ def pretty_repr(self, html: bool = False) -> str:
254259
255260
Returns:
256261
A pretty representation of the message.
262+
257263
"""
258264
base = super().pretty_repr(html=html)
259265
lines = []
@@ -293,7 +299,10 @@ class AIMessageChunk(AIMessage, BaseMessageChunk):
293299
# non-chunk variant.
294300
type: Literal["AIMessageChunk"] = "AIMessageChunk" # type: ignore[assignment]
295301
"""The type of the message (used for deserialization).
296-
Defaults to "AIMessageChunk"."""
302+
303+
Defaults to ``AIMessageChunk``.
304+
305+
"""
297306

298307
tool_call_chunks: list[ToolCallChunk] = []
299308
"""If provided, tool call chunks associated with the message."""
@@ -311,7 +320,10 @@ def init_tool_calls(self) -> Self:
311320
"""Initialize tool calls from tool call chunks.
312321
313322
Returns:
314-
This ``AIMessageChunk``.
323+
The values with tool calls initialized.
324+
325+
Raises:
326+
ValueError: If the tool call chunks are malformed.
315327
"""
316328
if not self.tool_call_chunks:
317329
if self.tool_calls:
@@ -522,9 +534,9 @@ def add_usage(
522534
def subtract_usage(
523535
left: Optional[UsageMetadata], right: Optional[UsageMetadata]
524536
) -> UsageMetadata:
525-
"""Recursively subtract two UsageMetadata objects.
537+
"""Recursively subtract two ``UsageMetadata`` objects.
526538
527-
Token counts cannot be negative so the actual operation is max(left - right, 0).
539+
Token counts cannot be negative so the actual operation is ``max(left - right, 0)``.
528540
529541
Example:
530542
.. code-block:: python

libs/core/langchain_core/messages/base.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class BaseMessage(Serializable):
2121
"""Base abstract message class.
2222
23-
Messages are the inputs and outputs of ChatModels.
23+
Messages are the inputs and outputs of ``ChatModel``s.
2424
"""
2525

2626
content: Union[str, list[Union[str, dict]]]
@@ -31,17 +31,18 @@ class BaseMessage(Serializable):
3131
3232
For example, for a message from an AI, this could include tool calls as
3333
encoded by the model provider.
34+
3435
"""
3536

3637
response_metadata: dict = Field(default_factory=dict)
37-
"""Response metadata. For example: response headers, logprobs, token counts, model
38-
name."""
38+
"""Examples: response headers, logprobs, token counts, model name."""
3939

4040
type: str
4141
"""The type of the message. Must be a string that is unique to the message type.
4242
4343
The purpose of this field is to allow for easy identification of the message type
4444
when deserializing messages.
45+
4546
"""
4647

4748
name: Optional[str] = None
@@ -51,20 +52,26 @@ class BaseMessage(Serializable):
5152
5253
Usage of this field is optional, and whether it's used or not is up to the
5354
model implementation.
55+
5456
"""
5557

5658
id: Optional[str] = Field(default=None, coerce_numbers_to_str=True)
57-
"""An optional unique identifier for the message. This should ideally be
58-
provided by the provider/model which created the message."""
59+
"""An optional unique identifier for the message.
60+
61+
This should ideally be provided by the provider/model which created the message.
62+
63+
"""
5964

6065
model_config = ConfigDict(
6166
extra="allow",
6267
)
6368

6469
def __init__(
65-
self, content: Union[str, list[Union[str, dict]]], **kwargs: Any
70+
self,
71+
content: Union[str, list[Union[str, dict]]],
72+
**kwargs: Any,
6673
) -> None:
67-
"""Pass in content as positional arg.
74+
"""Initialize ``BaseMessage``.
6875
6976
Args:
7077
content: The string contents of the message.
@@ -73,7 +80,7 @@ def __init__(
7380

7481
@classmethod
7582
def is_lc_serializable(cls) -> bool:
76-
"""BaseMessage is serializable.
83+
"""``BaseMessage`` is serializable.
7784
7885
Returns:
7986
True
@@ -90,10 +97,11 @@ def get_lc_namespace(cls) -> list[str]:
9097
return ["langchain", "schema", "messages"]
9198

9299
def text(self) -> str:
93-
"""Get the text content of the message.
100+
"""Get the text ``content`` of the message.
94101
95102
Returns:
96103
The text content of the message.
104+
97105
"""
98106
if isinstance(self.content, str):
99107
return self.content
@@ -136,6 +144,7 @@ def pretty_repr(
136144
137145
Returns:
138146
A pretty representation of the message.
147+
139148
"""
140149
title = get_msg_title_repr(self.type.title() + " Message", bold=html)
141150
# TODO: handle non-string content.
@@ -155,11 +164,12 @@ def merge_content(
155164
"""Merge multiple message contents.
156165
157166
Args:
158-
first_content: The first content. Can be a string or a list.
159-
contents: The other contents. Can be a string or a list.
167+
first_content: The first ``content``. Can be a string or a list.
168+
contents: The other ``content``s. Can be a string or a list.
160169
161170
Returns:
162171
The merged content.
172+
163173
"""
164174
merged = first_content
165175
for content in contents:
@@ -207,9 +217,10 @@ def __add__(self, other: Any) -> BaseMessageChunk: # type: ignore[override]
207217
208218
For example,
209219
210-
`AIMessageChunk(content="Hello") + AIMessageChunk(content=" World")`
220+
``AIMessageChunk(content="Hello") + AIMessageChunk(content=" World")``
221+
222+
will give ``AIMessageChunk(content="Hello World")``
211223
212-
will give `AIMessageChunk(content="Hello World")`
213224
"""
214225
if isinstance(other, BaseMessageChunk):
215226
# If both are (subclasses of) BaseMessageChunk,
@@ -257,8 +268,9 @@ def message_to_dict(message: BaseMessage) -> dict:
257268
message: Message to convert.
258269
259270
Returns:
260-
Message as a dict. The dict will have a "type" key with the message type
261-
and a "data" key with the message data as a dict.
271+
Message as a dict. The dict will have a ``type`` key with the message type
272+
and a ``data`` key with the message data as a dict.
273+
262274
"""
263275
return {"type": message.type, "data": message.model_dump()}
264276

@@ -267,10 +279,11 @@ def messages_to_dict(messages: Sequence[BaseMessage]) -> list[dict]:
267279
"""Convert a sequence of Messages to a list of dictionaries.
268280
269281
Args:
270-
messages: Sequence of messages (as BaseMessages) to convert.
282+
messages: Sequence of messages (as ``BaseMessage``s) to convert.
271283
272284
Returns:
273285
List of messages as dicts.
286+
274287
"""
275288
return [message_to_dict(m) for m in messages]
276289

@@ -284,6 +297,7 @@ def get_msg_title_repr(title: str, *, bold: bool = False) -> str:
284297
285298
Returns:
286299
The title representation.
300+
287301
"""
288302
padded = " " + title + " "
289303
sep_len = (80 - len(padded)) // 2

libs/core/langchain_core/messages/chat.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ class ChatMessageChunk(ChatMessage, BaseMessageChunk):
3030
# non-chunk variant.
3131
type: Literal["ChatMessageChunk"] = "ChatMessageChunk" # type: ignore[assignment]
3232
"""The type of the message (used during serialization).
33-
Defaults to "ChatMessageChunk"."""
33+
34+
Defaults to ``'ChatMessageChunk'``.
35+
36+
"""
3437

3538
@override
3639
def __add__(self, other: Any) -> BaseMessageChunk: # type: ignore[override]

libs/core/langchain_core/messages/function.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515
class FunctionMessage(BaseMessage):
1616
"""Message for passing the result of executing a tool back to a model.
1717
18-
FunctionMessage are an older version of the ToolMessage schema, and
19-
do not contain the tool_call_id field.
18+
``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and
19+
do not contain the ``tool_call_id`` field.
2020
21-
The tool_call_id field is used to associate the tool call request with the
21+
The ``tool_call_id`` field is used to associate the tool call request with the
2222
tool call response. This is useful in situations where a chat model is able
2323
to request multiple tool calls in parallel.
24+
2425
"""
2526

2627
name: str
2728
"""The name of the function that was executed."""
2829

2930
type: Literal["function"] = "function"
30-
"""The type of the message (used for serialization). Defaults to "function"."""
31+
"""The type of the message (used for serialization). Defaults to ``'function'``."""
3132

3233

3334
class FunctionMessageChunk(FunctionMessage, BaseMessageChunk):
@@ -38,7 +39,10 @@ class FunctionMessageChunk(FunctionMessage, BaseMessageChunk):
3839
# non-chunk variant.
3940
type: Literal["FunctionMessageChunk"] = "FunctionMessageChunk" # type: ignore[assignment]
4041
"""The type of the message (used for serialization).
41-
Defaults to "FunctionMessageChunk"."""
42+
43+
Defaults to ``'FunctionMessageChunk'``.
44+
45+
"""
4246

4347
@override
4448
def __add__(self, other: Any) -> BaseMessageChunk: # type: ignore[override]

0 commit comments

Comments
 (0)