I'm trying to use nio.process.run to run a curl command and read the output of curl from stdout.
The code to read stdout is:
while true do
print("enter loop")
local chunk = response.stdout.read(1024)
print("get chunk from response")
end
I added logs before and after it
my test code:
local nio = require("nio")
local messages = {
{ role = "user", content = "hello" },
}
local body = {
stream = true,
max_tokens = 512,
messages = messages,
}
local ACCOUNT = os.getenv("ACCOUNT")
local KEY = os.getenv("KEY")
local MODEL = "@cf/google/gemma-7b-it-lora"
nio.run(function()
local response = nio.process.run({
cmd = "curl",
args = {
string.format("https://api.cloudflare.com/client/v4/accounts/%s/ai/run/%s", ACCOUNT, MODEL),
"-N",
"-X",
"POST",
"-H",
"Content-Type: application/json",
"-H",
"Authorization: Bearer " .. KEY,
"-d",
vim.fn.json_encode(body),
},
})
while true do
print("enter loop")
local chunk = response.stdout.read(1024)
print("get chunk from response")
if not chunk then
print("chunk is nil")
break
end
print(chunk)
end
end)
my output:
enter loop
Why does my program get stuck at local chunk = response.stdout.read(1024)
I'm trying to use
nio.process.run
to run a curl command and read the output of curl from stdout.The code to read stdout is:
I added logs before and after it
my test code:
my output:
Why does my program get stuck at
local chunk = response.stdout.read(1024)
This shell command is correct.
env: