finyx_data_ai/configure_siliconflow.sh
2026-01-11 07:48:19 +08:00

75 lines
2.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 硅基流动 API Key 配置辅助脚本
echo "========================================="
echo "硅基流动 API Key 配置助手"
echo "========================================="
echo ""
# 检查当前配置
CURRENT_KEY=$(grep "^SILICONFLOW_API_KEY=" .env 2>/dev/null | cut -d'=' -f2 | tr -d ' ')
if [ -z "$CURRENT_KEY" ] || [ "$CURRENT_KEY" = "" ]; then
echo "❌ 当前状态: API Key 未配置"
echo ""
echo "请按照以下步骤配置:"
echo ""
echo "1. 获取 API Key:"
echo " 访问 https://siliconflow.cn 获取您的 API Key"
echo ""
echo "2. 编辑 .env 文件:"
echo " nano .env"
echo " 或"
echo " vim .env"
echo ""
echo "3. 找到这一行:"
echo " SILICONFLOW_API_KEY="
echo ""
echo "4. 在等号后面添加您的 API Key例如:"
echo " SILICONFLOW_API_KEY=sk-xxxxxxxxxxxxx"
echo ""
echo "5. 保存文件后,运行以下命令重启服务:"
echo " ./restart_service.sh"
echo ""
read -p "您已经添加了 API Key 吗?(y/n): " confirmed
if [ "$confirmed" = "y" ] || [ "$confirmed" = "Y" ]; then
echo ""
echo "正在验证配置..."
source venv/bin/activate
python3 -c "
from app.core.config import settings
key = settings.SILICONFLOW_API_KEY
if key and key.strip():
print(f'✅ API Key 已配置 (长度: {len(key)})')
print(f'✅ 配置验证成功!')
else:
print('❌ API Key 仍然未配置')
print('请确认:')
print(' 1. 已编辑 .env 文件(不是 .env.example')
print(' 2. API Key 已正确填写在等号后面')
print(' 3. 已保存文件')
" 2>&1
else
echo ""
echo "请先添加 API Key 后再运行此脚本"
fi
else
echo "✅ 当前状态: API Key 已配置"
echo ""
echo "验证配置加载..."
source venv/bin/activate
python3 -c "
from app.core.config import settings
key = settings.SILICONFLOW_API_KEY
print(f'✅ API Key 长度: {len(key)}')
print(f'✅ Base URL: {settings.SILICONFLOW_BASE_URL}')
print(f'✅ 默认模型: {settings.SILICONFLOW_MODEL}')
print('')
print('配置验证成功!可以重启服务进行测试。')
" 2>&1
fi
echo ""
echo "========================================="