GithubHelp home page GithubHelp logo

milua's Issues

Benchmark

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!

Session and cookies

Thank you Miguel for created this framework. I need to know how to implement session and cookies for milua?

module 'milua_config' not found:

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 ?

Cors Error

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:

image

My client is just doing a POST via axios:

const response = await axios.post("http://localhost:8800/openai", {
        content: input,
      });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.