LiteLLM عبارة عن حزمة تطوير برامج (SDK) مفتوحة المصدر بلغة Python وخادم وكيل (بوابة LLM)، قادر على استدعاء أكثر من 100 واجهة برمجة تطبيقات لنماذج اللغة الكبيرة بتنسيق OpenAI، بما في ذلك موفري الخدمات الرئيسيين مثل Bedrock وAzure وOpenAI وVertexAI وCohere وAnthropic وSagemaker وHuggingFace وReplicate وGroq وغيرها.
عنوان GitHub: https://github.com/BerriAI/litellm
['choices'][0]['message']['content']
from litellm import completion
import os
os.environ["OPENAI_API_KEY"] = "your-openai-key"
os.environ["ANTHROPIC_API_KEY"] = "your-anthropic-key"
messages = [{"content": "Hello, how are you?", "role": "user"}]
# OpenAI
response = completion(model="openai/gpt-4o", messages=messages)
# Anthropic
response = completion(model="anthropic/claude-3-sonnet-20240229", messages=messages)
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="openai/gpt-4o", messages=messages)
return response
response = asyncio.run(test_get_response())
from litellm import completion
response = completion(model="openai/gpt-4o", messages=messages, stream=True)
for part in response:
print(part.choices[0].delta.content or "")
pip install 'litellm[proxy]'
litellm --model huggingface/bigcode/starcoder
# INFO: Proxy running on http://0.0.0.0:4000
import openai
client = openai.OpenAI(
api_key="anything",
base_url="http://0.0.0.0:4000"
)
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{
"role": "user",
"content": "this is a test request, write a short poem"
}]
)
يدعم LiteLLM أكثر من 30 موفرًا رئيسيًا لـ LLM، بما في ذلك:
يدعم LiteLLM بشكل مضمن العديد من منصات المراقبة والتسجيل:
import litellm
import os
os.environ["LUNARY_PUBLIC_KEY"] = "your-lunary-public-key"
os.environ["HELICONE_API_KEY"] = "your-helicone-auth-key"
os.environ["LANGFUSE_PUBLIC_KEY"] = "your-langfuse-public-key"
litellm.success_callback = [
"lunary", "mlflow", "langfuse",
"athina", "helicone"
]
response = completion(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Hi 👋"}]
)
منصات المراقبة المدعومة:
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": "user@company.com",
"team": "core-infra"
}
}'
git clone https://github.com/BerriAI/litellm
cd litellm
echo 'LITELLM_MASTER_KEY="sk-1234"' > .env
echo 'LITELLM_SALT_KEY="your-salt-key"' > .env
docker-compose up
/ui
للحصول على واجهة إدارة مرئيةopenai>=1.0.0
(إلزامي v1.0.0+)pydantic>=2.0.0
(إلزامي v1.40.14+)-stable
pip install litellm
pip install 'litellm[proxy]'
git clone https://github.com/BerriAI/litellm
cd litellm
python -m venv .venv
source .venv/bin/activate
pip install -e ".[all]"
uvicorn litellm.proxy.proxy_server:app --host localhost --port 4000 --reload
تم اعتماد LiteLLM من قبل شركات بارزة مثل Rocket Money وSamsara وLemonade وAdobe. من خلال توفير واجهة API موحدة ووظائف توجيه قوية وميزات إدارة على مستوى المؤسسات، فإنه يبسط بشكل كبير تعقيد إدارة بيئات LLM المتعددة، مما يجعله خيارًا مثاليًا لتطوير تطبيقات الذكاء الاصطناعي الحديثة.