mirror of
https://github.com/gosticks/complai.git
synced 2025-10-16 11:45:36 +00:00
Add rest endpoints
This commit is contained in:
parent
4f5b361acb
commit
7a30c54114
@ -13,16 +13,53 @@ app.use(bodyParser.json());
|
||||
//support parsing of application/x-www-form-urlencoded post data
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
app.route("/register").get((req, res) => {
|
||||
// check static beta invitation code
|
||||
const {email, code} = req.body;
|
||||
|
||||
if (code === "SOMECODE") {
|
||||
res.status(200).end(true);
|
||||
} else {
|
||||
res.status(403).end(false);
|
||||
}
|
||||
})
|
||||
|
||||
var companies = [];
|
||||
|
||||
class Company {
|
||||
constructor(email, nace, region, size, name) {
|
||||
this.email = email;
|
||||
this.nace = nace;
|
||||
this.region = region;
|
||||
this.size = size;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
// Put new company
|
||||
app.route("/company").post((req, res) => {
|
||||
const {email, code, nace, region, size, name} = req.body;
|
||||
|
||||
if (code !== "SOMECODE") {
|
||||
res.status(403).end(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var id = companies.push(new Company(email, nace, region, size, name));
|
||||
res.status(200).end(id);
|
||||
})
|
||||
|
||||
// Poll notifications for company
|
||||
app.route("/interpretLaw").post((req, res) => {
|
||||
const {lawtext} = req.body;
|
||||
getResponse(lawtext, res);
|
||||
const {id, lawtext} = req.body;
|
||||
getResponse(lawtext, id, res);
|
||||
});
|
||||
|
||||
app.listen(8543, ()=>{
|
||||
console.log('server is runing at port 8543')
|
||||
});
|
||||
|
||||
async function getResponse(lawtext, res) {
|
||||
async function getResponse(lawtext, id, res) {
|
||||
const { Configuration, OpenAIApi } = require("openai");
|
||||
|
||||
const configuration = new Configuration({
|
||||
@ -30,7 +67,8 @@ async function getResponse(lawtext, res) {
|
||||
});
|
||||
const openai = new OpenAIApi(configuration);
|
||||
|
||||
const prompt = "Können Sie zuerst in 1 Wort angeben, welche von diesen Dienstleistungen: [Beratung, Finanzierung, Logistik, Outsourcing, Design, Buchhaltung, Recht, IT, Marketing, Verkauf, Training, Forschung, Wartung, Produktion, Consulting, PR, Support, Recruiting, Coaching, Lieferung.] das folgende Gesetzt betrifft? Dann geben Sie in der nächsten Zeile ausführliche Empfehlungen an Unternehmen, die diese Dienste anbieten, zum Umgang mit diesem Gesetz:\n" + lawtext;
|
||||
const company = companies[id];
|
||||
const prompt = "Betriff eine Firma mit NACE code " + company.nace + " das folgende Gesetzt? Dann, und nur dann, geben Sie in der nächsten Zeile ausführliche Empfehlungen an Unternehmen, die diese Dienste anbieten, zum Umgang mit diesem Gesetz:\n" + lawtext;
|
||||
console.log("sending to openai: " + prompt);
|
||||
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user