Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,59 @@
"print(result.final_result.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"id": "077b1f69",
"metadata": {},
"source": [
"(orchestration_fallback)=\n",
"### Using Fallback Configurations\n",
"\n",
"You can provide multiple `ModuleConfig` objects to `OrchestrationConfig` instead of a single one.\n",
"The configurations are tried in order: if a call with one configuration fails, the next one is used as fallback.\n",
"\n",
"This works for both regular and streaming calls.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "827c4812",
"metadata": {},
"outputs": [],
"source": [
"from gen_ai_hub.orchestration_v2 import (SystemMessage, UserMessage, Template, PromptTemplatingModuleConfig,\n",
" LLMModelDetails, ModuleConfig, OrchestrationConfig, OrchestrationService)\n",
"\n",
"working_config = ModuleConfig(\n",
" prompt_templating=PromptTemplatingModuleConfig(\n",
" prompt=Template(template=[UserMessage(content=\"What is the longest river on planet earth?\")]),\n",
" model=LLMModelDetails(name=\"gpt-4o-mini\"),\n",
" )\n",
")\n",
"\n",
"second_working_config = ModuleConfig(\n",
" prompt_templating=PromptTemplatingModuleConfig(\n",
" prompt=Template(template=[UserMessage(content=\"What is the longest river on planet earth?\")]),\n",
" model=LLMModelDetails(name=\"gpt-4o\"),\n",
" )\n",
")\n",
"\n",
"broken_config = ModuleConfig(\n",
" prompt_templating=PromptTemplatingModuleConfig(\n",
" prompt=Template(template=[UserMessage(content=\"What is the longest river on planet earth?\")]),\n",
" model=LLMModelDetails(name=\"dummy-model\"),\n",
" )\n",
")\n",
"\n",
"# broken_config is tried first and will fail, so working_config is used as fallback\n",
"config = OrchestrationConfig(modules=[broken_config, working_config, second_working_config])\n",
"\n",
"service = OrchestrationService(config=config)\n",
"result = service.run()\n",
"print(result.final_result.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"id": "1bd44dc91b57793d",
Expand Down
Loading