Browse Source

修复了一些bug

Pchen 1 year ago
parent
commit
414cd56b21
3 changed files with 37 additions and 35 deletions
  1. 14 14
      API/tongyi.js
  2. 16 16
      API/xunfei.js
  3. 7 5
      README.md

+ 14 - 14
API/tongyi.js

@@ -21,14 +21,14 @@ function getConfigValue(configName) {
 // 读取配置信息并设置相应的变量
 // 读取配置信息并设置相应的变量
 async function loadConfigValues() {
 async function loadConfigValues() {
     try {
     try {
-        apiKey = await getConfigValue('apiKey')
-        apiUrl = await getConfigValue('apiUrl')
-        maxTokensStr = await getConfigValue('max_tokens')
-        temperatureStr = await getConfigValue('temperature')
-        model = await getConfigValue('model')
-        presets = await getConfigValue('presets')
-        temperature = parseFloat(temperatureStr)
-        max_tokens = parseInt(maxTokensStr)
+        ty_apiKey = await getConfigValue('apiKey')
+        ty_apiUrl = await getConfigValue('apiUrl')
+        ty_maxTokensStr = await getConfigValue('max_tokens')
+        ty_temperatureStr = await getConfigValue('temperature')
+        ty_model = await getConfigValue('model')
+        ty_presets = await getConfigValue('presets')
+        ty_temperature = parseFloat(ty_temperatureStr)
+        ty_max_tokens = parseInt(ty_maxTokensStr)
     } catch (error) {
     } catch (error) {
         console.error('加载通义api接口设置失败!', error)
         console.error('加载通义api接口设置失败!', error)
     }
     }
@@ -39,23 +39,23 @@ loadConfigValues()
 
 
 async function getTYMessage(message) {
 async function getTYMessage(message) {
     const requestData = {
     const requestData = {
-        model: model,
+        model: ty_model,
         input: {
         input: {
             messages: [
             messages: [
-                { "role": "system", "content": presets },
+                { "role": "system", "content": ty_presets },
                 { "role": "user", "content": message }
                 { "role": "user", "content": message }
             ],
             ],
         },
         },
         parameters: {
         parameters: {
-            max_tokens: max_tokens,
-            temperature: temperature
+            max_tokens: ty_max_tokens,
+            temperature: ty_temperature
         }
         }
     }
     }
 
 
-    const token = "Bearer " + apiKey
+    const token = "Bearer " + ty_apiKey
 
 
     try {
     try {
-        const responseData = await axios.post(apiUrl, requestData, {
+        const responseData = await axios.post(ty_apiUrl, requestData, {
             headers: { 'Content-Type': 'application/json', Authorization: token }
             headers: { 'Content-Type': 'application/json', Authorization: token }
         })
         })
 
 

+ 16 - 16
API/xunfei.js

@@ -25,15 +25,15 @@ function getConfigValue(configName) {
 // 读取配置信息并设置相应的变量
 // 读取配置信息并设置相应的变量
 async function loadConfigValues() {
 async function loadConfigValues() {
     try {
     try {
-        url = await getConfigValue('APIUrl')
-        APIKey = await getConfigValue('APIKey')
-        APISecret = await getConfigValue('APISecret')
-        app_id = await getConfigValue('app_id')
-        temperatureStr = await getConfigValue('temperature')
-        maxTokensStr = await getConfigValue('max_tokens')
-        domain = await getConfigValue('domain')
-        temperature = parseFloat(temperatureStr)
-        max_tokens = parseInt(maxTokensStr)
+        xf_url = await getConfigValue('APIUrl')
+        xf_APIKey = await getConfigValue('APIKey')
+        xf_APISecret = await getConfigValue('APISecret')
+        xf_app_id = await getConfigValue('app_id')
+        xf_temperatureStr = await getConfigValue('temperature')
+        xf_maxTokensStr = await getConfigValue('max_tokens')
+        xf_domain = await getConfigValue('domain')
+        xf_temperature = parseFloat(xf_temperatureStr)
+        xf_max_tokens = parseInt(xf_maxTokensStr)
     } catch (error) {
     } catch (error) {
         console.error('加载讯飞接口设置失败!', error)
         console.error('加载讯飞接口设置失败!', error)
     }
     }
@@ -51,7 +51,7 @@ async function loadConfigValues() {
 async function getXunfeiMessage(message) {
 async function getXunfeiMessage(message) {
 
 
     const dateString = new Date().toGMTString()
     const dateString = new Date().toGMTString()
-    const parsedUrl = new URL(url)
+    const parsedUrl = new URL(xf_url)
 
 
     const host = parsedUrl.hostname
     const host = parsedUrl.hostname
     const path = parsedUrl.pathname
     const path = parsedUrl.pathname
@@ -60,12 +60,12 @@ async function getXunfeiMessage(message) {
 date: ${dateString}
 date: ${dateString}
 GET ${path} HTTP/1.1`
 GET ${path} HTTP/1.1`
 
 
-    let signature = crypto.createHmac('sha256', APISecret)
+    let signature = crypto.createHmac('sha256', xf_APISecret)
         .update(tmp)
         .update(tmp)
         .digest('base64')
         .digest('base64')
 
 
     const authorization_origin =
     const authorization_origin =
-        `api_key="${APIKey}", algorithm="hmac-sha256", headers="host date request-line", signature="${signature}"`
+        `api_key="${xf_APIKey}", algorithm="hmac-sha256", headers="host date request-line", signature="${signature}"`
 
 
     let buff = Buffer.from(authorization_origin)
     let buff = Buffer.from(authorization_origin)
     const authorization = buff.toString('base64')
     const authorization = buff.toString('base64')
@@ -79,13 +79,13 @@ GET ${path} HTTP/1.1`
         sock.on("open", function () {
         sock.on("open", function () {
             sock.send(JSON.stringify({
             sock.send(JSON.stringify({
                 "header": {
                 "header": {
-                    "app_id": app_id,
+                    "app_id": xf_app_id,
                 },
                 },
                 "parameter": {
                 "parameter": {
                     "chat": {
                     "chat": {
-                        "domain": domain,
-                        "temperature": temperature,
-                        "max_tokens": max_tokens,
+                        "domain": xf_domain,
+                        "temperature": xf_temperature,
+                        "max_tokens": xf_max_tokens,
                     }
                     }
                 },
                 },
                 "payload": {
                 "payload": {

+ 7 - 5
README.md

@@ -30,21 +30,23 @@
 WebWechatBot                            
 WebWechatBot                            
 ├─ API                                  
 ├─ API                                  
 │  ├─ ChatGPT.js                        
 │  ├─ ChatGPT.js                        
+│  ├─ tongyi.js                         
 │  └─ xunfei.js                         
 │  └─ xunfei.js                         
 ├─ db                                   
 ├─ db                                   
-│  └─ data.db                                                  ├─ public                               
-│  ├─ css                                
-│  ├─ js                                
+│  └─ data.db                           
+├─ public                               
+│  ├─ css                                 
+│  ├─ js                                              
 │  └─ index.html                        
 │  └─ index.html                        
 ├─ wechat                               
 ├─ wechat                               
-│  ├─ avatar                                               
+│  ├─ avatar                                              
 │  └─ main.js                           
 │  └─ main.js                           
 ├─ app.js                               
 ├─ app.js                               
 ├─ config.js                            
 ├─ config.js                            
+├─ LICENSE                              
 ├─ package.json                         
 ├─ package.json                         
 ├─ README.md                            
 ├─ README.md                            
 └─ router.js                            
 └─ router.js                            
-		
 ```
 ```