Last active
February 5, 2025 06:38
-
-
Save ivwv/9bcf8fa3ee5e39c303017cc928a861af to your computer and use it in GitHub Desktop.
litellm.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 使用 litellm 官方镜像作为基础镜像 | |
FROM ghcr.io/berriai/litellm:main-latest | |
# 设置工作目录 | |
WORKDIR /app | |
# 尝试使用 apk 安装 curl | |
RUN apk update && apk add curl | |
# 从指定 URL 下载 litellm.sh 脚本 | |
RUN curl -s -L "https://gist.githubusercontent.com/ivwv/9bcf8fa3ee5e39c303017cc928a861af/raw/litellm.sh" -o /app/litellm.sh | |
# 确保脚本可执行 | |
RUN chmod +x /app/litellm.sh | |
# 暴露端口 | |
EXPOSE 4000 | |
# 在容器启动时执行 litellm.sh 生成配置文件并启动 litellm | |
ENTRYPOINT ["/app/litellm.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 可选的环境变量设置: | |
# | |
# MODEL_URL: 模型列表文件的 URL,默认为 https://gist.githubusercontent.com/ivwv/9bcf8fa3ee5e39c303017cc928a861af/raw/provider.txt | |
# MASTER_KEY: (可选) 设置后,所有 API 请求都必须在请求头中包含 `Authorization: Bearer <MASTER_KEY>` | |
# <PROVIDER>: (可选, 但建议设置) 例如: gemini="your_gemini_key", groq="your_groq_key" | |
# 为每个模型提供商设置 API 密钥,可以设置多个,用逗号分隔。例如: export gemini=key1,key2,key3 | |
# 如果没有设置某个提供商的 API_KEY,则该提供商的模型将被跳过。 | |
# | |
# 注意: | |
# - `<PROVIDER>` 需要替换为实际的提供商名称,例如 gemini, groq, openai 等。 | |
# - 提供商名称需要与模型列表文件 (MODEL_URL) 中 `model_name` 字段的第一个 `/` 之前的部分保持一致。 | |
# - 多个 API 密钥使用逗号分隔,不需要空格。 | |
# 设置工作目录 | |
cd "$(dirname "$0")" | |
# 从环境变量获取 MODEL_URL | |
MODEL_URL="${MODEL_URL:-https://gist.githubusercontent.com/ivwv/9bcf8fa3ee5e39c303017cc928a861af/raw/provider.txt}" | |
# 下载数据 | |
DATA=$(curl -s "$MODEL_URL") | |
# 检查下载是否成功 | |
if [ -z "$DATA" ]; then | |
echo "错误:无法从 $MODEL_URL 下载模型列表。" | |
exit 1 | |
fi | |
# 生成 litellm-config.yaml 文件 | |
OUTPUT_FILE="litellm-config.yaml" | |
# 开始构建 litellm-config.yaml | |
cat >"$OUTPUT_FILE" <<EOL | |
model_list: | |
EOL | |
# 获取所有已设置的环境变量 | |
env_vars=$(env | awk -F= '{print $1}') | |
while IFS= read -r line; do | |
PROVIDER=$(echo "$line" | cut -d'/' -f1) | |
# 检查当前提供商的环境变量是否已设置 | |
api_key_found=false | |
for var in $env_vars; do | |
if [[ "$var" == "$PROVIDER" ]]; then | |
api_key_found=true | |
break | |
fi | |
done | |
if ! $api_key_found; then | |
echo "警告: 未定义提供商 $PROVIDER 的 API_KEY,跳过该条目。" | |
continue | |
fi | |
# 获取 API 密钥列表,支持单个 API 密钥和逗号分隔的多个 API 密钥 | |
API_KEY_LIST=$(echo "${!PROVIDER}" | tr ',' '\n') | |
for API_KEY in $API_KEY_LIST; do | |
cat <<EOL >>"$OUTPUT_FILE" | |
- model_name: $line | |
litellm_params: | |
model: $line | |
api_key: "$API_KEY" | |
EOL | |
done | |
done <<<"$DATA" | |
# 添加 litellm_settings (可选) | |
cat <<EOL >>"$OUTPUT_FILE" | |
litellm_settings: | |
drop_params: True | |
EOL | |
# 设置 general_settings 和 master_key (可选) | |
# 检查 MASTER_KEY 环境变量是否已设置 | |
if [[ -n "${MASTER_KEY+_}" ]]; then | |
cat <<EOL >>"$OUTPUT_FILE" | |
general_settings: | |
master_key: "$MASTER_KEY" | |
EOL | |
fi | |
echo "生成 $OUTPUT_FILE 成功!" | |
# 运行 litellm 命令 | |
litellm --port 4000 --config /app/litellm-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gemini/gemini-2.0-flash-exp | |
gemini/gemini-2.0-flash-thinking-exp | |
gemini/gemini-1.5-flash-002 | |
gemini/gemini-1.5-flash-001 | |
gemini/gemini-1.5-flash | |
gemini/gemini-1.5-flash-latest | |
gemini/gemini-1.5-flash-8b | |
gemini/gemini-1.5-flash-8b-exp-0924 | |
gemini/gemini-exp-1114 | |
gemini/gemini-exp-1206 | |
gemini/gemini-1.5-flash-exp-0827 | |
gemini/gemini-1.5-flash-8b-exp-0827 | |
gemini/gemini-pro | |
gemini/gemini-1.5-pro | |
gemini/gemini-1.5-pro-002 | |
gemini/gemini-1.5-pro-001 | |
gemini/gemini-1.5-pro-exp-0801 | |
gemini/gemini-1.5-pro-exp-0827 | |
gemini/gemini-1.5-pro-latest | |
gemini/gemini-pro-vision | |
gemini/gemini-gemma-2-27b-it | |
gemini/gemini-gemma-2-9b-it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment