From ee1a0a940902f20c5fc108c4f9b293b84c6354ca Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 20 Mar 2024 21:15:50 -0700 Subject: [PATCH] (docs) add example using openai compatib model --- .../docs/providers/openai_compatible.md | 75 ++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/docs/my-website/docs/providers/openai_compatible.md b/docs/my-website/docs/providers/openai_compatible.md index f86544c285d..09dcd7e4c98 100644 --- a/docs/my-website/docs/providers/openai_compatible.md +++ b/docs/my-website/docs/providers/openai_compatible.md @@ -1,3 +1,6 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + # OpenAI-Compatible Endpoints To call models hosted behind an openai proxy, make 2 changes: @@ -39,4 +42,74 @@ response = litellm.embedding( input=["good morning from litellm"] ) print(response) -``` \ No newline at end of file +``` + + + +## Usage with LiteLLM Proxy Server + +Here's how to call an OpenAI-Compatible Endpoint with the LiteLLM Proxy Server + +1. Modify the config.yaml + + ```yaml + model_list: + - model_name: my-model + litellm_params: + model: openai/ # add openai/ prefix to route as OpenAI provider + api_base: # add api base for OpenAI compatible provider + api_key: api-key # api key to send your model + ``` + +2. Start the proxy + + ```bash + $ litellm --config /path/to/config.yaml + ``` + +3. Send Request to LiteLLM Proxy Server + + + + + + ```python + import openai + client = openai.OpenAI( + api_key="sk-1234", # pass litellm proxy key, if you're using virtual keys + base_url="http://0.0.0.0:4000" # litellm-proxy-base url + ) + + response = client.chat.completions.create( + model="my-model", + messages = [ + { + "role": "user", + "content": "what llm are you" + } + ], + ) + + print(response) + ``` + + + + + ```shell + curl --location 'http://0.0.0.0:4000/chat/completions' \ + --header 'Authorization: Bearer sk-1234' \ + --header 'Content-Type: application/json' \ + --data '{ + "model": "my-model", + "messages": [ + { + "role": "user", + "content": "what llm are you" + } + ], + }' + ``` + + +