forked from phoenix/litellm-mirror
adding model fallback example
This commit is contained in:
parent
6bf2db71d1
commit
1be48da73e
1 changed files with 52 additions and 0 deletions
52
cookbook/Untitled156.ipynb
Normal file
52
cookbook/Untitled156.ipynb
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
{
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 0,
|
||||||
|
"metadata": {
|
||||||
|
"colab": {
|
||||||
|
"provenance": []
|
||||||
|
},
|
||||||
|
"kernelspec": {
|
||||||
|
"name": "python3",
|
||||||
|
"display_name": "Python 3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"name": "python"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"source": [
|
||||||
|
"!pip install litellm"
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"id": "j6yJsCGeaq8G"
|
||||||
|
},
|
||||||
|
"execution_count": null,
|
||||||
|
"outputs": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "u129iWNPaf72"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import litellm\n",
|
||||||
|
"from litellm import embedding, completion\n",
|
||||||
|
"\n",
|
||||||
|
"model_fallback_list = [\"claude-instant-1\", \"gpt-3.5-turbo\", \"chatgpt-test\"]\n",
|
||||||
|
"\n",
|
||||||
|
"user_message = \"Hello, how are you?\"\n",
|
||||||
|
"messages = [{ \"content\": user_message,\"role\": \"user\"}]\n",
|
||||||
|
"\n",
|
||||||
|
"for model in model_fallback_list:\n",
|
||||||
|
" try:\n",
|
||||||
|
" response = completion(model=model, messages=messages)\n",
|
||||||
|
" except Exception as e:\n",
|
||||||
|
" print(f\"error occurred: {traceback.format_exc()}\")"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue