From cdae08f3c30aeb83bff76bbe80c4584a325dbef5 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 1 Apr 2024 12:09:08 -0700 Subject: [PATCH] docs(openai.md): fix docs to include example of calling openai on proxy --- docs/my-website/docs/providers/openai.md | 110 +++++++++++++++++++++++ litellm/proxy/_new_secret_config.yaml | 23 +++-- 2 files changed, 124 insertions(+), 9 deletions(-) diff --git a/docs/my-website/docs/providers/openai.md b/docs/my-website/docs/providers/openai.md index aa42847b1..c50cc7598 100644 --- a/docs/my-website/docs/providers/openai.md +++ b/docs/my-website/docs/providers/openai.md @@ -1,3 +1,6 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + # OpenAI LiteLLM supports OpenAI Chat + Text completion and embedding calls. @@ -22,6 +25,113 @@ response = completion( ) ``` +### Proxy Usage + +Here's how to call OpenAI models with the LiteLLM Proxy Server + +### 1. Save key in your environment + +```bash +export OPENAI_API_KEY="" +``` + +### 2. Start the proxy + + + + +```bash +$ litellm --model gpt-3.5-turbo + +# Server running on http://0.0.0.0:4000 +``` + + + +```yaml +model_list: + - model_name: gpt-3.5-turbo + litellm_params: + model: gpt-3.5-turbo +``` + + + +### 3. Test it + + + + + +```shell +curl --location 'http://0.0.0.0:4000/chat/completions' \ +--header 'Content-Type: application/json' \ +--data ' { + "model": "gpt-3.5-turbo", + "messages": [ + { + "role": "user", + "content": "what llm are you" + } + ] + } +' +``` + + + +```python +import openai +client = openai.OpenAI( + api_key="anything", + base_url="http://0.0.0.0:4000" +) + +# request sent to model set on litellm proxy, `litellm --model` +response = client.chat.completions.create(model="gpt-3.5-turbo", messages = [ + { + "role": "user", + "content": "this is a test request, write a short poem" + } +]) + +print(response) + +``` + + + +```python +from langchain.chat_models import ChatOpenAI +from langchain.prompts.chat import ( + ChatPromptTemplate, + HumanMessagePromptTemplate, + SystemMessagePromptTemplate, +) +from langchain.schema import HumanMessage, SystemMessage + +chat = ChatOpenAI( + openai_api_base="http://0.0.0.0:4000", # set openai_api_base to the LiteLLM Proxy + model = "gpt-3.5-turbo", + temperature=0.1 +) + +messages = [ + SystemMessage( + content="You are a helpful assistant that im using to make a test request to." + ), + HumanMessage( + content="test from litellm. tell me why it's amazing in 1 sentence" + ), +] +response = chat(messages) + +print(response) +``` + + + + ### Optional Keys - OpenAI Organization, OpenAI API Base ```python diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml index dde07bb87..003597eaa 100644 --- a/litellm/proxy/_new_secret_config.yaml +++ b/litellm/proxy/_new_secret_config.yaml @@ -4,18 +4,23 @@ model_list: model: openai/my-fake-model api_key: my-fake-key api_base: https://exampleopenaiendpoint-production.up.railway.app/ +- model_name: gpt-instruct + litellm_params: + model: gpt-3.5-turbo-instruct + # api_key: my-fake-key + # api_base: https://exampleopenaiendpoint-production.up.railway.app/ -litellm_settings: - cache: true +# litellm_settings: +# cache: true # max_budget: 600020 # budget_duration: 30d general_settings: master_key: sk-1234 - proxy_batch_write_at: 60 # 👈 Frequency of batch writing logs to server (in seconds) - enable_jwt_auth: True - alerting: ["slack"] - litellm_jwtauth: - admin_jwt_scope: "litellm_proxy_admin" - team_jwt_scope: "litellm_team" - public_key_ttl: 600 \ No newline at end of file + # proxy_batch_write_at: 60 # 👈 Frequency of batch writing logs to server (in seconds) + # enable_jwt_auth: True + # alerting: ["slack"] + # litellm_jwtauth: + # admin_jwt_scope: "litellm_proxy_admin" + # team_jwt_scope: "litellm_team" + # public_key_ttl: 600 \ No newline at end of file