Put a if condition to add two line breaks(\n\n) at the start of every message response…
- User
Put a if condition to add two line breaks(\n\n) at the start of every message response recieved from openai under only the resume category? Code:
Chatgpt.botreplyfirst = async(req, res) => {
let data=req.body; let message = data.message; let category_key = data.category_key; let tone = data.tone; let replyIn = data.replyIn; let formality = data.formality; let promptfilter = data.promptfilter; let promtmessage = ""; let promtvalue = 0; // let packType = 0; let userToken = 0; let purchaseTime =0; if(!promptfilter){ promptfilter =" " }else{ // promptfilter = promptfilter+' and ' promptfilter = '['+promptfilter+']' }
if(!category_key){ reject("category_key required"); return; } let userId = req.authUser ? req.authUser.userId : 0; if (!userId) { reject("login required"); return; }
let userdata = await UserModel.findOne({ _id: userId }).lean().exec();
let categorydata = await CategoryModel.findOne({ categorykey: category_key }).lean().exec();if(category_key == 'social_media'){ promtmessage = 'somepormpt' } if(category_key == 'general'){ promtmessage = 'someprompt' } if(category_key == 'resume'){ promtmessage =
someprompt}
if(userdata.promptToken != undefined){ promtvalue = userdata.promptToken } const response = await openai.createChatCompletion({ model: "gpt-3.5-turbo", messages: [{"role": "system", "content": "You are a helpful assistant your name is tamara."}, {role: "user", content: promtmessage}], }); console.log("promtmessage:-",response) await UserModel.findOneAndUpdate( { _id: userId }, { $set: { promptToken:response.data.usage.prompt_tokens+promtvalue, // userToken:userToken-1, updatedAt: new Date() } }, { new: true }, ); let findCase={user_id:userId}; let historydataresp = await HistoryModel.find(findCase).sort({_id:-1}).limit(2) let chatgpt = historydataresp[0] let user = historydataresp[1] const data = { userMessage: { _id: user._doc._id, message: user._doc.message, message_from: "user", createdAt:user._doc.createdAt, isLike: user._doc.isLike, isDisLike: user._doc.isDisLike, isSave: user._doc.isSave, translator: user._doc.translator, user: { _id: userId, name:userdata.name, avatar: userdata.profilePicture, }, }, chatGPTMessage: { _id: chatgpt._doc._id, message: chatgpt._doc.message, message_from: "chatgpt", createdAt: chatgpt._doc.createdAt, isLike: chatgpt._doc.isLike, isDisLike: chatgpt._doc.isDisLike, isSave: chatgpt._doc.isSave, translator: chatgpt._doc.translator, user: { _id: categorydata._id, name: categorydata.name, avatar: null, }, }} resolve(data) } }}); };
- Assistant
To add two line breaks at the start of every response received from OpenAI under the 'resume' category, you can modify the
responseobject before sending it to theresolvefunction. Just before theresolve(data), add an if condition to check if thecategory_keyis 'resume', and if so, prepend\n\nto thechatGPTMessage.message.Here's the code with the required modification:
// ... [existing code above] // Assuming 'response' contains the message from OpenAI in the property `response.data.choices[0].message` let replyMessage = response.data.choices[0].message; if (category_key === 'resume') { // Prepend two line breaks if the category is 'resume' replyMessage = "\n\n" + replyMessage; } // ... [existing code in-between] const data = { userMessage: { // ... [existing userMessage properties] }, chatGPTMessage: { _id: chatgpt._doc._id, message: replyMessage, // Use the modified replyMessage with or without line breaks // ... [other existing chatGPTMessage properties] }, // ... [existing code below] resolve(data); } // ... [existing code below]Make sure you update the
replyMessagevariable with the actual message from theresponseobject provided by OpenAI. The example assumes that the message content is available inresponse.data.choices[0].message, but you'll need to adjust that part based on the structure of the actual response you're receiving from OpenAI's API. Remember to place this code snippet at the appropriate place in your existing function, before the final data object is resolved and sent as the response.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.