概要
過去に dspy で使用したエンドポイントを LiteLLM Proxy で使用する方法を紹介します
ちなみに LiteLLM Proxy は簡単に言うと OpenAI API 互換に変換してくれるプロキシです
環境
- docker 27.3.1
- Ubuntu 24.04
- litellm-proxy v1.67.0-stable
litellm_config.yaml
model_list:
- model_name: azure-gpt-4-32k
litellm_params:
model: azure/gpt-4-32k
api_base: os.environ/AZURE_API_BASE # runs os.getenv("AZURE_API_BASE")
api_key: os.environ/AZURE_API_KEY # runs os.getenv("AZURE_API_KEY")
api_version: ""
docker 起動
docker run \
-v $(pwd)/litellm_config.yaml:/app/config.yaml \
-e AZURE_API_KEY=b4xxx \
-e AZURE_API_BASE=https://your-api-endpoint/ai/chat-ai/gpt4 \
-p 4000:4000 \
ghcr.io/berriai/litellm:main-latest \
--config /app/config.yaml --detailed_debug
動作確認
curl で動作確認します
model 名は litellm_config.yaml で指定した model_name を指定します
curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--data '{
"model": "azure-gpt-4-32k",
"messages": [
{
"role": "user",
"content": "what llm are you"
}
]
}'
レスポンスは以下です
{
"id": "chatcmpl-BOZAENZRJ1j3WErgssAmUj41gcl16",
"created": 1745194742,
"model": "gpt-4o-2024-08-06",
"object": "chat.completion",
"system_fingerprint": "fp_ee1d74bde0",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "I am based on OpenAI's GPT-4 architecture, which is a type of large language model (LLM) designed for understanding and generating human-like text.",
"role": "assistant",
"tool_calls": null,
"function_call": null
}
}
],
"usage": {
"completion_tokens": 34,
"prompt_tokens": 12,
"total_tokens": 46,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0
}
},
"service_tier": null,
"prompt_filter_results": [
{
"prompt_index": 0,
"content_filter_results": {
"hate": {
"filtered": false,
"severity": "safe"
},
"self_harm": {
"filtered": false,
"severity": "safe"
},
"sexual": {
"filtered": false,
"severity": "safe"
},
"violence": {
"filtered": false,
"severity": "safe"
}
}
}
]
}
最後に
次回はこれと Open WebUI を組み合わせて自分専用の Chat 用 UI を構築します
0 件のコメント:
コメントを投稿