Browse Source

更新 target/aliyun/ai.lua

1585346868 2 months ago
parent
commit
64ffad1a52
1 changed files with 6 additions and 3 deletions
  1. 6 3
      target/aliyun/ai.lua

+ 6 - 3
target/aliyun/ai.lua

@@ -5,12 +5,15 @@ local cjson = require("cjson")
 local M = {}
 local url = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"
 
-M.ask = function(key,content,model)
+M.ask = function(key,content,model,is_json)
     -- 构造 JSON 格式的请求数据
     local payload = {
         model = model,
-        messages = content
-    }
+        messages = content,
+    } 
+    if is_json ~= nil and is_json == true then
+        payload["response_format"] = {type = "json_object"}
+    end
     local response_body = {}
 
     local res, code, response_headers, status = http.request{