场景人设切换
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 2m30s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 2m30s
				
			This commit is contained in:
		
							parent
							
								
									c96c49ff3f
								
							
						
					
					
						commit
						9d4bbc182c
					
				
							
								
								
									
										24
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								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()
 | ||||
|  | ||||
| @ -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 = []; | ||||
|      | ||||
|  | ||||
| @ -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, | ||||
|  | ||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								videos/8-4-sh-3.mp4
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								videos/8-4-sh-3.mp4
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Song367
						Song367