Sentiment Analysis on real time chatting with AI for lead generation

I am making a personal loan app chatbot powerd by open ai api using 3.5 turbo. How can i do real time sentiment analysis on user chatting and i am passing user chat histroy and so that user can ask follow-up questions, now i want to know weather user wants to take personal loan or not by using their chat history , now the main problem is due to follow-up question user will not write whole query and i assuming therre will be 6-7 pair of question anwer will be thier , now with this much of chat data how can i know that user is wanted to take personal loan and than can chatbot proceed further.

I do not have any user data except this chatting data with my chatbot

What appraoch could i follow to know the intent of user

2 Likes

You can use function calling to get customer sentiment by evaluating the whole 6-7 pairs of question answer data you have.

Check this sample function:

{
    "name": "customer_sentiment",
    "description": "Predicts and scores the customer's intent sentiment based on given text",
    "parameters": {
        "type": "object",
        "properties": {
            "purchase_intent": {
                "type": "number",
                "description": "Score indicating the customer's intent to purchase a product or service"
            },
            "feedback_intent": {
                "type": "number",
                "description": "Score indicating the customer's intent to provide feedback or a review"
            },
            "query_intent": {
                "type": "number",
                "description": "Score indicating the customer's intent to seek information or ask a question"
            }
        },
        "required": [ "purchase_intent", "feedback_intent", "query_intent" ]
    }
}

Sample conversations and scores:

Sales Rep: Hello Mr. Stevens. This is Rico from Town Credit Company. Do you have two minutes to chat?
Prospect: Yes, I do. How can I help you?
Sales Rep: Great, thank you. We’re a business finance platform that helps companies like yours to get additional funds for your projects. I’m calling to see if we can provide assistance.
Prospect: Interesting, can you tell me more about how your product can help my company?

{
  role: 'assistant',
  content: null,
  function_call: {
    name: 'customer_sentiment',
    arguments: '{\n' +
      '  "purchase_intent": 0.6,\n' +
      '  "feedback_intent": 0.2,\n' +
      '  "query_intent": 0.8\n' +
      '}'
  }
}

Sales Rep: Hello Mr. Stevens. This is Rico from Town Credit Company. Do you have two minutes to chat?
Prospect: Yes, I do. How can I help you?
Sales Rep: Great, thank you. We’re a business finance platform that helps companies like yours to get additional funds for your projects. I’m calling to see if we can provide assistance.
Prospect: Well, currently we do not have such need.

{
  role: 'assistant',
  content: null,
  function_call: {
    name: 'customer_sentiment',
    arguments: '{\n  "purchase_intent": 0,\n  "feedback_intent": 0,\n  "query_intent": 0\n}'
  }
}

Sales Rep: Hello Mr. Stevens. This is Rico from Town Credit Company. Do you have two minutes to chat?
Prospect: Yes, I do. How can I help you?
Sales Rep: Great, thank you. We’re a business finance platform that helps companies like yours to get additional funds for your projects. I’m calling to see if we can provide assistance.
Prospect: Do you have any materials or site which I can check?

{
  role: 'assistant',
  content: null,
  function_call: {
    name: 'customer_sentiment',
    arguments: '{\n' +
      '  "purchase_intent": 0.2,\n' +
      '  "feedback_intent": 0.8,\n' +
      '  "query_intent": 0.9\n' +
      '}'
  }
}

Just create your own parameters/categories and analyze the scores you will get.

3 Likes

If you are coding this yourself, the answer from @supershaneski is perfect and should work.

If you are trying to do it with a no-code system (or without functions), this approach might help: Combining Sentiment Analysis with Retrieval Augmented Generation (RAG) | by Alden Do Rosario | Sep, 2023 | Medium

i am making telegram bot which will interact openai api and i am using aiogram for telegram bot.
Also for the history maintaining i am using lanchain memory, just memory part not anything else from langchain

but i am seeing that if two user from differnt device , chatting with telegram bot their history is mixing so when more user will chat thier chat hisotry will aslo mix,

I am using ‘/start’ command from the telegram to clear the user chat history, but this will also clear chat histroy from all the user devices,

what am i doing wrong?

With this information i only tell you that you need to maintain separate chat histories for each user. Can you share your Code for that part to better assist you.

I alreday sent u code please check and please assist me , it is very confusing me