Files
MermsMainSocket/service/openaifunc.js
T
CHIEFSOFT\ameye 653ef00ca6 first commit
2024-12-18 02:39:56 -05:00

213 lines
8.1 KiB
JavaScript

'use strict';
const request = require('request');
const db = require('../app/db')
const logger = require('../app/logger');
const { Configuration, OpenAIApi } = require('openai');
// const config = new Configuration({
// apiKey: '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',
// });
// const openai = new OpenAIApi(config);
var openaifunc = {
openaipromt: function (req, res, next) {
// const openai2 = new OpenAIApi({
// api_key: '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'
// });
const config = new Configuration({
apiKey: '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',
});
const openai = new OpenAIApi();
let message ="What is robots ?";
// Calling the OpenAI API to complete the message
openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: chatArray.concat([{ role: "user", content: message }])
}).then((response) => {
// Save the user's message and the AI's response to the chatArray
chatArray.push({ role: "user", content: message });
chatArray.push({ role: "assistant", content: response.data.choices[0].message.content });
// Return the chatArray as a JSON response
// res.json(chatArray);
let resultItem ={
"result": chatArray,
"total_record": 4
}
next(null, resultItem ); // pass control to the next handler
});
},
homebanners: function (req, res, next) {
var result=[];
this.RecoCheckOffers(req, res, function(err, result){
logger.info("************************ aaaa");
logger.info(result);
logger.info("************************ bbbb");
});
var result_list =[
{
"title": "Some family accounts are yet to log in.",
"contract": null,
"card_type": "FAMILY_NOLOGIN",
"card_style": null,
"description": "Some family members have not logged in - a little nudge might help.",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "https://www.wrenchboard.com/assets/images/apps/banners/family-login.jpg",
"banner_location": "URL",
"link_path": "acc-family",
"button_text": "Continue",
"short_button_text": "View Now",
"short_title": "Some family accounts are yet to log in",
"short_description": "Help your family member get started.",
"short_style": "short_style"
},
{
"title": "Yo man , you have Coupons to play with",
"contract": null,
"card_type": "COUPONS",
"card_style": null,
"description": "You have received some cash coupons waiting to be redeemed.",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "banner-coupons.jpg",
"banner_location": "LOCAL",
"link_path": "my-coupon",
"button_text": "Continue",
"short_button_text": "Redeem",
"short_title": "Redeem your Cash Coupons!",
"short_description": "You have received some cash coupons waiting to be redeemed.",
"short_style": "short_style lg"
},
{
"title": "Some of your task as owner Need Review now ",
"contract": null,
"card_type": "REVIEWJOB",
"card_style": null,
"description": "Some of your task as owner Need Review now,Some of your task as owner Need Review now, S Need Review now",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "banner-job-due.jpg",
"banner_location": "LOCAL",
"link_path": "my-review-jobs",
"button_text": "View Tasks",
"short_button_text": "Start Review",
"short_title": "Review Ready Tasks",
"short_description": "Some of your jobs are waiting for approval ",
"short_style": "short_style lr"
},
{
"title": "Some of your task as owner of the tasks are due ",
"contract": null,
"card_type": "PASTDUEJOB",
"card_style": null,
"description": "Some of your task as owner of the tasks are due, Some of your task as owner of the tasks are due",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "https://www.wrenchboard.com/assets/images/apps/banners/past-due.jpg",
"banner_location": "URL",
"link_path": "my-pastdue-jobs",
"button_text": "View Tasks",
"short_button_text": "View",
"short_title": "Past Due Tasks",
"short_description": "Some of you task are now past due",
"short_style": "short_style lr"
},
{
"title": "Share WrenchBoard with a friend.",
"contract": null,
"card_type": "INVITE",
"card_style": null,
"description": "Show WrenchBoard to a friend and earn free coupons. Get started.",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "banner-refer.jpg",
"banner_location": "LOCAL",
"link_path": "referral",
"button_text": "Continue",
"short_button_text": "View now",
"short_title": "Invite a Friend - get Rewards",
"short_description": "Share WrenchBoard with a friend.",
"short_style": "short_style by"
}
];
let resultItem ={
"result": result_list,
"total_record": 5
}
next(null, resultItem ); // pass control to the next handler
},
RecoCheckOffers : function (req, res, next) {
let Qstring ="SELECT * FROM members_jobs_offer WHERE expire > now() "+
"AND status = 1 AND client_id > 0 AND client_id =" +req.body.member_id;
logger.info(Qstring);
db.query(Qstring, function (err, result) {
try {
if (err) throw err;
let resultItem ={
"result":
[
{
"title": "Share RecoCheckOffers with a friend.",
"contract": null,
"card_type": "INVITE",
"card_style": null,
"description": "Show WrenchBoard to a friend and earn free coupons. Get started.",
"blog_id": "0",
"card_icon": "icon1",
"offer_id": "0",
"banner": "banner-refer.jpg",
"banner_location": "LOCAL",
"link_path": "referral",
"button_text": "Continue",
"short_button_text": "View now",
"short_title": "Invite a Friend - get Rewards",
"short_description": "Share WrenchBoard with a friend.",
"short_style": "short_style by"
}
]
,
"total_record": result.rowCount
};
logger.info(result);
next(null, resultItem); // pass control to the next handler
} catch (e) {
next(e.message, null); // pass control to the next handler
}
});
}
};
module.exports = openaifunc;