From 006aa04a7f52acde547919b974654d96a37f2bf6 Mon Sep 17 00:00:00 2001 From: libingxiang Date: Mon, 15 Jun 2026 16:29:09 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=99=E6=B8=AF=E6=95=B0=E5=AD=97=E4=BA=BA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yaml | 6 ++-- src/App.vue | 12 +++---- src/hooks/useDigitalHuman.ts | 2 +- src/hooks/useLLM.ts | 62 ++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 11 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 10de8be..7ba11bf 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -35,12 +35,12 @@ jobs: uses: https://gitea.yantootech.com/neil/build-push-action@v6 with: push: true - tags: hub.kce.ksyun.com/yantoo/yantoo-repository/baidu-digital-human-app:${{ gitea.run_id }} + tags: hub.kce.ksyun.com/yantoo/yantoo-repository/xg-digital-human-app:${{ gitea.run_id }} - name: Install run: | - helm upgrade --install baidu-digital-human-app ./.gitea/charts \ + helm upgrade --install xg-digital-human-app ./.gitea/charts \ --namespace digital-human-prod \ --create-namespace \ - --set image.repository=hub.kce.ksyun.com/yantoo/yantoo-repository/baidu-digital-human-app \ + --set image.repository=hub.kce.ksyun.com/yantoo/yantoo-repository/xg-digital-human-app \ --set image.tag=${{ gitea.run_id }} - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/src/App.vue b/src/App.vue index fa1e920..514cf25 100644 --- a/src/App.vue +++ b/src/App.vue @@ -465,7 +465,7 @@ import SubtitlePanel from "@/components/SubtitlePanel.vue"; import { useDigitalHuman } from "@/hooks/useDigitalHuman"; import { useLLM } from "@/hooks/useLLM"; -const { sendToLLM } = useLLM(); +const { sendToChatBase } = useLLM(); const { isConnected, @@ -522,23 +522,21 @@ const hasSubstantialContent = (text: string): boolean => { async function handleVoiceQueryComplete(text: string) { if (!text.trim() || !hasSubstantialContent(text)) return; try { - const reply = await sendToLLM(text); + const reply = await sendToChatBase(text); if (reply) { textRender(reply); } else { - // LLM返回空回复,恢复空闲状态 - setPickPhase("idle", "LLM返回空回复"); + setPickPhase("idle", "ChatBase返回空回复"); if (audioMode.value === "rtc") { changeMicrophoneState(false); } } } catch (err: any) { - // LLM请求失败,恢复空闲状态 - setPickPhase("idle", "LLM请求失败"); + setPickPhase("idle", "ChatBase请求失败"); if (audioMode.value === "rtc") { changeMicrophoneState(false); } - ElMessage.error(`大模型请求失败: ${err.message || "未知错误"}`); + ElMessage.error(`ChatBase请求失败: ${err.message || "未知错误"}`); } } diff --git a/src/hooks/useDigitalHuman.ts b/src/hooks/useDigitalHuman.ts index 0e5d37a..582bd85 100644 --- a/src/hooks/useDigitalHuman.ts +++ b/src/hooks/useDigitalHuman.ts @@ -7,7 +7,7 @@ import { TokenManager } from "@/utils/tokenManager"; import type { ChatMessage, SubtitleMode } from "@/types"; const DEFAULT_TEXT = - "你好,我是东航小云,请问有什么需要帮忙的吗?"; + "你好,我是GP超霸博士,请问有什么需要帮忙的吗?"; const OPENING_TTS_DELAY_MS = 200; const SILENCE_TIMEOUT_MS = 5000; // 最短有效语音时长(秒),低于此时长视为无效输入 diff --git a/src/hooks/useLLM.ts b/src/hooks/useLLM.ts index 045137d..6327b60 100644 --- a/src/hooks/useLLM.ts +++ b/src/hooks/useLLM.ts @@ -5,11 +5,21 @@ const LLM_API_URL = "https://ai.yantootech.com/polyhedron/api/ark/chat/completions"; const DEFAULT_MODEL = "bot-20260605135355-68pth"; +// ChatBase API 配置 +const CHATBASE_API_URL = "https://www.chatbase.co/api/v1/chat"; +const CHATBASE_API_KEY = "ca4616db-417c-4dce-8c65-b9909621f53e"; +const CHATBASE_CHATBOT_ID = "TRIe58TuVExBm6K0HKTfz"; + interface LLMMessage { role: "system" | "user" | "assistant"; content: string; } +interface ChatBaseMessage { + content: string; + role: "user"; +} + interface LLMChoice { index: number; message: { @@ -105,11 +115,63 @@ export function useLLM() { conversationHistory.value = []; }; + const sendToChatBase = async (userMessage: string): Promise => { + if (!userMessage.trim()) return ""; + + isLoading.value = true; + error.value = ""; + + try { + const messages: ChatBaseMessage[] = [ + { content: userMessage, role: "user" }, + ]; + + const response = await fetch(CHATBASE_API_URL, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${CHATBASE_API_KEY}`, + }, + body: JSON.stringify({ + messages, + chatbotId: CHATBASE_CHATBOT_ID, + }), + }); + + if (!response.ok) { + throw new Error(`HTTP错误: ${response.status}`); + } + + const data = await response.json(); + const aiReply = data.text || ""; + + conversationHistory.value.push({ + role: "user", + content: userMessage, + }); + + conversationHistory.value.push({ + role: "assistant", + content: aiReply, + }); + + return aiReply; + } catch (err: any) { + const errorMsg = err.message || "请求失败"; + error.value = errorMsg; + console.error("ChatBase请求错误:", err); + throw err; + } finally { + isLoading.value = false; + } + }; + return { isLoading, error, conversationHistory, sendToLLM, + sendToChatBase, clearHistory, }; }