mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-05 09:25:14 +03:00
docs(core): fix docstring examples that don't run as copied (#40815)
Co-authored-by: ccurme <ccurme@users.noreply.github.com> Co-authored-by: Aman Gupta <168967382+aman99dex@users.noreply.github.com>
This commit is contained in:
7 files changed
+13
-15
No files matched your search
@@ -1289,7 +1289,7 @@ def trim_messages(
|
||||
messages,
|
||||
max_tokens=45,
|
||||
strategy="last",
|
||||
token_counter=ChatOpenAI(model="openai:gpt-5.5"),
|
||||
token_counter=ChatOpenAI(model="gpt-5.5"),
|
||||
# Most chat models expect that chat history starts with either:
|
||||
# (1) a HumanMessage or
|
||||
# (2) a SystemMessage followed by a HumanMessage
|
||||
|
||||
@@ -19,7 +19,7 @@ class StrOutputParser(BaseTransformOutputParser[str]):
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
model = ChatOpenAI(model="openai:gpt-5.5")
|
||||
model = ChatOpenAI(model="gpt-5.5")
|
||||
parser = StrOutputParser()
|
||||
|
||||
# Get string output from a model
|
||||
|
||||
@@ -369,9 +369,9 @@ class FewShotChatMessagePromptTemplate(
|
||||
print(final_prompt.format_messages(input="What's 3+3?")) # noqa: T201
|
||||
|
||||
# Use within an LLM
|
||||
from langchain_core.chat_models import ChatAnthropic
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
|
||||
chain = final_prompt | ChatAnthropic(model="claude-3-haiku-20240307")
|
||||
chain = final_prompt | ChatAnthropic(model="claude-sonnet-5")
|
||||
chain.invoke({"input": "What's 3+3?"})
|
||||
```
|
||||
"""
|
||||
|
||||
@@ -105,9 +105,7 @@ class InMemoryRateLimiter(BaseRateLimiter):
|
||||
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
|
||||
model = ChatAnthropic(
|
||||
model_name="claude-sonnet-4-5-20250929", rate_limiter=rate_limiter
|
||||
)
|
||||
model = ChatAnthropic(model_name="claude-sonnet-5", rate_limiter=rate_limiter)
|
||||
|
||||
for _ in range(5):
|
||||
tic = time.time()
|
||||
|
||||
@@ -52,10 +52,10 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
|
||||
|
||||
Example:
|
||||
```python
|
||||
from langchain_core.chat_models.openai import ChatOpenAI
|
||||
from langchain_core.chat_models.anthropic import ChatAnthropic
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
model = ChatAnthropic(model="claude-sonnet-4-6").with_fallbacks(
|
||||
model = ChatAnthropic(model="claude-sonnet-5").with_fallbacks(
|
||||
[ChatOpenAI(model="gpt-5.4-mini")]
|
||||
)
|
||||
# Will usually use ChatAnthropic, but fallback to ChatOpenAI
|
||||
@@ -604,8 +604,8 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
|
||||
from langchain_openai import ChatOpenAI
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
|
||||
gpt_55 = ChatOpenAI(model="openai:gpt-5.5")
|
||||
claude_3_sonnet = ChatAnthropic(model="claude-sonnet-4-5-20250929")
|
||||
gpt_55 = ChatOpenAI(model="gpt-5.5")
|
||||
claude_3_sonnet = ChatAnthropic(model="claude-sonnet-5")
|
||||
model = gpt_55.with_fallbacks([claude_3_sonnet])
|
||||
|
||||
model.model_name
|
||||
|
||||
@@ -136,7 +136,7 @@ class RunnableWithMessageHistory(RunnableBindingBase[Any, Any]): # type: ignore
|
||||
]
|
||||
)
|
||||
|
||||
chain = prompt | ChatAnthropic(model="claude-2")
|
||||
chain = prompt | ChatAnthropic(model="claude-sonnet-5")
|
||||
|
||||
chain_with_history = RunnableWithMessageHistory(
|
||||
chain,
|
||||
@@ -189,7 +189,7 @@ class RunnableWithMessageHistory(RunnableBindingBase[Any, Any]): # type: ignore
|
||||
]
|
||||
)
|
||||
|
||||
chain = prompt | ChatAnthropic(model="claude-2")
|
||||
chain = prompt | ChatAnthropic(model="claude-sonnet-5")
|
||||
|
||||
with_message_history = RunnableWithMessageHistory(
|
||||
chain,
|
||||
|
||||
@@ -96,7 +96,7 @@ class RunnableRetry(RunnableBindingBase[Input, Output]): # type: ignore[no-rede
|
||||
|
||||
Example:
|
||||
```python
|
||||
from langchain_core.chat_models import ChatOpenAI
|
||||
from langchain_openai import ChatOpenAI
|
||||
from langchain_core.prompts import PromptTemplate
|
||||
|
||||
template = PromptTemplate.from_template("tell me a joke about {topic}.")
|
||||
|
||||
Reference in new issue
Block a user