Panggil semua API LLM menggunakan format OpenAI [Bedrock, Huggingface, VertexAI, TogetherAI, Azure, OpenAI, Groq, dll.]
LiteLLM mengelola:
completion
, embedding
, dan image_generation
penyedia['choices'][0]['message']['content']
Lompat ke Dokumen LiteLLM Proxy (LLM Gateway).
Lompat ke Penyedia LLM yang Didukung
? Rilis Stabil: Gunakan gambar buruh pelabuhan dengan tag -stable
. Ini telah menjalani tes beban 12 jam, sebelum dipublikasikan.
Dukungan untuk lebih banyak penyedia. Tidak ada penyedia atau Platform LLM, ajukan permintaan fitur.
Penting
LiteLLM v1.0.0 sekarang membutuhkan openai>=1.0.0
. Panduan migrasi di sini
LiteLLM v1.40.14+ sekarang membutuhkan pydantic>=2.0.0
. Tidak diperlukan perubahan.
pip install litellm
from litellm import completion
import os
## set ENV variables
os . environ [ "OPENAI_API_KEY" ] = "your-openai-key"
os . environ [ "COHERE_API_KEY" ] = "your-cohere-key"
messages = [{ "content" : "Hello, how are you?" , "role" : "user" }]
# openai call
response = completion ( model = "gpt-3.5-turbo" , messages = messages )
# cohere call
response = completion ( model = "command-nightly" , messages = messages )
print ( response )
Panggil model apa pun yang didukung oleh penyedia, dengan model=
. Mungkin ada detail khusus penyedia di sini, jadi lihat dokumen penyedia untuk informasi lebih lanjut
from litellm import acompletion
import asyncio
async def test_get_response ():
user_message = "Hello, how are you?"
messages = [{ "content" : user_message , "role" : "user" }]
response = await acompletion ( model = "gpt-3.5-turbo" , messages = messages )
return response
response = asyncio . run ( test_get_response ())
print ( response )
liteLLM mendukung streaming kembali respons model, teruskan stream=True
untuk mendapatkan iterator streaming sebagai respons.
Streaming didukung untuk semua model (Bedrock, Huggingface, TogetherAI, Azure, OpenAI, dll.)
from litellm import completion
response = completion ( model = "gpt-3.5-turbo" , messages = messages , stream = True )
for part in response :
print ( part . choices [ 0 ]. delta . content or "" )
# claude 2
response = completion ( 'claude-2' , messages , stream = True )
for part in response :
print ( part . choices [ 0 ]. delta . content or "" )
LiteLLM mengekspos panggilan balik yang telah ditentukan sebelumnya untuk mengirim data ke Lunary, Langfuse, DynamoDB, s3 Buckets, Helicone, Promptlayer, Traceloop, Athina, Slack
from litellm import completion
## set env variables for logging tools
os . environ [ "LUNARY_PUBLIC_KEY" ] = "your-lunary-public-key"
os . environ [ "HELICONE_API_KEY" ] = "your-helicone-auth-key"
os . environ [ "LANGFUSE_PUBLIC_KEY" ] = ""
os . environ [ "LANGFUSE_SECRET_KEY" ] = ""
os . environ [ "ATHINA_API_KEY" ] = "your-athina-api-key"
os . environ [ "OPENAI_API_KEY" ]
# set callbacks
litellm . success_callback = [ "lunary" , "langfuse" , "athina" , "helicone" ] # log input/output to lunary, langfuse, supabase, athina, helicone etc
#openai call
response = completion ( model = "gpt-3.5-turbo" , messages = [{ "role" : "user" , "content" : "Hi ? - i'm openai" }])
Lacak pembelanjaan + Load Balance di beberapa proyek
Proksi yang Dihosting (Pratinjau)
Proksi menyediakan:
pip install ' litellm[proxy] '
$ litellm --model huggingface/bigcode/starcoder
# INFO: Proxy running on http://0.0.0.0:4000
Penting
Gunakan Proxy LiteLLM dengan Langchain (Python, JS), OpenAI SDK (Python, JS) Anthropic SDK, Mistral SDK, LlamaIndex, Instructor, Curl
import openai # openai v1.0.0+
client = openai . OpenAI ( api_key = "anything" , base_url = "http://0.0.0.0:4000" ) # set proxy to base_url
# 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 )
Hubungkan proksi dengan DB Postgres untuk membuat kunci proksi
# Get the code
git clone https://github.com/BerriAI/litellm
# Go to folder
cd litellm
# Add the master key - you can change this after setup
echo ' LITELLM_MASTER_KEY="sk-1234" ' > .env
# Add the litellm salt key - you cannot change this after adding a model
# It is used to encrypt / decrypt your LLM API Key credentials
# We recommned - https://1password.com/password-generator/
# password generator to get a random hash for litellm salt key
echo ' LITELLM_SALT_KEY="sk-1234" ' > .env
source .env
# Start
docker-compose up
UI di /ui
di server proxy Anda
Tetapkan anggaran dan batas tarif di beberapa proyek POST /key/generate
curl ' http://0.0.0.0:4000/key/generate '
--header ' Authorization: Bearer sk-1234 '
--header ' Content-Type: application/json '
--data-raw ' {"models": ["gpt-3.5-turbo", "gpt-4", "claude-2"], "duration": "20m","metadata": {"user": "[email protected]", "team": "core-infra"}} '
{
" key " : " sk-kdEXbIqZRwEeEiHwdg7sFA " , # Bearer token
" expires " : " 2023-11-19T01:38:25.838000+00:00 " # datetime object
}
Penyedia | Penyelesaian | Mengalir | Penyelesaian Asinkron | Streaming Asinkron | Penyematan Asinkron | Pembuatan Gambar Asinkron |
---|---|---|---|---|---|---|
terbuka | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
biru langit | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
aws - pembuat bijak | ✅ | ✅ | ✅ | ✅ | ✅ | |
aws - batuan dasar | ✅ | ✅ | ✅ | ✅ | ✅ | |
google - vertex_ai | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
google - telapak tangan | ✅ | ✅ | ✅ | ✅ | ||
google AI Studio - gemini | ✅ | ✅ | ✅ | ✅ | ||
mistral ai api | ✅ | ✅ | ✅ | ✅ | ✅ | |
Pekerja AI cloudflare | ✅ | ✅ | ✅ | ✅ | ||
berpadu | ✅ | ✅ | ✅ | ✅ | ✅ | |
antropis | ✅ | ✅ | ✅ | ✅ | ||
memberdayakan | ✅ | ✅ | ✅ | ✅ | ||
wajah berpelukan | ✅ | ✅ | ✅ | ✅ | ✅ | |
mengulangi | ✅ | ✅ | ✅ | ✅ | ||
bersama_ai | ✅ | ✅ | ✅ | ✅ | ||
openrouter | ✅ | ✅ | ✅ | ✅ | ||
ai21 | ✅ | ✅ | ✅ | ✅ | ||
dasar | ✅ | ✅ | ✅ | ✅ | ||
vllm | ✅ | ✅ | ✅ | ✅ | ||
nlp_cloud | ✅ | ✅ | ✅ | ✅ | ||
aleph alfa | ✅ | ✅ | ✅ | ✅ | ||
kelopak | ✅ | ✅ | ✅ | ✅ | ||
ollama | ✅ | ✅ | ✅ | ✅ | ✅ | |
infra dalam | ✅ | ✅ | ✅ | ✅ | ||
kebingungan-ai | ✅ | ✅ | ✅ | ✅ | ||
Groq AI | ✅ | ✅ | ✅ | ✅ | ||
Pencarian mendalam | ✅ | ✅ | ✅ | ✅ | ||
skala apa pun | ✅ | ✅ | ✅ | ✅ | ||
IBM - watsonx.ai | ✅ | ✅ | ✅ | ✅ | ✅ | |
perjalanan ai | ✅ | |||||
xinference [Inferensi Xorbit] | ✅ | |||||
Teman AI | ✅ | ✅ | ✅ | ✅ |
Baca Dokumen
Untuk berkontribusi: Kloning repo secara lokal -> Buat perubahan -> Kirim PR dengan perubahan tersebut.
Berikut cara memodifikasi repo secara lokal: Langkah 1: Kloning repo
git clone https://github.com/BerriAI/litellm.git
Langkah 2: Navigasikan ke proyek, dan instal dependensi:
cd litellm
poetry install -E extra_proxy -E proxy
Langkah 3: Uji perubahan Anda:
cd litellm/tests # pwd: Documents/litellm/litellm/tests
poetry run flake8
poetry run pytest .
Langkah 4: Kirim PR dengan perubahan Anda! ?
Untuk perusahaan yang membutuhkan keamanan yang lebih baik, manajemen pengguna, dan dukungan profesional
Bicaralah dengan para pendiri
Ini mencakup: