Schnellstart
Schneller Start CLI, Konfiguration, Docker
LiteLLM Server (LLM Gateway) verwaltet
- Einheitliche Schnittstelle: Aufruf von über 100 LLMs Huggingface/Bedrock/TogetherAI/etc. im OpenAI
ChatCompletions&CompletionsFormat - Kostenverfolgung: Authentifizierung, Ausgabenverfolgung & Budgets Virtuelle Schlüssel
- Lastverteilung: Zwischen mehreren Modellen + Bereitstellungen desselben Modells - LiteLLM Proxy kann bei Lasttests über 1,5k Anfragen/Sekunde verarbeiten.
$ pip install 'litellm[proxy]'
Schneller Start - LiteLLM Proxy CLI
Führen Sie den folgenden Befehl aus, um den litellm proxy zu starten
$ litellm --model huggingface/bigcode/starcoder
#INFO: Proxy running on http://0.0.0.0:4000
Führen Sie mit --detailed_debug aus, wenn Sie detaillierte Debug-Logs benötigen
$ litellm --model huggingface/bigcode/starcoder --detailed_debug
Testen
Führen Sie in einem neuen Terminal aus. Dies wird eine openai.chat.completions Anfrage machen. Stellen Sie sicher, dass Sie OpenAI v1.0.0+ verwenden.
litellm --test
Dies leitet nun automatisch alle Anfragen für gpt-3.5-turbo an bigcode starcoder weiter, das auf Huggingface Inference Endpoints gehostet wird.
Unterstützte LLMs
Alle von LiteLLM unterstützten LLMs werden vom Proxy unterstützt. Sehen Sie alle unterstützten LLMs
- AWS Bedrock
- Azure OpenAI
- OpenAI
- Ollama
- OpenAI-kompatibler Endpunkt
- Vertex AI [Gemini]
- Huggingface (TGI) bereitgestellt
- Huggingface (TGI) lokal
- AWS Sagemaker
- Anthropic
- VLLM
- TogetherAI
- Replicate
- Petals
- Palm
- AI21
- Cohere
$ export AWS_ACCESS_KEY_ID=
$ export AWS_REGION_NAME=
$ export AWS_SECRET_ACCESS_KEY=
$ litellm --model bedrock/anthropic.claude-v2
$ export AZURE_API_KEY=my-api-key
$ export AZURE_API_BASE=my-api-base
$ litellm --model azure/my-deployment-name
$ export OPENAI_API_KEY=my-api-key
$ litellm --model gpt-3.5-turbo
$ litellm --model ollama/<ollama-model-name>
$ export OPENAI_API_KEY=my-api-key
$ litellm --model openai/<your model name> --api_base <your-api-base> # e.g. http://0.0.0.0:3000
$ export VERTEX_PROJECT="hardy-project"
$ export VERTEX_LOCATION="us-west"
$ litellm --model vertex_ai/gemini-pro
$ export HUGGINGFACE_API_KEY=my-api-key #[OPTIONAL]
$ litellm --model huggingface/<your model name> --api_base <your-api-base> # e.g. http://0.0.0.0:3000
$ litellm --model huggingface/<your model name> --api_base http://0.0.0.0:8001
export AWS_ACCESS_KEY_ID=
export AWS_REGION_NAME=
export AWS_SECRET_ACCESS_KEY=
$ litellm --model sagemaker/jumpstart-dft-meta-textgeneration-llama-2-7b
$ export ANTHROPIC_API_KEY=my-api-key
$ litellm --model claude-instant-1
$ litellm --model vllm/facebook/opt-125m
$ export TOGETHERAI_API_KEY=my-api-key
$ litellm --model together_ai/lmsys/vicuna-13b-v1.5-16k
$ export REPLICATE_API_KEY=my-api-key
$ litellm \
--model replicate/meta/llama-2-70b-chat:02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3
$ litellm --model petals/meta-llama/Llama-2-70b-chat-hf
$ export PALM_API_KEY=my-palm-key
$ litellm --model palm/chat-bison
$ export AI21_API_KEY=my-api-key
$ litellm --model j2-light
$ export COHERE_API_KEY=my-api-key
$ litellm --model command-nightly
Schneller Start - LiteLLM Proxy + Config.yaml
Die Konfiguration ermöglicht es Ihnen, eine Modellliste zu erstellen und api_base, max_tokens (alle litellm-Parameter) festzulegen. Weitere Details zur Konfiguration finden Sie hier.
Erstellen Sie eine Konfiguration für LiteLLM Proxy
Beispielkonfiguration
model_list:
- model_name: gpt-3.5-turbo # user-facing model alias
litellm_params: # all params accepted by litellm.completion() - https://docs.litellm.de/docs/completion/input
model: azure/<your-deployment-name>
api_base: <your-azure-api-endpoint>
api_key: <your-azure-api-key>
- model_name: gpt-3.5-turbo
litellm_params:
model: azure/gpt-turbo-small-ca
api_base: https://my-endpoint-canada-berri992.openai.azure.com/
api_key: <your-azure-api-key>
- model_name: vllm-model
litellm_params:
model: openai/<your-model-name>
api_base: <your-vllm-api-base> # e.g. http://0.0.0.0:3000/v1
api_key: <your-vllm-api-key|none>
Proxy mit Konfiguration ausführen
litellm --config your_config.yaml
Verwendung von LiteLLM Proxy - Curl-Anfrage, OpenAI-Paket, Langchain
LiteLLM ist mit mehreren SDKs kompatibel - darunter OpenAI SDK, Anthropic SDK, Mistral SDK, LLamaIndex, Langchain (Js, Python)
- Curl-Anfrage
- OpenAI v1.0.0+
- Langchain
- Langchain Embeddings
- LiteLLM SDK
- Anthropic Python SDK
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"
}
]
}
'
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)
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)
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(model="sagemaker-embeddings", openai_api_base="http://0.0.0.0:4000", openai_api_key="temp-key")
text = "This is a test document."
query_result = embeddings.embed_query(text)
print(f"SAGEMAKER EMBEDDINGS")
print(query_result[:5])
embeddings = OpenAIEmbeddings(model="bedrock-embeddings", openai_api_base="http://0.0.0.0:4000", openai_api_key="temp-key")
text = "This is a test document."
query_result = embeddings.embed_query(text)
print(f"BEDROCK EMBEDDINGS")
print(query_result[:5])
embeddings = OpenAIEmbeddings(model="bedrock-titan-embeddings", openai_api_base="http://0.0.0.0:4000", openai_api_key="temp-key")
text = "This is a test document."
query_result = embeddings.embed_query(text)
print(f"TITAN EMBEDDINGS")
print(query_result[:5])
Dies wird nicht empfohlen. Es gibt doppelte Logik, da der Proxy auch das SDK verwendet, was zu unerwarteten Fehlern führen kann.
from litellm import completion
response = completion(
model="openai/gpt-3.5-turbo",
messages = [
{
"role": "user",
"content": "this is a test request, write a short poem"
}
],
api_key="anything",
base_url="http://0.0.0.0:4000"
)
print(response)
import os
from anthropic import Anthropic
client = Anthropic(
base_url="https://:4000", # proxy endpoint
api_key="sk-s4xN1IiLTCytwtZFJaYQrA", # litellm proxy virtual key
)
message = client.messages.create(
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Hello, Claude",
}
],
model="claude-3-opus-20240229",
)
print(message.content)
📖 Proxy-Endpunkte - Swagger Docs
- POST
/chat/completions- Chat-Completions-Endpunkt zum Aufrufen von über 100 LLMs - POST
/completions- Completions-Endpunkt - POST
/embeddings- Embedding-Endpunkt für Azure, OpenAI, Huggingface-Endpunkte - GET
/models- verfügbare Modelle auf dem Server - POST
/key/generate- Generieren Sie einen Schlüssel für den Zugriff auf den Proxy
Proxy debuggen
Ereignisse, die während des normalen Betriebs auftreten
litellm --model gpt-3.5-turbo --debug
Detaillierte Informationen
litellm --model gpt-3.5-turbo --detailed_debug
Debug-Level über Umgebungsvariablen festlegen
Ereignisse, die während des normalen Betriebs auftreten
export LITELLM_LOG=INFO
Detaillierte Informationen
export LITELLM_LOG=DEBUG
Keine Protokolle
export LITELLM_LOG=None