This is how I run ChatGPT in Ninox app
Hello friends :)
Please find code below, allows to run OpenAI ChatGPT in your Ninox apps. It is connected to button OpenAi. After click it sends content of yourPrompt to ChatGPT and display raw result in apiResponse and clean answer in chatAnswer.
Works like a charm in cloud. Doesn't work at all in standalone databases - this is limitation of free app.
You have to generate API key for yourself at https://platform.openai.com, probably you have to pay some amount of money for it. But for only for one person it is sooooo cheap. I pay 10 USD few month ago, and still have few bucks for playing with AI :)
I didn't test other models - I have a mess in head with all endpoints. So, if 3.5 turbo is ok...
There is one a super-ugly piece of code, but I can't do this prettier -> where I digg in json data. Generally: this code can be done much much better - I'm not a programmer - we all are open for suggestions :)
Here is the code:
let myPrompt := yourPrompt;
let keyAI := "PUT-HERE-YOUR-API-KEY-FROM-OPENAI";
let urlAI := "https://api.openai.com/v1/chat/completions";
let modelAI := "gpt-3.5-turbo";
let tempAI := 0.7;
let response := do as server
http("POST", urlAI, {
Authorization: "Bearer " + keyAI,
'content-type': "application/json"
}, {
model: modelAI,
temperature: tempAI,
messages: [{
role: "user",
content: myPrompt
}]
})
end;
apiResponse := text(response.result);
let json := parseJSON(text(response.result));
let answerfirst := first(response.result.choices);
let answersec := first(answerfirst.message);
let answer := first(answersec.content);
chatAnswer := answer + " finish!"
I think this can be helpful :)
Regards from Poland
Tomasz
2 replies
-
Thank you so much for sharing!
Let's see what our members can create with the help of AI.
I was wondering if in the future Ninox is considering incorporating some of the AI capabilities. For example as an aid to scripting, have you heard anything about that?
Content aside
-
4
Likes
- 6 mths agoLast active
- 2Replies
- 231Views
-
3
Following