Skip to content

Commit 40fe8d6

Browse files
yuee3ccurmeaman99dex
authored
docs(core): fix docstring examples that don't run as copied (#40815)
Co-authored-by: ccurme <[email protected]> Co-authored-by: Aman Gupta <[email protected]>
1 parent 021dce4 commit 40fe8d6

7 files changed

Lines changed: 13 additions & 15 deletions

File tree

‎libs/core/langchain_core/messages/utils.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ def trim_messages(
12891289
messages,
12901290
max_tokens=45,
12911291
strategy="last",
1292-
token_counter=ChatOpenAI(model="openai:gpt-5.5"),
1292+
token_counter=ChatOpenAI(model="gpt-5.5"),
12931293
# Most chat models expect that chat history starts with either:
12941294
# (1) a HumanMessage or
12951295
# (2) a SystemMessage followed by a HumanMessage

‎libs/core/langchain_core/output_parsers/string.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class StrOutputParser(BaseTransformOutputParser[str]):
1919
from langchain_core.output_parsers import StrOutputParser
2020
from langchain_openai import ChatOpenAI
2121
22-
model = ChatOpenAI(model="openai:gpt-5.5")
22+
model = ChatOpenAI(model="gpt-5.5")
2323
parser = StrOutputParser()
2424
2525
# Get string output from a model

‎libs/core/langchain_core/prompts/few_shot.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ class FewShotChatMessagePromptTemplate(
369369
print(final_prompt.format_messages(input="What's 3+3?")) # noqa: T201
370370
371371
# Use within an LLM
372-
from langchain_core.chat_models import ChatAnthropic
372+
from langchain_anthropic import ChatAnthropic
373373
374-
chain = final_prompt | ChatAnthropic(model="claude-3-haiku-20240307")
374+
chain = final_prompt | ChatAnthropic(model="claude-sonnet-5")
375375
chain.invoke({"input": "What's 3+3?"})
376376
```
377377
"""

‎libs/core/langchain_core/rate_limiters.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ class InMemoryRateLimiter(BaseRateLimiter):
105105
106106
from langchain_anthropic import ChatAnthropic
107107
108-
model = ChatAnthropic(
109-
model_name="claude-sonnet-4-5-20250929", rate_limiter=rate_limiter
110-
)
108+
model = ChatAnthropic(model_name="claude-sonnet-5", rate_limiter=rate_limiter)
111109
112110
for _ in range(5):
113111
tic = time.time()

‎libs/core/langchain_core/runnables/fallbacks.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
5252
5353
Example:
5454
```python
55-
from langchain_core.chat_models.openai import ChatOpenAI
56-
from langchain_core.chat_models.anthropic import ChatAnthropic
55+
from langchain_anthropic import ChatAnthropic
56+
from langchain_openai import ChatOpenAI
5757
58-
model = ChatAnthropic(model="claude-sonnet-4-6").with_fallbacks(
58+
model = ChatAnthropic(model="claude-sonnet-5").with_fallbacks(
5959
[ChatOpenAI(model="gpt-5.4-mini")]
6060
)
6161
# Will usually use ChatAnthropic, but fallback to ChatOpenAI
@@ -604,8 +604,8 @@ def __getattr__(self, name: str) -> Any:
604604
from langchain_openai import ChatOpenAI
605605
from langchain_anthropic import ChatAnthropic
606606
607-
gpt_55 = ChatOpenAI(model="openai:gpt-5.5")
608-
claude_3_sonnet = ChatAnthropic(model="claude-sonnet-4-5-20250929")
607+
gpt_55 = ChatOpenAI(model="gpt-5.5")
608+
claude_3_sonnet = ChatAnthropic(model="claude-sonnet-5")
609609
model = gpt_55.with_fallbacks([claude_3_sonnet])
610610
611611
model.model_name

‎libs/core/langchain_core/runnables/history.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def get_by_session_id(session_id: str) -> BaseChatMessageHistory:
136136
]
137137
)
138138
139-
chain = prompt | ChatAnthropic(model="claude-2")
139+
chain = prompt | ChatAnthropic(model="claude-sonnet-5")
140140
141141
chain_with_history = RunnableWithMessageHistory(
142142
chain,
@@ -189,7 +189,7 @@ def get_session_history(
189189
]
190190
)
191191
192-
chain = prompt | ChatAnthropic(model="claude-2")
192+
chain = prompt | ChatAnthropic(model="claude-sonnet-5")
193193
194194
with_message_history = RunnableWithMessageHistory(
195195
chain,

‎libs/core/langchain_core/runnables/retry.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def foo(input) -> None:
9696
9797
Example:
9898
```python
99-
from langchain_core.chat_models import ChatOpenAI
99+
from langchain_openai import ChatOpenAI
100100
from langchain_core.prompts import PromptTemplate
101101
102102
template = PromptTemplate.from_template("tell me a joke about {topic}.")

0 commit comments

Comments
 (0)