local thing = [[ok?]]
local encoded = thing:gsub(".", function(bb) return "//" .. bb:byte() end) or thing .. "/"
print(encoded)
local http = require("socket.http")
local json = require("json")
-- Set up the HTTP request
local url = "https://api.openai.com/v1/engines/davinci-codex/completions"
local headers = {
["Content-Type"] = "application/json",
["Authorization"] = "Bearer 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"
}
local body = {
prompt = "Hello, how are you?",
max_tokens = 50,
temperature = 0.7
}
local json_body = json.encode(body)
-- Send the HTTP request
local response_body = {}
local res, status = http.request {
url = url,
method = "POST",
headers = headers,
source = ltn12.source.string(json_body),
sink = ltn12.sink.table(response_body)
}
-- Parse the JSON response
if status == 200 then
local response = json.decode(table.concat(response_body))
local message = response.choices[1].text
print(message)
else
print("Error: " .. status)
end