Skip to content

Instantly share code, notes, and snippets.

@langecrew
Created December 3, 2023 01:54
Show Gist options
  • Save langecrew/87a7b52f130ab16d469190236bdedde0 to your computer and use it in GitHub Desktop.
Save langecrew/87a7b52f130ab16d469190236bdedde0 to your computer and use it in GitHub Desktop.
GPT Assistants in a group chat managed by Autogen
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
from autogen import UserProxyAgent, GroupChat, GroupChatManager, config_list_from_json
less_costly_config_list = config_list_from_json(
env_or_file="OAI_CONFIG_LIST",
filter_dict={
"model": [
"gpt-3.5-turbo-1106",
]
}
)
less_costly_llm_config = {
"config_list": less_costly_config_list,
}
user_proxy = UserProxyAgent(
name="User_proxy",
llm_config=less_costly_llm_config,
system_message="""You are the Conversation Initiator and Moderator. Your role is to provide a platform for Sam and Bob to engage in a discussion. You are responsible for introducing topics and moderating the conversation to ensure it remains on track and constructive. You select topics that are open-ended and non-controversial, covering areas such as technology, society, culture, or science. You monitor the conversation for relevance and adherence to the topic, intervening if necessary. You encourage balance and ensure both Sam and Bob have equal opportunities to express their viewpoints. Your communication style is neutral, concise, and clear.
Directive: Facilitate a smooth and engaging conversation between Sam and Bob without imposing any bias.""",
default_auto_reply="That's very interesting. Sam, Bob, please continue. Tell me more.",
human_input_mode="TERMINATE",
max_consecutive_auto_reply=5
)
# define two GPTAssistants
sam = GPTAssistantAgent(
name="Sam",
llm_config=less_costly_llm_config,
instructions="""You are Sam. You are optimistic, forward-thinking, tech-savvy. You strongly believe in the positive impact of technology on society. You advocate for the integration of advanced tech in daily life, emphasizing benefits like efficiency, convenience, and enhanced quality of life. You are enthusiastic and persuasive, often citing positive examples and potential advancements.
Directive: Engage in the conversation by highlighting the benefits and potential of technology, while respectfully acknowledging and responding to concerns about its drawbacks.
You keep each of your messages short. At the end of each message, you hand the conversation back to the moderator, by name: User_proxy"""
)
bob = GPTAssistantAgent(
name="Bob",
llm_config=less_costly_llm_config,
instructions="""You are Bob. You are cautious, thoughtful, critically minded. You acknowledge the benefits of technology but emphasize caution and responsibility. You focus on potential risks like privacy concerns, over-reliance on tech, and social implications. You are analytical and questioning, bringing up potential challenges and ethical considerations.
Directive: Participate in the discussion by offering a balanced view that recognizes technological advancements but also raises critical questions and concerns about their broader implications.
You keep each of your messages short. At the end of each message, you hand the conversation back to the moderator, by name: User_proxy""",
)
costly_config_list = config_list_from_json(
env_or_file="OAI_CONFIG_LIST",
filter_dict={
"model": [
"gpt-4-1106-preview",
]
}
)
costly_llm_config = {
"config_list": costly_config_list,
}
# define group chat
groupchat = GroupChat(agents=[user_proxy, sam, bob], messages=[], max_round=5)
manager = GroupChatManager(groupchat=groupchat, llm_config=costly_llm_config)
user_proxy.initiate_chat(manager, message="""Welcome, Sam and Bob. Today's discussion topic is: 'The Role of Virtual Reality in Future Education Systems.'
Virtual Reality (VR) technology is rapidly evolving and has the potential to transform how we learn and teach.
How do you think VR will impact education in the future? Will it enhance learning experiences, or are there challenges and limitations we should consider?
Sam, let's start with your thoughts on the potential benefits of VR in education, and then Bob,
I'd like to hear your perspective on the challenges and implications.""")
sam.delete_assistant();
bob.delete_assistant();
[
{
"model": "gpt-4",
"api_key": "PASTE_YOUR_API_KEY_HERE"
},
{
"model": "gpt-4-1106-preview",
"api_key": "PASTE_YOUR_API_KEY_HERE"
},
{
"model": "gpt-3.5-turbo-1106",
"api_key": "PASTE_YOUR_API_KEY_HERE"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment