diff --git a/server.js b/server.js index 707527c..f1a3202 100644 --- a/server.js +++ b/server.js @@ -85,6 +85,7 @@ app.delete('/api/messages/clear', async (req, res) => { // 存储连接的客户端和他们的视频流状态 const connectedClients = new Map(); +// 场景轮询系统 // 场景轮询系统 let currentSceneIndex = 0; const scenes = [ @@ -92,19 +93,22 @@ const scenes = [ name: '起床', defaultVideo: '8-4-bd-2.mp4', interactionVideo: '8-4-sh.mp4', - tag: 'wakeup' + tag: 'wakeup', + apiKey: 'bot-20250724150616-xqpz8' // 起床场景的API key }, { name: '开车', - defaultVideo: '8-4-kc-bd.mp4', // 根据您的视频文件调整 + defaultVideo: '8-4-kc-bd.mp4', interactionVideo: '8-4-kc-sh.mp4', - tag: 'driving' + tag: 'driving', + apiKey: 'bot-20250623140339-r8f8b' // 开车场景的API key }, { name: '喝茶', defaultVideo: '8-4-hc-bd.mp4', interactionVideo: '8-4-hc-sh.mp4', - tag: 'tea' + tag: 'tea', + apiKey: 'bot-20250804180724-4dgtk' // 喝茶场景的API key } ]; @@ -167,6 +171,18 @@ app.get('/api/videos', (req, res) => { }); }); +// 获取当前场景信息的API接口 +app.get('/api/current-scene', (req, res) => { + const scene = getCurrentScene(); + res.json({ + name: scene.name, + tag: scene.tag, + apiKey: scene.apiKey, + defaultVideo: scene.defaultVideo, + interactionVideo: scene.interactionVideo + }); +}); + // 获取视频映射 app.get('/api/video-mapping', (req, res) => { // videoMapping = getCurrentScene() @@ -373,4 +389,4 @@ server.listen(PORT, '0.0.0.0', async () => { // 导出消息历史管理器供其他模块使用 module.exports = { messageHistory }; -console.log(`访问 http://localhost:${PORT} 开始使用`); \ No newline at end of file +console.log(`访问 http://localhost:${PORT} 开始使用`); diff --git a/src/chat_with_audio.js b/src/chat_with_audio.js index 990de50..2b6f4b1 100644 --- a/src/chat_with_audio.js +++ b/src/chat_with_audio.js @@ -2,7 +2,7 @@ import { requestLLMStream } from './llm_stream.js'; import { requestMinimaxi } from './minimaxi_stream.js'; -import { getLLMConfig, getMinimaxiConfig, getAudioConfig, validateConfig } from './config.js'; +import { getLLMConfig, getLLMConfigByScene, getMinimaxiConfig, getAudioConfig, validateConfig } from './config.js'; // 防止重复播放的标志 let isPlaying = false; @@ -114,11 +114,14 @@ async function chatWithAudioStream(userInput) { console.log('用户输入:', userInput); - // 获取配置 - const llmConfig = getLLMConfig(); + // 获取当前场景对应的配置 + const llmConfig = await getLLMConfigByScene(); const minimaxiConfig = getMinimaxiConfig(); const audioConfig = getAudioConfig(); + console.log(`当前场景: ${llmConfig.sceneName} (${llmConfig.sceneTag})`); + console.log(`使用API Key: ${llmConfig.model.substring(0, 8)}...`); + // 清空音频队列 audioQueue = []; diff --git a/src/config.js b/src/config.js index 0433660..8aead23 100644 --- a/src/config.js +++ b/src/config.js @@ -70,13 +70,32 @@ export function validateConfig() { } // 获取配置的便捷方法 -export function getLLMConfig() { +export function getLLMConfig(sceneApiKey = null) { return { - apiKey: config.llm.apiKey, - model: config.llm.model, + apiKey: config.llm.apiKey, // 如果提供了场景API key,则使用它 + model: sceneApiKey || config.llm.model, }; } + +// 新增:根据场景获取LLM配置 +export async function getLLMConfigByScene() { + try { + const response = await fetch('/api/current-scene'); + const sceneData = await response.json(); + + return { + apiKey: config.llm.apiKey, + model: sceneData.apiKey, + sceneTag: sceneData.tag, + sceneName: sceneData.name + }; + } catch (error) { + console.warn('获取场景配置失败,使用默认配置:', error); + return getLLMConfig(); // 回退到默认配置 + } +} + export function getMinimaxiConfig() { return { apiKey: config.minimaxi.apiKey, diff --git a/videos/8-4-hc-bd.mp4 b/videos/8-4-hc-bd.mp4 index aed48f7..28b93bc 100644 Binary files a/videos/8-4-hc-bd.mp4 and b/videos/8-4-hc-bd.mp4 differ diff --git a/videos/8-4-sh-3.mp4 b/videos/8-4-sh-3.mp4 new file mode 100644 index 0000000..f10c741 Binary files /dev/null and b/videos/8-4-sh-3.mp4 differ