Greetings.
How can I execute a command using the new HTTPReq object, equivalent to this one (using curl)?
curl http://localhost:11434/api/generate -d '{
"model": "llama3",
"prompt": "Why is the sky blue?",
"stream": false
}'
I tried with:
function OnClick(clickData) {
DOpus.ClearOutput();
var Dlg = DOpus.Dlg;
Dlg.window = clickData.func.sourcetab;
Dlg.template = "testdlg";
Dlg.detach = true;
Dlg.Show();
var req = Dlg.NewHTTPReq();
var data = JSON.stringify({
model: "llama3",
prompt: "Why is the sky blue?",
stream: false
});
req.AddPostData("", data, "application/x-www-form-urlencoded");
req.SendRequest("http://localhost:11434/api/generate", "POST");
var Msg, success;
while (true) {
Msg = Dlg.GetMsg();
if (!Msg.result) break;
if (Msg.event == "http" && !success) {
DOpus.Output("status : " + Msg.value);
DOpus.Output("complete : " + req.complete);
DOpus.Output("response : " + req.response);
DOpus.Output("responsecode : " + req.responsecode);
if (Msg.value == "data") {
Dlg.Control("static1").title = req.ReadResponse();
success = true;
}
else if (Msg.value == "error") {
DOpus.Output("error code : " + req.errorcode + "\t; error : " + req.errortext);
}
}
}
req.shutdown();
}
HTTP POST.dcf (3.2 KB)
But it doesn't work; I get a "Bad request" response (response code 400). It's likely due to the format of the data being sent.
I've also tried with:
var data = DOpus.Create.Map(
"model", "llama3",
"prompt", "Why is the sky blue?",
"stream", false
);
req.AddPostData(data);
error code : 7 ; error : Error sending request (10053), response code : 0
And this :
var data = JSON.stringify({
model: "llama3",
prompt: "Why is the sky blue?",
stream: false
});
req.AddPostData("data", data); //using other values for 'data' as well
error code : 7 ; error : Error sending request (10053), response code : 0
With the equivalent ActiveX object, I can make the request by simply sending the JSON string, without needing to specify a name:value pair (bad thing it's not asynchronous).
Thanks.