import axios from 'axios'; class ApiService { constructor() { this.baseUrl = '/create-api'; // Using Vite proxy instead of direct URL this.projectId = '01a1debc964a4c6a8df1de2a6ce7aa4d'; this.authToken = 'Basic OGRkM2EzOGUxNTJjNGU1NDlmNWMwOTg0YmRhYzc1ZTE6ZWY1MTI2ZTRmMWFlNGE5MWE0MzVhN2Q0ZDc0YzNlYjg='; // Set the auth token this.sessionId = null; this.client = axios.create({ headers: { 'Content-Type': 'application/json', 'Authorization': this.authToken }, withCredentials: true }); } /** * Set the authentication token * @param {string} token - The authentication token */ setAuthToken(token) { this.authToken = token; this.client.defaults.headers.common['Authorization'] = token; } /** * Join a project to start a conversation * @param {string} channelName - The channel name * @param {string} agentRtcUid - The agent RTC UID * @returns {Promise} - The response from the API */ async joinProject(channelName = 'convaiconsole_122624', agentRtcUid = '29501') { try { const response = await this.client.post( `${this.baseUrl}/projects/${this.projectId}/join/`, { "name": "convaiconsole_116347", "properties": { "channel": "convaiconsole_116347", "agent_rtc_uid": "87578", "remote_rtc_uids": [ "*" ], "enable_string_uid": true, "idle_timeout": 120, "llm": { "url": "https://vip.apiyi.com/v1/chat/completions", "api_key": "sk-xVIc9b7EfY7LlPagF31d90F4736f4aE18cB91b5957A40506", "max_history": 10, "system_messages": [ { "role": "system", "content": "" } ], "params": { "model": "deepseek-r1", "max_token": 1024 }, "greeting_message": "你好呀,有什么可以帮您?", "failure_message": "我出错了,请稍等!" }, "asr": { "language": "zh-CN" }, "vad": { "interrupt_duration_ms": 160, "prefix_padding_ms": 300, "silence_duration_ms": 480, "threshold": 0.5 }, "tts": { "vendor": "bytedance", "params": { "token": "wN-fMujjNdcwJ2M3-MbhMHSF6-j_3dT3", "app_id": "4417529362", "cluster": "volcano_tts", "voice_type": "BV700_streaming", "speed_ratio": 1, "volume_ratio": 1, "pitch_ratio": 1, "emotion": "" } }, "parameters": { "transcript": { "enable": true, "protocol_version": "v2", "enable_words": false, "redundant": false }, "enable_metrics": true, "audio_scenario": "default" }, "token": "007eJxTYOhQ/af5fwa3YP9mzYq4WWxKco1TJJqEC9L6z39c0cf2xkuBwcAw0TAlNSnZ0swk0STZLNEiJQ3IN0o0S041T0w0SQk0u5veEMjIwFi9lhFIgiGIL8KQnJ9XlpgJJIvzc1LjDQ3NjE3MGRgACCIjzA==", "advanced_features": { "enable_aivad": false } } } ); this.sessionId = response.data.session_id; return response.data; } catch (error) { console.error('Error joining project:', error); throw error; } } /** * End the current session * @returns {Promise} - The response from the API */ async endSession() { if (!this.sessionId) { return null; } try { const response = await this.client.delete( `${this.baseUrl}/sessions/${this.sessionId}/` ); this.sessionId = null; return response.data; } catch (error) { console.error('Error ending session:', error); throw error; } } } export default new ApiService();