This commit is contained in:
NH
2026-02-21 19:26:14 +08:00
parent 9b6ad33cf9
commit 9dd5a02c88
5 changed files with 99 additions and 10 deletions

View File

@@ -30,6 +30,32 @@ M.ask = function(key,content,model)
return false, "请求失败,错误描述:" .. table.concat(response_body)
end
end
M.ask_local = function(url,content,model)
-- 构造 JSON 格式的请求数据
local payload = {
model = model,
messages = content,
stream = false
}
local response_body = {}
local res, code, response_headers, status = http.request{
url = url,
method = "POST",
headers = {
["Content-Type"] = "application/json",
},
source = ltn12.source.string(cjson.encode(payload)),
sink = ltn12.sink.table(response_body)
}
if code == 200 then
print(table.concat(response_body))
local data = cjson.decode(table.concat(response_body))
return true,{content = data.message.content}
else
return false, "请求失败,错误描述:" .. table.concat(response_body)
end
end
return M

View File

@@ -38,7 +38,13 @@ M.ext_dirpath = {
"xls",
"xlsx",
"ppt",
"pptx"
"pptx",
"txt",
"json",
"xml",
"html",
"css",
"js",
}
}

36
target/deepseek/ai.lua Normal file
View File

@@ -0,0 +1,36 @@
local http = require("socket.http")
local ltn12 = require("ltn12")
local cjson = require("cjson")
local M = {}
local url = "https://api.deepseek.com/chat/completions"
M.ask = function(key,content,model)
-- 构造 JSON 格式的请求数据
local payload = {
model = model,
messages = content
}
local response_body = {}
local res, code, response_headers, status = http.request{
url = url,
method = "POST",
headers = {
["Authorization"] = "Bearer " .. key,
["Content-Type"] = "application/json",
},
source = ltn12.source.string(cjson.encode(payload)),
sink = ltn12.sink.table(response_body)
}
if code == 200 then
local data = cjson.decode(table.concat(response_body))
return true,{content = data.choices[1].message.content}
else
return false, "请求失败,错误描述:" .. table.concat(response_body)
end
end
return M

View File

@@ -2,13 +2,31 @@ require("fwutils.webapi")
local M = {}
M.add = function(file_size,filepath,desc,conn)
local ppst = conn:setsql("INSERT INTO fw_file (role_id,custom_id,file_size,filepath,`desc`) VALUES (?,?,?,?,?)")
local user_data = cjson.decode(request.get("user_data"))
ppst:set_i32(1,user_data.role_id)
ppst:set_i32(2,user_data.id)
ppst:set_i64(3,file_size)
ppst:set_str(4,filepath)
ppst:set_str(5,desc)
local sql = ""
local user_data = request.get("user_data")
if user_data ~= nil and user_data ~= "" then
sql = "INSERT INTO fw_file (role_id,custom_id,file_size,filepath,`desc`) VALUES (?,?,?,?,?)"
user_data = cjson.decode(user_data)
else
user_data = nil
sql = "INSERT INTO fw_file (file_size,filepath,`desc`) VALUES (?,?,?)"
end
local ppst = conn:setsql(sql)
if user_data ~= nil then
ppst:set_i32(1,user_data.role_id)
ppst:set_i32(2,user_data.id)
ppst:set_i64(3,file_size)
ppst:set_str(4,filepath)
ppst:set_str(5,desc)
else
ppst:set_i64(1,file_size)
ppst:set_str(2,filepath)
ppst:set_str(3,desc)
end
if ppst:update() == 1 then
return true
end

View File

@@ -1,11 +1,12 @@
local http = require("socket.http")
local ltn12 = require("ltn12")
local cjson = require("cjson")
require("app.app")
local M = {}
M.timeout = 60*5
M.get = function(url,headers)
http.TIMEOUT = M.timeout
local response_body = {}
local res, status_code, response_headers, status_text = http.request{
url = url,
@@ -24,6 +25,7 @@ M.get = function(url,headers)
end
M.post = function(url,headers,body)
http.TIMEOUT = M.timeout
local response_body = {}
headers["Content-Length"] = tostring(#body)
local res, status_code, response_headers, status_text = http.request{
@@ -42,6 +44,7 @@ M.post = function(url,headers,body)
return true,table.concat(response_body)
end
M.delete = function(url,headers)
http.TIMEOUT = M.timeout
local response_body = {}
local res, status_code, response_headers, status_text = http.request{
url = url,