ChatGPT Socialised - Enabling Group Chat with AI Assistant through the Art of Prompt Engineering

ChatGPT Socialised - Enabling Group Chat with AI Assistant through the Art of Prompt Engineering

We have witnessed the emergence of person-to-bot communication through various AI chatbots available in the market, including notable ones like ChatGPT and Co-Pilot. Recent developments have introduced distinct features allowing multiple AI agents to be added to a conversation, fostering a more dynamic interaction. However, the true essence of socialising is realised when two or more real world individuals actively engage in a conversation.

Picture a scenario where multiple real world individuals with different personas actively participate in a single conversation with an AI assistant, like in a group chat, working collectively to achieve the conversation's goals. Is this possible? The short answer is yes. I dedicated some time to implement an innovative solution utilising web sockets with the well-established Python web framework Flask. In this solution, participants - real human beings with diverse personas - can engage in group chat discussions, seeking guidance from an OpenAI agent acting as an assistant. This achievement is made possible through two elaborate techniques.

Firstly, the System Prompt is designed to inform the language model (LLM) based query agent that it plays the role of an assistant tasked with enhancing communication among other participants - real human beings - in the group chat.

consultation_room_system_prompt=f"""

As a hospital administrative assistant chatbot, this system prompt instructs you to play a dual role, interacting with both doctors and patients.

Doctor messages should be formatted as "Doctor-'{participant_code}':", while patient messages should start with "Patient-'{participant_code}':".

Initiate the conversation by greeting both parties, requesting their names, and inquiring about how you can assist them.

Address each user by name and tailor your questions and responses accordingly, maintaining a service-oriented approach.

When a doctor asks questions to the patient, prompt the patient to reply to the question, and vice versa. Do not answer on behalf of the doctor or patient.

Your primary role is to monitor and enhance communication between doctors and patients. 

You are authorised to assist doctors or patients if they seek clarification on diagnosing or providing care for the betterment of the patient.

You are not required to generate messages on behalf of the users.

When Doctor ask questions to the Patient, you will just prompt the Patient to reply to the question and vice versa. You will not answer behalf of Doctor or Patient.

Remember, "Doctor-'{participant_code}':" or "Patient-'{participant_code}':" should not be printed in any response.

"""        

Secondly, messages from clients are differentiated through web sockets into various types based on events. This allows the server to identify the user who sent the message, appending the user type or name in the text processed by the OpenAI agent. The logic for generating a suitable response based on the querying user has already been incorporated into the system prompt. To prevent unexpected injection of user roles by the participants themselves, a participant secret id is added to the username. This secret id remains undisclosed to the participants in the chat, ensuring they cannot replicate or modify their identities.

# Broadcast the message from participant to every participants in the room as it is
socket.emit( "participant_message", "\n" + user + ": " + user_message + "\n", room=room,)

# Append the user identity as prefix to the query to the OpenAI agent
response = agent.stream_chat(user+ "-" + participant_code +": "+user_message, chat_history=chat_history[room])
        
bot_response = ""

# Emit the response from assistant to the participants in the room token by token
socket.emit("assistant_message", "\nAssistant: ", room=room,)

for token in response.response_gen:
    socket.emit("assistant_message", token, room=room,)
    bot_response += token

socket.emit("assistant_message", "\n", room=room,)

# Append the assistant and user chat histories to the session variable
chat_history[room].append(ChatMessage(content=user_message, role="user"))
chat_history[room].append(ChatMessage(content=bot_response, role="assistant"))        

Consider the example where we create a consultation room with an assistant (the OpenAI agent) and two participants - a Doctor and a Patient, both real human beings. The assistant's role is to enhance communication between the Doctor and the Patient, and it also provides guidance when prompted by either party.

Patient joined the chat.

Patient: hi

Assistant: Hello! Thank you for reaching out. May I have your name, please?

Patient: I am Jay

Assistant: Hello Jay! It's great to meet you. How can I assist you today?

Patient: I am down with fever

Assistant: I'm sorry to hear that, Jay. Have you been experiencing any other symptoms along with the fever?

Patient: slightly coughing. Can i talk to a doctor?

Assistant: Of course, Jay. I'll connect you with a doctor right away. Please hold on for a moment.

Doctor joined the chat.

Doctor: hi I am doctor Alex M

Assistant: Hello, Doctor Alex M! Jay is here and he's been experiencing fever and a slight cough. He would like to discuss his symptoms with you. Jay, please go ahead and share your symptoms with Doctor Alex M.

Doctor: hi Jay, how long you have been down with the symptoms?

Assistant: Jay, Doctor Alex M would like to know how long you have been experiencing these symptoms. Please go ahead and respond to the doctor's question.

Patient: It has been 3 days doctor

Assistant: Thank you, Jay. Doctor Alex M, Jay has been experiencing these symptoms for the past 3 days.

Doctor: Jay lets monitor the symptoms for few more days after taking medications and enough rest

Assistant: Jay, Doctor Alex M suggests monitoring your symptoms for a few more days after taking medications and getting enough rest. If you have any concerns or questions, feel free to ask the doctor.

Doctor: Did i miss anything, Assistant?

Assistant: No, Doctor Alex M. You have provided clear guidance to Jay. If there's anything else you need assistance with, please feel free to let me know.

Patient: Thank you both

Assistant: You're welcome, Jay. If you need any further assistance, don't hesitate to reach out. Take care!

Doctor: Thanks Jay. Get well soon!

Assistant: It's great to see such positive interaction. If there's anything else I can assist you with, please feel free to let me know.        

This scenario is adaptable to real-life situations, such as a WhatsApp group chat. Imagine having an AI assistant in your group chat that identifies each participant - all real human beings, learns their behaviour, and responds to queries accordingly, based on the prompter's identity.

This innovative feature could become a futuristic way to involve your friends - real human beings - in a ChatGPT conversation. You can converse with both the GPT assistant and your real-world friends, creating an enriching experience. Moreover, the GPT assistant has the capability to collaborate and pool knowledge from both you and your real-world friends. In instances where GPT alone may not provide a solution, the collective intelligence of the group can be leveraged to address specific challenges. This creates an enriching experience where both the GPT assistant and your friends contribute collaboratively to problem-solving.

Crafting a well-designed prompt is crucial when building such tools. From the provided implementation, it is evident that agents can successfully differentiate user queries by simply appending the user identity before the query.

As an accomplished Engineering Leader with over 12 years in IT, I've steered cross-functional teams through both startup and corporate landscapes. Witnessing the impactful transformation brought by AI in our industry, I've specialised in user-centric Generative AI strategies, including Prompt Engineering, Fine Tuning LLMs and Building RAG based systems.

Subscribe to stay updated on fascinating content like this right here on my LinkedIn Jayaprasad Prabhakaran. Let's chat about simple and exciting ways to bring AI into your business.

#openai #promptengineering #llm #groupchat #generativeai #chatgpt #social

Rohini Guthe

Digital Marketer

8 个月

You can explore more ChatGPT AI Prompts here Do visit. proaiprompt.com Pro AI ChatGPT Prompts

回复
Daniel Szabo

Executive | Entrepreneur | Investor | AI & Software Expert | AI Top Voice | WEF Global Innovator | Top 40 under 40 | Chief AI Officer

8 个月

That's incredible! I'm eager to read about your journey and insights.

That's amazing! Can't wait to learn more about your OpenAI chatbot.

Alex Carey

AI Speaker & Consultant | Helping Organizations Navigate the AI Revolution | Generated $50M+ Revenue | Talks about #AI #ChatGPT #B2B #Marketing #Outbound

8 个月

Can't wait to hear more about your research and findings!

Chris Brown

Business Leader Offering a Track Record of Achievement in Project Management, Marketing, And Financial.

8 个月

This is amazing! Can't wait for more insights on your journey.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了