add new tutorial
This commit is contained in:
parent
94a1f4bd0e
commit
2dc1c35a05
32
docs/my-website/docs/tutorials/model_fallbacks.md
Normal file
32
docs/my-website/docs/tutorials/model_fallbacks.md
Normal file
@ -0,0 +1,32 @@
|
||||
# Basic Model Fallbacks w/ LiteLLM
|
||||
|
||||
Here's how you can implement model fallbacks across 3 LLM providers (OpenAI, Anthropic, Azure) using LiteLLM.
|
||||
|
||||
## 1. Install LiteLLM
|
||||
```python
|
||||
!pip install litellm
|
||||
```
|
||||
|
||||
## 2. Complete Code
|
||||
```python
|
||||
import litellm
|
||||
from litellm import embedding, completion
|
||||
|
||||
# set ENV variables
|
||||
os.environ["OPENAI_API_KEY"] = ""
|
||||
os.environ["ANTHROPIC_API_KEY"] = ""
|
||||
os.environ["AZURE_API_KEY"] = ""
|
||||
os.environ["AZURE_API_BASE"] = ""
|
||||
os.environ["AZURE_API_VERSION"] = ""
|
||||
|
||||
model_fallback_list = ["claude-instant-1", "gpt-3.5-turbo", "chatgpt-test"]
|
||||
|
||||
user_message = "Hello, how are you?"
|
||||
messages = [{ "content": user_message,"role": "user"}]
|
||||
|
||||
for model in model_fallback_list:
|
||||
try:
|
||||
response = completion(model=model, messages=messages)
|
||||
except Exception as e:
|
||||
print(f"error occurred: {traceback.format_exc()}")
|
||||
```
|
||||
@ -18,7 +18,7 @@ const sidebars = {
|
||||
// But you can create a sidebar manually
|
||||
tutorialSidebar: [
|
||||
{ type: "doc", id: "index" }, // NEW
|
||||
'tutorials/ab_test_llms',
|
||||
'tutorials/compare_llms',
|
||||
{
|
||||
type: "category",
|
||||
label: "Completion()",
|
||||
@ -30,32 +30,32 @@ const sidebars = {
|
||||
items: ["embedding/supported_embedding"],
|
||||
},
|
||||
'completion/supported',
|
||||
{
|
||||
type: "category",
|
||||
label: "Providers",
|
||||
link: {
|
||||
type: 'generated-index',
|
||||
title: 'Providers',
|
||||
description: 'Learn how to deploy + call models from different providers on LiteLLM',
|
||||
slug: '/providers',
|
||||
},
|
||||
items: ["providers/huggingface"],
|
||||
},
|
||||
// {
|
||||
// type: "category",
|
||||
// label: "Providers",
|
||||
// link: {
|
||||
// type: 'generated-index',
|
||||
// title: 'Providers',
|
||||
// description: 'Learn how to deploy + call models from different providers on LiteLLM',
|
||||
// slug: '/providers',
|
||||
// },
|
||||
// items: ["providers/huggingface"],
|
||||
// },
|
||||
"token_usage",
|
||||
"exception_mapping",
|
||||
// 'debugging/hosted_debugging',
|
||||
'debugging/local_debugging',
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Tutorials',
|
||||
items: [
|
||||
"tutorials/model_fallbacks",
|
||||
'tutorials/ab_test_llms',
|
||||
'tutorials/huggingface_tutorial',
|
||||
'tutorials/TogetherAI_liteLLM',
|
||||
'tutorials/compare_llms',
|
||||
'tutorials/finetuned_chat_gpt',
|
||||
'tutorials/text_completion',
|
||||
'tutorials/litellm_Test_Multiple_Providers',
|
||||
"tutorials/first_playground"
|
||||
"tutorials/first_playground",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user