Skip to content
TheChatArchiveThe Chat Archive
gpt-4-1106-preview· OpenAIAi2 WildChat-4.8M (AI2)

Put a if condition to add two line breaks(\n\n) at the start of every message response…

  1. 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)
    }
    }
    

    }); };

  2. Assistant

    To add two line breaks at the start of every response received from OpenAI under the 'resume' category, you can modify the response object before sending it to the resolve function. Just before the resolve(data), add an if condition to check if the category_key is 'resume', and if so, prepend \n\n to the chatGPTMessage.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 replyMessage variable with the actual message from the response object provided by OpenAI. The example assumes that the message content is available in response.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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.