From 6a0f4cc773dba49b721302d6acd4879cd0680e32 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Tue, 22 Aug 2023 15:27:28 -0700 Subject: [PATCH] add fallbacks tutorial to docs --- docs/my-website/docs/tutorials/fallbacks.md | 47 +++++++++++++++++++++ docs/my-website/sidebars.js | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 docs/my-website/docs/tutorials/fallbacks.md diff --git a/docs/my-website/docs/tutorials/fallbacks.md b/docs/my-website/docs/tutorials/fallbacks.md new file mode 100644 index 0000000000..6fd1b72d3e --- /dev/null +++ b/docs/my-website/docs/tutorials/fallbacks.md @@ -0,0 +1,47 @@ +Using completion() with Fallbacks for Reliability + +This tutorial demonstrates how to employ the `completion()` function with model fallbacks to ensure reliability. LLM APIs can be unstable, completion() with fallbacks ensures you'll always get a response from your calls + +## Usage +To use fallback models with `completion()`, specify a list of models in the `fallbacks` parameter. + +Example +```python +try: + response = completion( + model="bad-model", + messages=messages, + fallbacks=["gpt-3.5-turbo", "command-nightly"] + ) +``` + +Output +``` +Completion with 'bad-model': got exception Unable to map your input to a model. Check your input - {'model': 'bad-model' + + + +completion call gpt-3.5-turbo +{ + "id": "chatcmpl-7qTmVRuO3m3gIBg4aTmAumV1TmQhB", + "object": "chat.completion", + "created": 1692741891, + "model": "gpt-3.5-turbo-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "I apologize, but as an AI, I do not have the capability to provide real-time weather updates. However, you can easily check the current weather in San Francisco by using a search engine or checking a weather website or app." + }, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 16, + "completion_tokens": 46, + "total_tokens": 62 + } +} + +``` diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.js index 413589125a..cf3f2ff52f 100644 --- a/docs/my-website/sidebars.js +++ b/docs/my-website/sidebars.js @@ -34,7 +34,7 @@ const sidebars = { { type: 'category', label: 'Tutorials', - items: ['tutorials/huggingface_tutorial', 'tutorials/TogetherAI_liteLLM'], + items: ['tutorials/huggingface_tutorial', 'tutorials/TogetherAI_liteLLM', 'tutorials/fallbacks'], }, 'token_usage', 'stream',