mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-04 23:07:50 +00:00
(docs) using openai compatible endpoints
This commit is contained in:
@@ -6,42 +6,37 @@ To call models hosted behind an openai proxy, make 2 changes:
|
||||
|
||||
2. **Do NOT** add anything additional to the base url e.g. `/v1/embedding`. LiteLLM uses the openai-client to make these calls, and that automatically adds the relevant endpoints.
|
||||
|
||||
## Usage
|
||||
|
||||
## Usage - completion
|
||||
```python
|
||||
import litellm
|
||||
import os
|
||||
|
||||
response = litellm.completion(
|
||||
model="openai/mistral, # add `openai/` prefix to model so litellm knows to route to OpenAI
|
||||
api_key="sk-1234", # api key to your openai compatible endpoint
|
||||
api_base="http://0.0.0.0:8000", # set API Base of your Custom OpenAI Endpoint
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hey, how's it going?",
|
||||
}
|
||||
],
|
||||
)
|
||||
print(response)
|
||||
```
|
||||
|
||||
## Usage - embedding
|
||||
|
||||
```python
|
||||
import litellm
|
||||
from litellm import embedding
|
||||
litellm.set_verbose = True
|
||||
import os
|
||||
|
||||
|
||||
litellm_proxy_endpoint = "http://0.0.0.0:8000"
|
||||
bearer_token = "sk-1234"
|
||||
|
||||
CHOSEN_LITE_LLM_EMBEDDING_MODEL = "openai/GPT-J 6B - Sagemaker Text Embedding (Internal)"
|
||||
|
||||
litellm.set_verbose = False
|
||||
|
||||
print(litellm_proxy_endpoint)
|
||||
|
||||
|
||||
|
||||
response = embedding(
|
||||
|
||||
model = CHOSEN_LITE_LLM_EMBEDDING_MODEL, # add `openai/` prefix to model so litellm knows to route to OpenAI
|
||||
|
||||
api_key=bearer_token,
|
||||
|
||||
api_base=litellm_proxy_endpoint, # set API Base of your Custom OpenAI Endpoint
|
||||
|
||||
input=["good morning from litellm"],
|
||||
|
||||
api_version='2023-07-01-preview'
|
||||
|
||||
response = litellm.embedding(
|
||||
model="openai/GPT-J", # add `openai/` prefix to model so litellm knows to route to OpenAI
|
||||
api_key="sk-1234", # api key to your openai compatible endpoint
|
||||
api_base="http://0.0.0.0:8000", # set API Base of your Custom OpenAI Endpoint
|
||||
input=["good morning from litellm"]
|
||||
)
|
||||
|
||||
print('================================================')
|
||||
|
||||
print(len(response.data[0]['embedding']))
|
||||
|
||||
print(response)
|
||||
```
|
||||
Reference in New Issue
Block a user