From 246052fe232a2629c1732325d15543fc7e90fdf7 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 2 Nov 2024 02:12:35 +0530 Subject: [PATCH] docs(lm_studio.md): add doc on lm studio support --- docs/my-website/docs/providers/lm_studio.md | 130 ++++++++++++++++++++ docs/my-website/sidebars.js | 1 + 2 files changed, 131 insertions(+) create mode 100644 docs/my-website/docs/providers/lm_studio.md diff --git a/docs/my-website/docs/providers/lm_studio.md b/docs/my-website/docs/providers/lm_studio.md new file mode 100644 index 00000000000..6a8bb1cdd21 --- /dev/null +++ b/docs/my-website/docs/providers/lm_studio.md @@ -0,0 +1,130 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# LM Studio + +https://lmstudio.ai/docs/basics/server + +:::tip + +**We support ALL LM Studio models, just set `model=lm_studio/` as a prefix when sending litellm requests** + +::: + +## API Key +```python +# env variable +os.environ['LM_STUDIO_API_BASE'] +os.environ['LM_STUDIO_API_KEY'] # optional, default is empty +``` + +## Sample Usage +```python +from litellm import completion +import os + +os.environ['LM_STUDIO_API_BASE'] = "" + +response = completion( + model="lm_studio/llama-3-8b-instruct", + messages=[ + { + "role": "user", + "content": "What's the weather like in Boston today in Fahrenheit?", + } + ] +) +print(response) +``` + +## Sample Usage - Streaming +```python +from litellm import completion +import os + +os.environ['XAI_API_KEY'] = "" +response = completion( + model="lm_studio/llama-3-8b-instruct", + messages=[ + { + "role": "user", + "content": "What's the weather like in Boston today in Fahrenheit?", + } + ], + stream=True, +) + +for chunk in response: + print(chunk) +``` + + +## Usage with LiteLLM Proxy Server + +Here's how to call a XAI model with the LiteLLM Proxy Server + +1. Modify the config.yaml + + ```yaml + model_list: + - model_name: my-model + litellm_params: + model: lm_studio/ # add lm_studio/ prefix to route as LM Studio 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" + } + ], + }' + ``` + + + + + diff --git a/docs/my-website/sidebars.js b/docs/my-website/sidebars.js index 2df917f56c3..d0b46fe1ec6 100644 --- a/docs/my-website/sidebars.js +++ b/docs/my-website/sidebars.js @@ -156,6 +156,7 @@ const sidebars = { "providers/predibase", "providers/nvidia_nim", "providers/xai", + "providers/lm_studio", "providers/cerebras", "providers/volcano", "providers/triton-inference-server",