miguelmj / milua Goto Github PK
View Code? Open in Web Editor NEWLua micro framework for web development
License: MIT License
Lua micro framework for web development
License: MIT License
Hey, awesome project! I have been looking for some really simple web framework to keep learning Lua and found this. And it also looks similar to what I'm used to work with (Flask).
Now my question is, have you ever made any kind of benchmark to compare it with other frameworks? It's just to have an idea of what to expect. Thanks!
Thank you Miguel for created this framework. I need to know how to implement session and cookies for milua?
ports:
- '8080:8080'
requests outside container don't answer
inside all is good
luarocks install milua
use config like example and get error
/app # lua server_start.lua
lua: server_start.lua:2: module 'milua_config' not found:
no field package.preload['milua_config']
no file '/usr/local/share/lua/5.4/milua_config.lua'
no file '/usr/local/share/lua/5.4/milua_config/init.lua'
no file '/usr/local/lib/lua/5.4/milua_config.lua'
no file '/usr/local/lib/lua/5.4/milua_config/init.lua'
no file './milua_config.lua'
no file './milua_config/init.lua'
no file '/usr/local/lib/lua/5.4/milua_config.so'
no file '/usr/local/lib/lua/5.4/loadall.so'
no file './milua_config.so'
stack traceback:
[C]: in function 'require'
server_start.lua:2: in main chunk
[C]: in ?
Hello!
I'm having issues with a Cors error being generated on by browser when I attempt to access Milua using a React client on local host. I'm unable to find any documentation on how to fix this. Any ideas?
This is my current script:
local app = require "milua"
local http = require("socket.http")
local ltn12 = require("ltn12")
local cjson = require("cjson")
local config = dofile("config.lua")
local openaiApiKey = config.openaiApiKey
-- API endpoint
local apiUrl = "https://api.openai.com/v1/chat/completions"
app.add_handler(
"POST",
"/openai",
function(captures, query, headers, body)
if headers["method"] == "OPTIONS" then
return "", 200, {
["Access-Control-Allow-Origin"] = "*", -- Allow requests from any origin
["Access-Control-Allow-Methods"] = "POST, OPTIONS", -- Allow POST and OPTIONS methods
["Access-Control-Allow-Headers"] = "Content-Type, Authorization" -- Allow specified headers
}
end
-- Parse JSON from the request body
local requestData = {
model = "gpt-3.5-turbo",
messages = {{role = "user", content = cjson.decode(body).content}},
temperature = 0.7
}
print("Request:", requestData)
-- Convert Lua table to JSON
local requestBody = cjson.encode(requestData)
print("RequestBB:", requestBody)
-- Request headers
local requestHeaders = {
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. openaiApiKey
}
-- Perform HTTP request
local response = {}
local _, statusCode, _, _ = http.request{
url = apiUrl,
method = "POST",
headers = requestHeaders,
source = ltn12.source.string(requestBody),
sink = ltn12.sink.table(response)
}
-- Check the response
if statusCode == 200 then
print("Made it here!")
local responseBody = table.concat(response)
print("responseBody", responseBody)
return responseBody
else
return "Error"
end
end
)
app.start()
The error message I get:
My client is just doing a POST via axios:
const response = await axios.post("http://localhost:8800/openai", {
content: input,
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.