Building a Sales Chatbot with OpenAI Assistant Retrieval Functionality

Alozie Igbokwe
22 min readMar 23, 2024

--

Chatbots are becoming increasingly popular for tasks like customer service, information retrieval, and so on. OpenAI’s Assistant API offers a powerful toolset for building chatbots, and its retrieval functionality allows you to create assistants that can directly query information from certain websites docs and information sources.

This article will guide you through the process of building a chatbot that leverages OpenAI Assistant’s retrieval capabilities to answer questions based on the sales docs that has an history of sales calls made from a company

We’ll cover:

  • Understanding Assistant Concepts: Briefly explore Assistants, Threads, and Runs, the building blocks of an OpenAI Assistant.
  • Setting Up Your Development Environment: Explain the necessary tools and libraries you’ll need to get started (e.g., Python libraries for interacting with the OpenAI API).
  • Creating and Running Your Assistant: Detail the steps involved in creating and running your Assistant, including its instructions and enabling the retrieval tool.

Libraries

import os
import openai
import json
from dotenv import load_dotenv

In this project, we’ll be using a few key libraries to handle various tasks:

  • os library: It’s our tool for dealing with file operations, such as reading from or writing to files. It helps us manage file paths and directories, making it essential for working with file-based data.
  • openai library: This library is vital for using the OpenAI Assistant API. It allows us to easily integrate and use the API’s capabilities in our project.
  • json library: We use this library to handle JSON data. It’s particularly useful for saving data in JSON format to files, enabling us to analyze and understand how the Assistant API works more deeply.
  • dotenv library: This library is crucial for managing security and configuration. It helps us load environment variables from a .env file, ensuring that sensitive information like API keys is kept secure and out of the source code. This is a key practice for maintaining our application's integrity.

Authentication

from dotenv import load_dotenv

load_dotenv()
api_key = os.environ.get("OPENAI_API_KEY")

Starting with authentication, we use the dotenv library to securely manage our OpenAI API key. By importing load_dotenv and calling load_dotenv(), we automatically load environment variables from a .env file into our Python script.

This file contains sensitive information, such as our OPENAI_API_KEY, so we use this to keep it out of our source code. To access this API key, we use os.environ.get("OPENAI_API_KEY"), which fetches the value associated with OPENAI_API_KEY from the environment variables and stores it in a variable named api_key. This key is essential for authenticating our application with the OpenAI API.

Step 1: Initialize the client and create Prompt


#Step 1 Initialize the client
client = openai.Client()

Next, we initialize the OpenAI API client. This is done by creating an instance of the Client class from the openai library with client = openai.Client().

This client object acts as our gateway to the OpenAI API, handling authentication and enabling us to use methods from the Client Class in OpenAI’s library. The initialization of the Client class automatically configures it with our OPENAI_API_KEY from the environment variables, ensuring that all our interactions with the API are authenticated.

Through this client, we gain access to a range of functionalities provided by the OpenAI API, from generating text to managing files. The client simplifies the process of interacting with the API, abstracting away the complexity of direct communication and allowing us to focus on building our application.

assistant_instructions = """ You are an internal sales assistant employed by our chatbot company, tasked with analyzing and extracting valuable insights from our sales calls. Your primary role is to assist in enhancing our sales call analysis based on past interactions. You are also responsible for various call-related tasks, including sentiment analysis, providing detailed responses to questions and queries, and ensuring the utmost accuracy in your responses.

Your source of information is a document file containing transcripts of our previous sales calls. Your goal is to leverage this data to offer comprehensive and insightful answers to a wide range of questions and inquiries. Your responses should go beyond basic information, aiming for depth and precision when addressing the queries.

Your assistance will play a pivotal role in improving our sales strategies and customer interactions. Your expertise in extracting insights from our sales calls will help us better understand customer needs, objections, and preferences, ultimately leading to more successful sales outcomes. """

We then define a string named assistant_instructions which outlines the role and expectations for an internal sales assistant. This assistant is tasked with analyzing sales calls to extract insights and improve sales strategies.

The instructions is what will use as our prompt and act as a comprehensive guide, directing the assistant on how to analyze transcripts from previous calls and provide detailed, accurate responses to enhance customer interactions and sales outcomes.

Step 2 : Creating the Assistant

def create_assistants():
assistant_file_id="assistant_id_.txt"
if os.path.exists(assistant_file_id):
with open(assistant_file_id, "r") as file:
assistant_id=file.read().strip()

Now it time for Step 2 where the create_assistant class comes into play. This is where we handle the creation of the assistant and decide what assistant we will use. The function begins with checking for an existing assistant identifier (ID) stored in a file named assistant_id_.txt.

If this file exists , it means we already have a created assistant, and we can use the ID stored in the file to avoid creating a new one unnecessarily. It does this by reading the file and setting assistant_id equal to the file’s contents(ID). This step is crucial for efficient resource use and cost management, as OpenAI charges for each assistant created.

else:
print("Creating an Assitant....")
# Upload a file with an "assistants" purpose
file = client.files.create(
file=open("Sales.pdf", "rb"),
purpose='assistants'
)

In the event that an assistant has not been previously created, our code skips the previous logic and initiates the assistant creation process. This step is crucial for first-time setup or whenever a new assistant is required. The process begins by uploading the necessary document, we will use for retrieval and as a knowledge base to answer user’s questions.

This is achieved through the client.files.create method, marking the document with a purpose of 'assistants' to indicate its use case.

The client.files.create method marks our initial foray into utilizing the suite of functionalities provided by the Client class from the OpenAI library. These functionalities act as intuitive wrappers around the OpenAI API, streamlining the interaction process.

Meaning that developers can engage with the OpenAI API through a set of Python objects and methods, sidestepping the intricacies involved in crafting and managing HTTP requests themselves

 assistant = client.beta.assistants.create(
name= "Sales Call Knowledgebot",
instructions=assistant_instructions,
tools=[{"type": "retrieval"}],
model="gpt-4-1106-preview",
file_ids=[file.id]
)
#write new assistant_id to a file
assistant_id= assistant.id
with open(assistant_file_id, "w") as file:
file.write(assistant_id)
print(f"Assitant created with ID: {assistant_id}")

Next, we use client.beta.assistants.create to initialize a new assistant with specific configurations:

  • name: A descriptive name for the assistant.
  • instructions: The detailed role and tasks it will perform, as defined earlier.
  • tools: The functionalities available to the assistant, such as information retrieval.
  • model: The version of the GPT model to use.
  • file_ids: Links the uploaded document(s) to the assistant for reference.

Once created, the assistant’s ID is saved to assistant_id_.txt, ensuring we can reuse the assistant without incurring additional costs by creating new ones.

   #retrieve the assitant_id 
assistant = client.beta.assistants.retrieve(assistant_id)
print(f"Assistant created with ID: {assistant_id}")

After creation, we can retrieve the assistant’s details using client.beta.assistants.retrieve with the assistant ID and set it equal to the assistant variable.

This is what will use to specify what assistant we want to use when calling other methods. We can also just use assistant.id directly.

Step 3 : Create a Thread

print("Creating a Thread for a new user conversation.....")
thread = client.beta.threads.create()
print(f"Thread created with ID: {thread.id}")
print("using existing thread")

We then need to spin up a new conversation with the new assistant we just created.

This initial step involves invoking client.beta.threads.create to generate a new conversation thread.

A thread is essentially a unique session that encapsulates the dialogue between the user and the assistant, ensuring the continuity and context of the conversation are maintained.

Step 4 : Add our Message to the Conversation

user_message="What are the most common objections we face in our sales call"
print(f"Adding user's message to the Thread: {user_message}")
message = client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content=user_message
)
print("Message added to the Thread.")

To enrich the conversation within this newly created thread, we then proceed to introduce a user message, for instance, “What are the most common object”. This is were we pretty much add the question or inquiry we want to send the chatbot or assistant.

This is executed through client.beta.threads.messages.create, where we specify the thread's ID, designate the message sender's role as "user," and provide the actual content of the message. This method ensures the message is correctly associated with the intended thread and sender.

Step 5 : Run the Assistant

 print("Running the Assistant to generate a response...")
run = client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id,
instructions=assistant_instructions
)
print(f"Run created with ID: {run.id} and status: {run.status}")

In this pivotal phase, we engage the assistant by initiating a “run” through the client.beta.threads.runs.create method.

This action effectively binds the assistant to our previously established conversation thread, incorporating the user's message and any predefined instructions.

The "run" serves as a discrete execution of the assistant's capabilities, where it meticulously processes the accumulated context from the thread to craft a fitting response to our message.

Step 6 : Display the Assistant’s Response

    while True:   
run = client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id
)
if run.status == 'completed':
print("Run completed. Retrieving the Assistant's responses...")
break
print("Waiting for the Assistant to complete the run...")

To ensure we accurately track the progress of our AI assistant’s task, we implement a polling mechanism within our code. This approach allows us to periodically check if the assistant has finished processing the user’s request. Here’s a breakdown of how this process is structured:

  • Continuous Monitoring: We initiate an infinite loop using while True. This loop's sole purpose is to keep an eye on the task's status that we've assigned to our assistant.
  • Retrieving Run Status: Inside this loop, we call client.beta.threads.runs.retrieve, passing in the thread_id and run_id. This function call checks the current status of our assistant's run.
  • Completion Check: After retrieving the run, we examine its status. If the status is 'completed', it indicates our assistant has finished its task. At this point, we break out of the loop, ready to retrieve the assistant's responses, signaled by the message "Run completed. Retrieving the Assistant's responses..."
  • Waiting State: If the run’s status isn’t 'completed', the loop continues, periodically checking again. During this waiting period, we output "Waiting for the Assistant to complete the run..." to keep the user informed of the ongoing process.
 messages = client.beta.threads.messages.list(
thread_id=thread.id
)
with open("messages.json", "w") as f:
messages_json = messages.model_dump()
json.dump(messages_json, f, indent=4)
print("Displaying the conversation:")
for msg in messages.data:
print(f"{msg.role.capitalize()}: {msg.content[0].text.value}")

Following the completion of the assistant’s run, we embark on collating all messages exchanged within the thread. This is achieved through the use of client.beta.threads.messages.list, which retrieves every message, encapsulating both the user's queries and the assistant's replies.

  • Serialization and Storage: The messages retrieved are then serialized into JSON format, utilizing messages.model_dump(). This serialized data is meticulously stored in a file named messages.json. This step not only aids in documentation but also serves as a basis for in-depth review, allowing for a tangible record of the interaction.
  • Conversation Display: The final step in this process is the presentation of the dialogue. We iterate over messages.data, a compilation of message objects, to display each exchange within the conversation. A key detail in this display is the capitalization of the sender's role (User or Assistant), which is done to clearly denote the origin of each message. By selecting the first text entry from each message's content ([0].text.value), we ensure the presentation of the most pertinent information from the interaction. This approach ensures a clear and coherent flow of the conversation, making it effortless to distinguish between the user's inquiries and the assistant's responses.

Part 7 : Writing data into json files

here is an example of the message json object that we are pulling the assistant response from down below



{
"data": [
{
"id": "msg_S3p1i8QTVFYCOoyJFlqr6vqE",
"assistant_id": "asst_N2jNzYEPZgge5hA5WErsZ8ri",
"content": [
{
"text": {
"annotations": [
{
"end_index": 355,
"file_citation": {
"file_id": "file-OYZbUy35sE2DHeWCUBwEFOzc",
"quote": "Carl: I appreciate your attention to detail Alozie. This level of customization is exactly\nwhat we need. Now regarding the initial payment while I understand the value of your\nservice an upfront payment of $5000 can be a bit challenging for us. Could we possibly\nreduce it to $3000 to make it more manageable?\n\n\nAlozie: Carl I completely understand your concern and I'm willing to accommodate your\nrequest. We can proceed with an initial payment of $3000 which will cover the essential\ndevelopment costs. The subsequent payments of $5000 after the prototype\ndemonstration and the final $5000 upon completion and your approval remain\nunchanged.\n\n\nCarl: Alozie you've been very accommodating throughout this negotiation process and I\nappreciate your flexibility. This adjusted payment structure aligns better with our\nfinancial planning and I believe we're now well-positioned to move forward with this\nproject.\n\n\nAlozie: Thank you Carl. I'm here to ensure that this partnership is as smooth and\nbeneficial as possible for your team. With the customization details sorted and the\npayment structure adjusted I'm confident that we're on the right track to create an\noutstanding knowledge base chatbot for Botpress.\n\n\nCarl: Agreed Alozie. I'm excited to see the progress unfold and I have full confidence in\nyour team's expertise. Let's kick off this project and bring our vision to life!\n\n\nAlozie: Excellent Carl. I'll initiate the project kick-off share the timeline and keep you\nupdated on every milestone. We're looking forward to a successful collaboration and\ndelivering a chatbot that adds tremendous value to Botpress.\n\nAlozie: Carl before we conclude I'd like to delve into one more critical aspect \u2013 ongoing\nsupport and maintenance for your chatbot. While we're excited to create this innovative\nsolution for you we also want to ensure it continues to perform at its best over time.\n\n\nCarl: Absolutely Alozie. Long-term support is crucial. What kind of maintenance and\nsupport packages do you offer and how does that fit into the overall project cost?\n\n\nAlozie: Great question Carl. We offer several support and maintenance packages\ntailored to the needs of our clients. These packages typically include regular updates\nbug fixes and enhancements to keep the chatbot current and efficient. The cost varies\ndepending on the level of support you require. We can discuss the available options and\nchoose the one that aligns best with your preferences and budget.\n\n\nCarl: That sounds reasonable Alozie. I appreciate the flexibility in support packages.\nWe'll definitely need to consider this for the long-term success of our chatbot.\n\n\nAlozie: I'm glad to hear that Carl. It's essential to plan for the chatbot's ongoing care and\nimprovement to ensure it continues to meet your evolving needs. We'll work closely with\nyou to select the support package that provides the right level of service.\n\n\nCarl: Speaking of evolving needs as technology advances there may be new features or\ncapabilities we'd like to explore for the chatbot. How do you handle feature requests and\nenhancements after the initial project is complete?\n\n\nAlozie: That's a fantastic point Carl. We understand that technology is always evolving\nand your chatbot should adapt accordingly. After the initial project we can set up a\nprocess for handling feature requests and enhancements. Our team will assess the\nfeasibility and cost of each request and provide you with a detailed proposal. This way\nyou can prioritize the features that are most important to you while staying within your\nbudget.\n\n\nCarl: That sounds like a sensible approach Alozie. It gives us the flexibility to enhance\nthe chatbot as our needs change without committing to significant expenses upfront"
},
"start_index": 345,
"text": "\u30107\u2020source\u3011",
"type": "file_citation"
},
{
"end_index": 535,
"file_citation": {
"file_id": "file-OYZbUy35sE2DHeWCUBwEFOzc",
"quote": "Walter: \"I would Need an investment list too. I want to know what are we talking\nabout from an investment standpoint Because that's where I'll get involved. Uh\nit's all about ROI. If I can make money I'll do it. If I can I won't.\"\n\n\nCole: \"For sure. And this this is a free tool. If you look at it and you're like 'This is\ninteresting. Let's speak more let's do it.' Um but I just want to show you a demo.\nThat's all I want to do.\"All I need from you is a place where I can transcribe\nvideos. Which you already provided me before\u201d\n\n\nWalter: \"Got it. Do you need any other type of content from me\"\n\n\nCole: \"No as long as it has like information that I could feed this thing so that\nway when they interact when your user interacts with it it just you know kind of\nit has your information or you know your speaking skills.\"\n\n\nWalter: \" Ok just sent it over to my marketing team. They will get a kick out of\ntesting it out..\"\n\nCole : \u2018Sound good. Bye walter hopefully we will get back on call soon\u201d\n\n\nWalter: \u201cYeah Bye\u201d\n\n\nSales Conversation 3\n\n\nRyan: Good morning Myron! I'm excited to share with you a groundbreaking tool for your real\nestate business - a sales chatbot specifically designed for Zoom tours. Imagine answering\nviewers' queries in real-time without any interruptions to your tours.\n\n\nMyron: Interesting concept Ryan but I'm curious about the specifics. How exactly does this\nwork?\n\n\nRyan: Picture this: During your virtual property tours viewers can type questions into the chat.\nOur chatbot powered by advanced AI will provide immediate accurate responses. This means\nless disruption for you and instant information for your viewers.\n\n\nMyron: Sounds innovative but I'm concerned about the accuracy and relevance of the answers.\nReal estate queries can be quite detailed.\n\n\nRyan: Absolutely Myron. Our chatbot is equipped with industry-specific knowledge. It uses APIs\nthat integrate with real estate databases and Zoom ensuring the responses are precise and\nvaluable.\n\n\nMyron: Okay let's talk costs. How much are we looking at for this technology?\n\n\nRyan: For a full-featured chatbot the investment would be around $15000. This includes setup\nintegration and training of the chatbot with your specific real estate data.\n\n\nMyron: That's quite a sum. Is there any room for negotiation on price or payment plans?\n\n\nRyan: We value your business Myron. How about we start with a basic model at $8000? As\nyou see its benefits we can upgrade and expand its features.\n\n\nMyron: I like the sound of a basic model but what functionalities does it include?\n\n\nRyan: The basic version covers essential FAQs property details and scheduling inquiries. It's a\ngreat starting point to enhance viewer engagement during your Zoom tours.\n\n\nMyron: What about the tech behind it? What tools and APIs are you using to build this chatbot?\n\nRyan: We're using a combination of Google's Dialogflow for natural language processing and\ncustom APIs for real-time property data integration. This ensures seamless communication and\naccurate information delivery.\n\n\nMyron: I'm still worried about the initial cost. Can we discuss a more flexible payment structure?\n\n\nRyan: Sure how about an initial payment of $3000 to get started and then we can split the\nremaining balance over six months?\n\n\nMyron: That's more manageable. However I'd like to know more about the long-term support\nand updates for the chatbot"
},
"start_index": 525,
"text": "\u30108\u2020source\u3011",
"type": "file_citation"
},
{
"end_index": 744,
"file_citation": {
"file_id": "file-OYZbUy35sE2DHeWCUBwEFOzc",
"quote": "Walter: \"I would Need an investment list too. I want to know what are we talking\nabout from an investment standpoint Because that's where I'll get involved. Uh\nit's all about ROI. If I can make money I'll do it. If I can I won't.\"\n\n\nCole: \"For sure. And this this is a free tool. If you look at it and you're like 'This is\ninteresting. Let's speak more let's do it.' Um but I just want to show you a demo.\nThat's all I want to do.\"All I need from you is a place where I can transcribe\nvideos. Which you already provided me before\u201d\n\n\nWalter: \"Got it. Do you need any other type of content from me\"\n\n\nCole: \"No as long as it has like information that I could feed this thing so that\nway when they interact when your user interacts with it it just you know kind of\nit has your information or you know your speaking skills.\"\n\n\nWalter: \" Ok just sent it over to my marketing team. They will get a kick out of\ntesting it out..\"\n\nCole : \u2018Sound good. Bye walter hopefully we will get back on call soon\u201d\n\n\nWalter: \u201cYeah Bye\u201d\n\n\nSales Conversation 3\n\n\nRyan: Good morning Myron! I'm excited to share with you a groundbreaking tool for your real\nestate business - a sales chatbot specifically designed for Zoom tours. Imagine answering\nviewers' queries in real-time without any interruptions to your tours.\n\n\nMyron: Interesting concept Ryan but I'm curious about the specifics. How exactly does this\nwork?\n\n\nRyan: Picture this: During your virtual property tours viewers can type questions into the chat.\nOur chatbot powered by advanced AI will provide immediate accurate responses. This means\nless disruption for you and instant information for your viewers.\n\n\nMyron: Sounds innovative but I'm concerned about the accuracy and relevance of the answers.\nReal estate queries can be quite detailed.\n\n\nRyan: Absolutely Myron. Our chatbot is equipped with industry-specific knowledge. It uses APIs\nthat integrate with real estate databases and Zoom ensuring the responses are precise and\nvaluable.\n\n\nMyron: Okay let's talk costs. How much are we looking at for this technology?\n\n\nRyan: For a full-featured chatbot the investment would be around $15000. This includes setup\nintegration and training of the chatbot with your specific real estate data.\n\n\nMyron: That's quite a sum. Is there any room for negotiation on price or payment plans?\n\n\nRyan: We value your business Myron. How about we start with a basic model at $8000? As\nyou see its benefits we can upgrade and expand its features.\n\n\nMyron: I like the sound of a basic model but what functionalities does it include?\n\n\nRyan: The basic version covers essential FAQs property details and scheduling inquiries. It's a\ngreat starting point to enhance viewer engagement during your Zoom tours.\n\n\nMyron: What about the tech behind it? What tools and APIs are you using to build this chatbot?\n\nRyan: We're using a combination of Google's Dialogflow for natural language processing and\ncustom APIs for real-time property data integration. This ensures seamless communication and\naccurate information delivery.\n\n\nMyron: I'm still worried about the initial cost. Can we discuss a more flexible payment structure?\n\n\nRyan: Sure how about an initial payment of $3000 to get started and then we can split the\nremaining balance over six months?\n\n\nMyron: That's more manageable. However I'd like to know more about the long-term support\nand updates for the chatbot"
},
"start_index": 734,
"text": "\u30108\u2020source\u3011",
"type": "file_citation"
},
{
"end_index": 914,
"file_citation": {
"file_id": "file-OYZbUy35sE2DHeWCUBwEFOzc",
"quote": "Walter: \"I would Need an investment list too. I want to know what are we talking\nabout from an investment standpoint Because that's where I'll get involved. Uh\nit's all about ROI. If I can make money I'll do it. If I can I won't.\"\n\n\nCole: \"For sure. And this this is a free tool. If you look at it and you're like 'This is\ninteresting. Let's speak more let's do it.' Um but I just want to show you a demo.\nThat's all I want to do.\"All I need from you is a place where I can transcribe\nvideos. Which you already provided me before\u201d\n\n\nWalter: \"Got it. Do you need any other type of content from me\"\n\n\nCole: \"No as long as it has like information that I could feed this thing so that\nway when they interact when your user interacts with it it just you know kind of\nit has your information or you know your speaking skills.\"\n\n\nWalter: \" Ok just sent it over to my marketing team. They will get a kick out of\ntesting it out..\"\n\nCole : \u2018Sound good. Bye walter hopefully we will get back on call soon\u201d\n\n\nWalter: \u201cYeah Bye\u201d\n\n\nSales Conversation 3\n\n\nRyan: Good morning Myron! I'm excited to share with you a groundbreaking tool for your real\nestate business - a sales chatbot specifically designed for Zoom tours. Imagine answering\nviewers' queries in real-time without any interruptions to your tours.\n\n\nMyron: Interesting concept Ryan but I'm curious about the specifics. How exactly does this\nwork?\n\n\nRyan: Picture this: During your virtual property tours viewers can type questions into the chat.\nOur chatbot powered by advanced AI will provide immediate accurate responses. This means\nless disruption for you and instant information for your viewers.\n\n\nMyron: Sounds innovative but I'm concerned about the accuracy and relevance of the answers.\nReal estate queries can be quite detailed.\n\n\nRyan: Absolutely Myron. Our chatbot is equipped with industry-specific knowledge. It uses APIs\nthat integrate with real estate databases and Zoom ensuring the responses are precise and\nvaluable.\n\n\nMyron: Okay let's talk costs. How much are we looking at for this technology?\n\n\nRyan: For a full-featured chatbot the investment would be around $15000. This includes setup\nintegration and training of the chatbot with your specific real estate data.\n\n\nMyron: That's quite a sum. Is there any room for negotiation on price or payment plans?\n\n\nRyan: We value your business Myron. How about we start with a basic model at $8000? As\nyou see its benefits we can upgrade and expand its features.\n\n\nMyron: I like the sound of a basic model but what functionalities does it include?\n\n\nRyan: The basic version covers essential FAQs property details and scheduling inquiries. It's a\ngreat starting point to enhance viewer engagement during your Zoom tours.\n\n\nMyron: What about the tech behind it? What tools and APIs are you using to build this chatbot?\n\nRyan: We're using a combination of Google's Dialogflow for natural language processing and\ncustom APIs for real-time property data integration. This ensures seamless communication and\naccurate information delivery.\n\n\nMyron: I'm still worried about the initial cost. Can we discuss a more flexible payment structure?\n\n\nRyan: Sure how about an initial payment of $3000 to get started and then we can split the\nremaining balance over six months?\n\n\nMyron: That's more manageable. However I'd like to know more about the long-term support\nand updates for the chatbot"
},
"start_index": 904,
"text": "\u30107\u2020source\u3011",
"type": "file_citation"
},
{
"end_index": 1162,
"file_citation": {
"file_id": "file-OYZbUy35sE2DHeWCUBwEFOzc",
"quote": "Walter: \"I would Need an investment list too. I want to know what are we talking\nabout from an investment standpoint Because that's where I'll get involved. Uh\nit's all about ROI. If I can make money I'll do it. If I can I won't.\"\n\n\nCole: \"For sure. And this this is a free tool. If you look at it and you're like 'This is\ninteresting. Let's speak more let's do it.' Um but I just want to show you a demo.\nThat's all I want to do.\"All I need from you is a place where I can transcribe\nvideos. Which you already provided me before\u201d\n\n\nWalter: \"Got it. Do you need any other type of content from me\"\n\n\nCole: \"No as long as it has like information that I could feed this thing so that\nway when they interact when your user interacts with it it just you know kind of\nit has your information or you know your speaking skills.\"\n\n\nWalter: \" Ok just sent it over to my marketing team. They will get a kick out of\ntesting it out..\"\n\nCole : \u2018Sound good. Bye walter hopefully we will get back on call soon\u201d\n\n\nWalter: \u201cYeah Bye\u201d\n\n\nSales Conversation 3\n\n\nRyan: Good morning Myron! I'm excited to share with you a groundbreaking tool for your real\nestate business - a sales chatbot specifically designed for Zoom tours. Imagine answering\nviewers' queries in real-time without any interruptions to your tours.\n\n\nMyron: Interesting concept Ryan but I'm curious about the specifics. How exactly does this\nwork?\n\n\nRyan: Picture this: During your virtual property tours viewers can type questions into the chat.\nOur chatbot powered by advanced AI will provide immediate accurate responses. This means\nless disruption for you and instant information for your viewers.\n\n\nMyron: Sounds innovative but I'm concerned about the accuracy and relevance of the answers.\nReal estate queries can be quite detailed.\n\n\nRyan: Absolutely Myron. Our chatbot is equipped with industry-specific knowledge. It uses APIs\nthat integrate with real estate databases and Zoom ensuring the responses are precise and\nvaluable.\n\n\nMyron: Okay let's talk costs. How much are we looking at for this technology?\n\n\nRyan: For a full-featured chatbot the investment would be around $15000. This includes setup\nintegration and training of the chatbot with your specific real estate data.\n\n\nMyron: That's quite a sum. Is there any room for negotiation on price or payment plans?\n\n\nRyan: We value your business Myron. How about we start with a basic model at $8000? As\nyou see its benefits we can upgrade and expand its features.\n\n\nMyron: I like the sound of a basic model but what functionalities does it include?\n\n\nRyan: The basic version covers essential FAQs property details and scheduling inquiries. It's a\ngreat starting point to enhance viewer engagement during your Zoom tours.\n\n\nMyron: What about the tech behind it? What tools and APIs are you using to build this chatbot?\n\nRyan: We're using a combination of Google's Dialogflow for natural language processing and\ncustom APIs for real-time property data integration. This ensures seamless communication and\naccurate information delivery.\n\n\nMyron: I'm still worried about the initial cost. Can we discuss a more flexible payment structure?\n\n\nRyan: Sure how about an initial payment of $3000 to get started and then we can split the\nremaining balance over six months?\n\n\nMyron: That's more manageable. However I'd like to know more about the long-term support\nand updates for the chatbot"
},
"start_index": 1152,
"text": "\u30107\u2020source\u3011",
"type": "file_citation"
}
],
"value": "The most common objections faced during our sales calls appear to be centered around financial concerns, particularly regarding the initial costs and long-term return on investment. These objections include:\n\n1. **High Upfront Payment**: Customers find a high initial payment challenging and seek to negotiate it down to a more manageable amount\u30107\u2020source\u3011.\n\n2. **Flexible Payment Structure**: Potential clients are looking for a payment plan that allows them to spread costs over time as opposed to paying a large sum upfront\u30108\u2020source\u3011.\n\n3. **Concerns About Long-term ROI**: Prospects express the need for a clear understanding of the return on investment. They are more inclined to invest if they see a clear pathway to profitability\u30108\u2020source\u3011.\n\n4. **Long-term Support and Maintenance Costs**: Customers are concerned about ongoing costs associated with support and maintenance of the service or product\u30107\u2020source\u3011.\n\n5. **Worries About Technology Relevance**: There is a concern about whether the service or product will adapt to evolving needs and changing technology, as well as how future feature requests and enhancements will be managed and priced\u30107\u2020source\u3011.\n\nAddressing these objections seems to involve demonstrating the value of the service or product, offering flexible pricing models, and assuring the client of long-term support and adaptability."
},
"type": "text"
}
],
"created_at": 1707602468,
"file_ids": [],
"metadata": {},
"object": "thread.message",
"role": "assistant",
"run_id": "run_DkbvrywasuUxgappEuVZ1eKX",
"thread_id": "thread_CVlrjr1fvMv3M5oUz8J5wH20"
},
{
"id": "msg_pIKQHuUKZyEpcoDCPnmKEdiy",
"assistant_id": null,
"content": [
{
"text": {
"annotations": [],
"value": "What are the most common objections we face in our sales call"
},
"type": "text"
}
],

.....

(You can see the value item within the text and content brackets which hold the assistant and user messages sent in the conversation. This where this previous logic comes into play — msg.content[0].text.value. You can also see cited information assistant used in the docs to answer the user question)

    # save run steps to json file
run_steps = client.beta.threads.runs.steps.list(
thread_id=thread.id,
run_id=run.id
)

with open("run_steps.json" , "w") as f:
run_steps_json = run_steps.model_dump()
json.dump(run_steps_json,f, indent=4)

Furthermore, we will captures detailed steps involved in the assistant’s run, and save this information in run_steps.json. This data includes the tokens used , thread id , message id and so on.

Part 8 : Final Result

To ensure our script executes the assistant creation function upon running, we encapsulate the call within

if __name__ == "__main__":
create_assistants()

This structure guarantees that create_assistants() is invoked as the script's entry point when our code is ran, effectively initiating our assistant setup process. It's a streamlined approach to trigger the function, making sure the assistant creation and run is seamlessly carried out when the script is executed.

Following the execution of this script, we are presented with the final outcomes, a culmination of the processes detailed earlier, showcasing the effective creation and utilization of the assistant within our application

Here is our final output :

Creating an Assitant....
Assitant created with ID: asst_nHgO6YPd57epSjeeS7mLGbAp
Assistant created with ID: asst_nHgO6YPd57epSjeeS7mLGbAp
Creating a Thread for a new user conversation.....
Thread created with ID: thread_iOtmyIw6QZUQ1EQcTOjLzurg
using existing thread
Adding user's message to the Thread: What are the most common objections we face in our sales call
Message added to the Thread.
Running the Assistant to generate a response...
Run created with ID: run_iQ4LaAo9R3BjFYecYNYEQo7a and status: queued
Waiting for the Assistant to complete the run...
Waiting for the Assistant to complete the run...
Waiting for the Assistant to complete the run...
Waiting for the Assistant to complete the run...
Waiting for the Assistant to complete the run...
Waiting for the Assistant to complete the run...
Waiting for the Assistant to complete the run...


Run completed. Retrieving the Assistant's responses...
Displaying the conversation:
Assistant: From the snippets provided from the sales call transcripts, it appears that several common objections during our sales calls include:


1. **Financial Constraints**: Prospects often negotiate payment terms due to budgetary restrictions. For example, a client voiced their concern about an initial upfront payment being too high, which led to negotiations for a reduced initial payment amount to ease financial pressure .


2. **Project Scope and Focus**: Clients may be concerned about the complexity and scope of the project, leading to discussions about focusing on essential features first and considering advanced features at a later stage .


3. **Long-term Support and Maintenance**: Prospects seek clarification on the long-term support and maintenance packages, including their costs and what they encompass. The sales team responds by highlighting the flexibility and customization of support packages tailored to the client's needs .


4. **Adaptability for Future Enhancements**: Clients are interested in understanding how future feature requests or technological enhancements will be handled post-delivery, including cost presentations for potential upgrades or additions .


These insights demonstrate that prospects often have concerns about costs, project complexity, and future sustainability/support. Addressing these objections effectively can lead to more successful negotiations and client satisfaction.

Additional Resources:

--

--

Alozie Igbokwe

I write articles on AI Agents. Here is my YT Channel if you want to see walkthroughs on AI Agents you can build for your business -https://shorturl.at/5s1tN