一个静态页面接入科大讯飞3.5AI
静态文件html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>体验-大模型</title> </head> <body> <div class="chat-bot"> <div class="chat-bot-header"> <img src="./qwen.png" alt="Logo" class="logo"/> 测试页面 </div> <div id="output_text" class="chat-bot-messages"></div> <div class="chat-bot-input"> <input id="input_text" type="text" placeholder="输入你想问的问题"/> <button id="audio-ctrl-btn">Send</button> </div> </div> </body> </html>
获取科大讯飞最新的websocket接口地址
function getWebsocketUrl() { // console.log(httpUrl.pathname) // 动态获取domain信息 switch (httpUrl.pathname) { case "/v1.1/chat": modelDomain = "general"; break; case "/v2.1/chat": modelDomain = "generalv2"; break; case "/v3.1/chat": modelDomain = "generalv3"; break; case "/v3.5/chat": modelDomain = "generalv3.5"; break; } return new Promise((resolve, reject) => { var apiKey = API_KEY var apiSecret = API_SECRET var url = 'wss://' + httpUrl.host + httpUrl.pathname // console.log("我打印的" + httpUrl.host) // console.log("我打印的" + httpUrl.pathname) var host = location.host var date = new Date().toGMTString() var algorithm = 'hmac-sha256' var headers = 'host date request-line' var signatureOrigin = `host: ${host}\ndate: ${date}\nGET ${httpUrl.pathname} HTTP/1.1` var signatureSha = CryptoJS.HmacSHA256(signatureOrigin, apiSecret) var signature = CryptoJS.enc.Base64.stringify(signatureSha) var authorizationOrigin = `api_key="${apiKey}", algorithm="${algorithm}", headers="${headers}", signature="${signature}"` var authorization = btoa(authorizationOrigin) url = `${url}?authorization=${authorization}&date=${date}&host=${host}` resolve(url) }) }
代码地址:https://gitee.com/m1v/xfyun_spark_demo.git
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步