diff --git a/backend/services/bot_service.py b/backend/services/bot_service.py index 457163d..ce30471 100644 --- a/backend/services/bot_service.py +++ b/backend/services/bot_service.py @@ -424,6 +424,7 @@ def serialize_bot_detail(bot: BotInstance) -> Dict[str, Any]: "image_tag": bot.image_tag, "llm_provider": runtime["llm_provider"], "llm_model": runtime["llm_model"], + "api_key": runtime["api_key"], "api_base": runtime["api_base"], "temperature": runtime["temperature"], "top_p": runtime["top_p"], diff --git a/download_model.sh b/download_model.sh new file mode 100755 index 0000000..6561c93 --- /dev/null +++ b/download_model.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +# ========================================== +# Whisper ggml 模型下载脚本 +# 下载的模型将存放在 data/model 目录下 +# ========================================== + +# 确保在项目根目录运行 +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +TARGET_DIR="${SCRIPT_DIR}/data/model" + +# 创建目标目录 +mkdir -p "$TARGET_DIR" + +# Hugging Face 的 whisper.cpp 模型仓库地址 +# 使用 hf-mirror 镜像加速国内下载 +BASE_URL="https://hf-mirror.com/ggerganov/whisper.cpp/resolve/main" + +echo "==========================================" +echo "请选择要下载的 Whisper 语音识别模型:" +echo "1) tiny (最小,速度最快,约 40MB)" +echo "2) base (基础,速度快,约 74MB)" +echo "3) small (当前默认,平衡,约 240MB)" +echo "4) medium (推荐,效果更好,约 770MB)" +echo "5) large-v3 (最大,效果最好,约 1.5GB)" +echo "==========================================" + +read -p "请输入对应的数字 [1-5,默认 4]: " choice + +MODEL_NAME="" +case $choice in + 1) MODEL_NAME="ggml-tiny-q8_0.bin" ;; + 2) MODEL_NAME="ggml-base-q8_0.bin" ;; + 3) MODEL_NAME="ggml-small-q8_0.bin" ;; + 4|"") MODEL_NAME="ggml-medium-q8_0.bin" ;; + 5) MODEL_NAME="ggml-large-v3-q8_0.bin" ;; + *) + echo "无效的选择,使用默认选项 4 (medium)" + MODEL_NAME="ggml-medium-q8_0.bin" + ;; +esac + +echo "" +echo "准备下载模型: $MODEL_NAME" +echo "保存路径: $TARGET_DIR/$MODEL_NAME" +echo "" + +# 下载文件 +DOWNLOAD_URL="${BASE_URL}/${MODEL_NAME}" + +if command -v wget >/dev/null 2>&1; then + echo "使用 wget 下载中..." + wget -c --show-progress "$DOWNLOAD_URL" -O "$TARGET_DIR/$MODEL_NAME" +elif command -v curl >/dev/null 2>&1; then + echo "使用 curl 下载中..." + curl -L -C - -o "$TARGET_DIR/$MODEL_NAME" "$DOWNLOAD_URL" +else + echo "错误:找不到 wget 或 curl 命令,无法下载文件。" + exit 1 +fi + +if [ $? -eq 0 ]; then + echo "" + echo "✅ 下载成功!" + echo "模型文件已保存到: $TARGET_DIR/$MODEL_NAME" + echo "" + echo "请记得更新 .env.prod 或 backend/.env 文件中的配置:" + echo "STT_MODEL=$MODEL_NAME" + echo "修改后重启后端容器即可生效。" +else + echo "" + echo "❌ 下载失败,请检查网络连接或稍后重试。" + exit 1 +fi diff --git a/frontend/src/i18n/app.zh-cn.ts b/frontend/src/i18n/app.zh-cn.ts index ad106d9..e1146d1 100644 --- a/frontend/src/i18n/app.zh-cn.ts +++ b/frontend/src/i18n/app.zh-cn.ts @@ -1,5 +1,5 @@ export const appZhCn = { - title: 'Nanobot 管理面板', + title: 'Unisbot 管理面板', theme: '主题', language: '语言', dark: '深色', diff --git a/frontend/src/i18n/dashboard.en.ts b/frontend/src/i18n/dashboard.en.ts index f721077..688726f 100644 --- a/frontend/src/i18n/dashboard.en.ts +++ b/frontend/src/i18n/dashboard.en.ts @@ -69,7 +69,7 @@ export const dashboardEn = { feedbackSaveFail: 'Failed to save feedback.', feedbackMessagePending: 'Message is not synced yet. Please retry in a moment.', sendFailMsg: (msg: string) => `Command delivery failed: ${msg}`, - providerRequired: 'Set provider/model/new API key before testing.', + providerRequired: 'Set provider/model/API key before testing.', connOk: (preview: string) => (preview ? `Connection passed, models: ${preview}` : 'Connection passed'), connFail: (msg: string) => `Failed: ${msg}`, configUpdated: 'Configuration updated (effective after bot restart).', @@ -265,8 +265,8 @@ export const dashboardEn = { baseImageReadonly: 'Base Image', modelName: 'Model Name', modelNamePlaceholder: 'e.g. qwen-plus', - newApiKey: 'New API Key (optional)', - newApiKeyPlaceholder: 'Only updated when filled', + newApiKey: 'API Key', + newApiKeyPlaceholder: 'Enter API key', testing: 'Testing...', testModelConnection: 'Test model connection', cancel: 'Cancel', diff --git a/frontend/src/i18n/dashboard.zh-cn.ts b/frontend/src/i18n/dashboard.zh-cn.ts index d807992..77b2d6d 100644 --- a/frontend/src/i18n/dashboard.zh-cn.ts +++ b/frontend/src/i18n/dashboard.zh-cn.ts @@ -69,7 +69,7 @@ export const dashboardZhCn = { feedbackSaveFail: '反馈保存失败。', feedbackMessagePending: '消息尚未同步,暂不可反馈。', sendFailMsg: (msg: string) => `指令发送失败:${msg}`, - providerRequired: '请填写 Provider、模型和新 API Key 后再测试。', + providerRequired: '请填写 Provider、模型和 API Key 后再测试。', connOk: (preview: string) => (preview ? `连接成功,模型: ${preview}` : '连接成功'), connFail: (msg: string) => `连接失败: ${msg}`, configUpdated: '配置已更新(重启 Bot 后生效)。', @@ -265,8 +265,8 @@ export const dashboardZhCn = { baseImageReadonly: '基础镜像', modelName: '模型名称', modelNamePlaceholder: '如 qwen-plus', - newApiKey: '新的 API Key(留空不更新)', - newApiKeyPlaceholder: '输入新 Key 才会更新', + newApiKey: 'API Key', + newApiKeyPlaceholder: '输入 API Key', testing: '测试中...', testModelConnection: '测试模型连接', cancel: '取消', diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index b4f2645..1fc8d97 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -1,11 +1,14 @@ import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' +import axios from 'axios' import './index.css' import App from './App.tsx' import { LucentPromptProvider } from './components/lucent/LucentPromptProvider.tsx' import { setupBotAccessAuth } from './utils/botAccess.ts' import { setupPanelAccessAuth } from './utils/panelAccess.ts' +axios.defaults.withCredentials = true + setupPanelAccessAuth(); setupBotAccessAuth(); diff --git a/frontend/src/modules/dashboard/hooks/useDashboardBotEditor.ts b/frontend/src/modules/dashboard/hooks/useDashboardBotEditor.ts index 9fd7345..1b3cc0e 100644 --- a/frontend/src/modules/dashboard/hooks/useDashboardBotEditor.ts +++ b/frontend/src/modules/dashboard/hooks/useDashboardBotEditor.ts @@ -97,7 +97,7 @@ export function useDashboardBotEditor({ llm_provider: provider, llm_model: bot.llm_model || '', image_tag: bot.image_tag || '', - api_key: '', + api_key: bot.api_key || '', api_base: bot.api_base || '', temperature: clampTemperature(bot.temperature ?? 0.2), top_p: bot.top_p ?? 1, diff --git a/frontend/src/types/bot.ts b/frontend/src/types/bot.ts index 1188c3b..131a6e0 100644 --- a/frontend/src/types/bot.ts +++ b/frontend/src/types/bot.ts @@ -28,6 +28,7 @@ export interface BotState { image_tag?: string; llm_provider?: string; llm_model?: string; + api_key?: string; api_base?: string; temperature?: number; top_p?: number;