From 68bb735b3b0d15539821521ffb5a0da6fcae069d Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 26 Aug 2024 10:50:24 -0700 Subject: [PATCH 1/2] docs use litellm proxy with litellm python sdk --- .../docs/providers/litellm_proxy.md | 90 +++++++++++++++++++ docs/my-website/sidebars.js | 1 + 2 files changed, 91 insertions(+) create mode 100644 docs/my-website/docs/providers/litellm_proxy.md diff --git a/docs/my-website/docs/providers/litellm_proxy.md b/docs/my-website/docs/providers/litellm_proxy.md new file mode 100644 index 0000000000..de026967f0 --- /dev/null +++ b/docs/my-website/docs/providers/litellm_proxy.md @@ -0,0 +1,90 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# LiteLLM Proxy (LLM Gateway) + + +**[LiteLLM Proxy](../simple_proxy) is OpenAI compatible**, you just need the `openai/` prefix before the model + +:::tip + +[LiteLLM Providers a **self hosted** proxy server (AI Gateway)](../simple_proxy) to call all the LLMs in the OpenAI format + +::: + +## Required Variables + +```python +os.environ["OPENAI_API_KEY"] = "" # "sk-1234" your litellm proxy api key +os.environ["OPENAI_API_BASE"] = "" # "http://localhost:4000" your litellm proxy api base +``` + + +## Usage (Non Streaming) +```python +import os +import litellm +from litellm import completion + +os.environ["OPENAI_API_KEY"] = "" + +# set custom api base to your proxy +# either set .env or litellm.api_base +# os.environ["OPENAI_API_BASE"] = "" +litellm.api_base = "your-openai-proxy-url" + + +messages = [{ "content": "Hello, how are you?","role": "user"}] + +# openai call +response = completion(model="openai/your-model-name", messages) +``` + +## Usage - passing `api_base`, `api_key` per request + +If you need to set api_base dynamically, just pass it in completions instead - completions(...,api_base="your-proxy-api-base") + +```python +import os +import litellm +from litellm import completion + +os.environ["OPENAI_API_KEY"] = "" + +messages = [{ "content": "Hello, how are you?","role": "user"}] + +# openai call +response = completion( + model="openai/your-model-name", + messages, + api_base = "your-litellm-proxy-url", + api_key = "your-litellm-proxy-api-key" +) +``` +## Usage - Streaming + +```python +import os +import litellm +from litellm import completion + +os.environ["OPENAI_API_KEY"] = "" + +messages = [{ "content": "Hello, how are you?","role": "user"}] + +# openai call +response = completion( + model="openai/your-model-name", + messages, + api_base = "your-litellm-proxy-url", + stream=True +) + +for chunk in response: + print(chunk) +``` + + +## **Usage with Langchain, LLamaindex, OpenAI Js, Anthropic SDK, Instructor** + +[Follow this doc to see how to use litellm proxy with langchain, llamaindex, anthropic etc](../proxy/user_keys) \ No newline at end of file diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.js index 8c8c87fb8f..beae3544ff 100644 --- a/docs/my-website/sidebars.js +++ b/docs/my-website/sidebars.js @@ -128,6 +128,7 @@ const sidebars = { "providers/anthropic", "providers/aws_sagemaker", "providers/bedrock", + "providers/litellm_proxy", "providers/mistral", "providers/codestral", "providers/cohere", From 6d61c396b3cba8accbee84230066adb151e3d08c Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 26 Aug 2024 11:03:33 -0700 Subject: [PATCH 2/2] docs using litellm sdk with litellm proxy --- docs/my-website/docs/providers/litellm_proxy.md | 7 +++---- docs/my-website/docs/proxy/user_keys.md | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/my-website/docs/providers/litellm_proxy.md b/docs/my-website/docs/providers/litellm_proxy.md index de026967f0..2914b09f28 100644 --- a/docs/my-website/docs/providers/litellm_proxy.md +++ b/docs/my-website/docs/providers/litellm_proxy.md @@ -3,15 +3,14 @@ import TabItem from '@theme/TabItem'; # LiteLLM Proxy (LLM Gateway) - -**[LiteLLM Proxy](../simple_proxy) is OpenAI compatible**, you just need the `openai/` prefix before the model - :::tip [LiteLLM Providers a **self hosted** proxy server (AI Gateway)](../simple_proxy) to call all the LLMs in the OpenAI format ::: +**[LiteLLM Proxy](../simple_proxy) is OpenAI compatible**, you just need the `openai/` prefix before the model + ## Required Variables ```python @@ -87,4 +86,4 @@ for chunk in response: ## **Usage with Langchain, LLamaindex, OpenAI Js, Anthropic SDK, Instructor** -[Follow this doc to see how to use litellm proxy with langchain, llamaindex, anthropic etc](../proxy/user_keys) \ No newline at end of file +#### [Follow this doc to see how to use litellm proxy with langchain, llamaindex, anthropic etc](../proxy/user_keys) \ No newline at end of file diff --git a/docs/my-website/docs/proxy/user_keys.md b/docs/my-website/docs/proxy/user_keys.md index af037ea77b..18b6a36052 100644 --- a/docs/my-website/docs/proxy/user_keys.md +++ b/docs/my-website/docs/proxy/user_keys.md @@ -810,6 +810,9 @@ print(result) +## Using with Vertex, Boto3, Anthropic SDK (Native format) + +👉 **[Here's how to use litellm proxy with Vertex, boto3, Anthropic SDK - in the native format](../pass_through/vertex_ai.md)** ## Advanced