Skip to content

Commit a07f8b5

Browse files
authored
add all models as fallbacks (langchain-ai#290)
1 parent 6296d0a commit a07f8b5

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

‎backend/chain.py‎

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -236,39 +236,42 @@ def cohere_response_synthesizer(input: dict) -> RunnableSequence:
236236
)
237237

238238

239-
llm = ChatOpenAI(
240-
model="gpt-3.5-turbo-0125",
239+
gpt_3_5 = ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0, streaming=True)
240+
claude_3_sonnet = ChatAnthropic(
241+
model="claude-3-sonnet-20240229",
241242
temperature=0,
242-
streaming=True,
243-
).configurable_alternatives(
243+
max_tokens=4096,
244+
anthropic_api_key=os.environ.get("ANTHROPIC_API_KEY", "not_provided"),
245+
)
246+
fireworks_mixtral = ChatFireworks(
247+
model="accounts/fireworks/models/mixtral-8x7b-instruct",
248+
temperature=0,
249+
max_tokens=16384,
250+
fireworks_api_key=os.environ.get("FIREWORKS_API_KEY", "not_provided"),
251+
)
252+
gemini_pro = ChatGoogleGenerativeAI(
253+
model="gemini-pro",
254+
temperature=0,
255+
max_tokens=16384,
256+
convert_system_message_to_human=True,
257+
google_api_key=os.environ.get("GOOGLE_API_KEY", "not_provided"),
258+
)
259+
cohere_command = ChatCohere(
260+
model="command",
261+
temperature=0,
262+
cohere_api_key=os.environ.get("COHERE_API_KEY", "not_provided"),
263+
)
264+
llm = gpt_3_5.configurable_alternatives(
244265
# This gives this field an id
245266
# When configuring the end runnable, we can then use this id to configure this field
246267
ConfigurableField(id="llm"),
247268
default_key="openai_gpt_3_5_turbo",
248-
anthropic_claude_3_sonnet=ChatAnthropic(
249-
model="claude-3-sonnet-20240229",
250-
temperature=0,
251-
max_tokens=4096,
252-
anthropic_api_key=os.environ.get("ANTHROPIC_API_KEY", "not_provided"),
253-
),
254-
fireworks_mixtral=ChatFireworks(
255-
model="accounts/fireworks/models/mixtral-8x7b-instruct",
256-
temperature=0,
257-
max_tokens=16384,
258-
fireworks_api_key=os.environ.get("FIREWORKS_API_KEY", "not_provided"),
259-
),
260-
google_gemini_pro=ChatGoogleGenerativeAI(
261-
model="gemini-pro",
262-
temperature=0,
263-
max_tokens=16384,
264-
convert_system_message_to_human=True,
265-
google_api_key=os.environ.get("GOOGLE_API_KEY", "not_provided"),
266-
),
267-
cohere_command=ChatCohere(
268-
model="command",
269-
temperature=0,
270-
cohere_api_key=os.environ.get("COHERE_API_KEY", "not_provided"),
271-
),
269+
anthropic_claude_3_sonnet=claude_3_sonnet,
270+
fireworks_mixtral=fireworks_mixtral,
271+
google_gemini_pro=gemini_pro,
272+
cohere_command=cohere_command,
273+
).with_fallbacks(
274+
[gpt_3_5, claude_3_sonnet, fireworks_mixtral, gemini_pro, cohere_command]
272275
)
273276

274277
retriever = get_retriever()

0 commit comments

Comments
 (0)