From a983465694c79010f529488112549696ccfff396 Mon Sep 17 00:00:00 2001 From: ccurme Date: Tue, 21 May 2024 11:01:18 -0700 Subject: [PATCH] docs: set default anthropic model (#21988) `ChatAnthropic()` raises ValidationError. --- docs/docs/how_to/fallbacks.ipynb | 4 ++-- libs/core/langchain_core/prompts/few_shot.py | 2 +- libs/core/langchain_core/runnables/fallbacks.py | 4 +++- libs/langchain/langchain/agents/self_ask_with_search/base.py | 2 +- libs/langchain/langchain/agents/xml/base.py | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/docs/how_to/fallbacks.ipynb b/docs/docs/how_to/fallbacks.ipynb index 8f8117d76cd..bdb234c83cc 100644 --- a/docs/docs/how_to/fallbacks.ipynb +++ b/docs/docs/how_to/fallbacks.ipynb @@ -90,8 +90,8 @@ "outputs": [], "source": [ "# Note that we set max_retries = 0 to avoid retrying on RateLimits, etc\n", - "openai_llm = ChatOpenAI(max_retries=0)\n", - "anthropic_llm = ChatAnthropic()\n", + "openai_llm = ChatOpenAI(model=\"gpt-3.5-turbo-0125\", max_retries=0)\n", + "anthropic_llm = ChatAnthropic(model=\"claude-3-haiku-20240307\")\n", "llm = openai_llm.with_fallbacks([anthropic_llm])" ] }, diff --git a/libs/core/langchain_core/prompts/few_shot.py b/libs/core/langchain_core/prompts/few_shot.py index bf0d55f84e7..2fbc7d7a46e 100644 --- a/libs/core/langchain_core/prompts/few_shot.py +++ b/libs/core/langchain_core/prompts/few_shot.py @@ -305,7 +305,7 @@ class FewShotChatMessagePromptTemplate( # Use within an LLM from langchain_core.chat_models import ChatAnthropic - chain = final_prompt | ChatAnthropic() + chain = final_prompt | ChatAnthropic(model="claude-3-haiku-20240307") chain.invoke({"input": "What's 3+3?"}) """ diff --git a/libs/core/langchain_core/runnables/fallbacks.py b/libs/core/langchain_core/runnables/fallbacks.py index 131061e9e9f..494c27a4bcd 100644 --- a/libs/core/langchain_core/runnables/fallbacks.py +++ b/libs/core/langchain_core/runnables/fallbacks.py @@ -61,7 +61,9 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]): from langchain_core.chat_models.openai import ChatOpenAI from langchain_core.chat_models.anthropic import ChatAnthropic - model = ChatAnthropic().with_fallbacks([ChatOpenAI()]) + model = ChatAnthropic( + model="claude-3-haiku-20240307" + ).with_fallbacks([ChatOpenAI(model="gpt-3.5-turbo-0125")]) # Will usually use ChatAnthropic, but fallback to ChatOpenAI # if ChatAnthropic fails. model.invoke('hello') diff --git a/libs/langchain/langchain/agents/self_ask_with_search/base.py b/libs/langchain/langchain/agents/self_ask_with_search/base.py index d616a06de22..a930a59b4ba 100644 --- a/libs/langchain/langchain/agents/self_ask_with_search/base.py +++ b/libs/langchain/langchain/agents/self_ask_with_search/base.py @@ -117,7 +117,7 @@ def create_self_ask_with_search_agent( ) prompt = hub.pull("hwchase17/self-ask-with-search") - model = ChatAnthropic() + model = ChatAnthropic(model="claude-3-haiku-20240307") tools = [...] # Should just be one tool with name `Intermediate Answer` agent = create_self_ask_with_search_agent(model, tools, prompt) diff --git a/libs/langchain/langchain/agents/xml/base.py b/libs/langchain/langchain/agents/xml/base.py index 1fc70f50be4..2a224736e5a 100644 --- a/libs/langchain/langchain/agents/xml/base.py +++ b/libs/langchain/langchain/agents/xml/base.py @@ -147,7 +147,7 @@ def create_xml_agent( from langchain.agents import AgentExecutor, create_xml_agent prompt = hub.pull("hwchase17/xml-agent-convo") - model = ChatAnthropic() + model = ChatAnthropic(model="claude-3-haiku-20240307") tools = ... agent = create_xml_agent(model, tools, prompt)