LiteLLMは、オープンソースのPython SDKおよびプロキシサーバー(LLMゲートウェイ)であり、Bedrock、Azure、OpenAI、VertexAI、Cohere、Anthropic、Sagemaker、HuggingFace、Replicate、Groqなどの主要プロバイダーを含む100以上の大規模言語モデルAPIをOpenAI形式で呼び出すことができます。
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は、以下の主要なLLMプロバイダーを30以上サポートしています。
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
タグ付きのDockerイメージを使用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環境の管理の複雑さを大幅に簡素化し、現代のAIアプリケーション開発に最適な選択肢です。