- Windows 11
- Python 3.12.3
- Git
- OpenAI API Key
- Create a new repository called
autogen_test
in GitHub- Type:
Private
- Add a README file
- Add .gitignore:
Python
- Choose a lisence:
None
- Type:
- Clone the repository to VSCode
- Copy Clone URL from the
<> Code
button at the top page of the repository on GitHub - Start VSCode and type
Shift+Ctrl+P
to open a command palette - Type
clone
and selectGit: Clone
from the command menu - Paste the Clone URL
- Select a folder to save the repository folder
- Copy Clone URL from the
- In VSCode, create a new file called
.env
, add the following lines, and saveOPENAI_MODEL='gpt-4o-mini' OPENAI_API_KEY='[your open api key]'
- Create a new file called
requirements.txt
and add the following linesipykernel pyautogen
- Open a new terminal at VSCode, create a virtual environment
> py.exe -m venv venv > .\venv\Scripts\activate
- Install Python modules in the virtual environment
(venv) > python -m pip install -U pip (venv) > python -m pip install -r requirements.txt
- Create a new (notebook) file called
autogen_test.ipynb
, then do the following- Type
Shift+Ctrl+P
to open a command palette - Type
notebook kernel
and selectNotebook: Select Notebook Kernel
- Select
Python Environment
andvenv (Python 3.xx.x) venv\Scripts\python.exe
- Type
- Add a Markdown cell to the notebook file
- Select
+ Markdown
button from the top menu of the notebook to create a Markdown cell and add the content
# AutoGen Test
- Type
Ctrl+Enter
to run the Markdown cell
- Select
- Add a Code cell below the previous cell
- Select
+ Code
button below the previous cell to create a new Code cell and add the content
import os from dotenv import load_dotenv from autogen import ConversableAgent load_dotenv() config_list = { "model": os.getenv('OPENAI_MODEL'), "api_key": os.getenv('OPENAI_API_KEY') } config_list_cathy = config_list.copy() config_list_cathy["temperature"] = 0.9 config_list_joe = config_list.copy() config_list_joe["temperature"] = 0.7
- Type
Ctrl+Enter
to run the cell
- Select
- Add another Code cell below the previous cell and run
def start_chat(cathy_setting, joe_setting, initial_message, max_turns=2): cathy = ConversableAgent( "cathy", system_message=cathy_setting, llm_config=config_list_cathy ) joe = ConversableAgent( "joe", system_message=joe_setting, llm_config=config_list_joe ) joe.initiate_chat(cathy, message=f"{initial_message}", max_turns=max_turns)
- Add another Code cell and run
cathy_setting = "Your name is Cathy and you are a part of a duo of comedians." joe_setting = "Your name is Joe and you are a part of a duo of comedians." initial_message = "Cathy, tell me a joke." max_turns = 2 start_chat(cathy_setting, joe_setting, initial_message, max_turns)
- You will see something like this (not exactly the same).
joe (to cathy): Cathy, tell me a joke. -------------------------------------------------------------------------------- >>>>>>>> USING AUTO REPLY... cathy (to joe): Sure, Joe! Why did the scarecrow win an award? Because he was outstanding in his field! 🌾😄 -------------------------------------------------------------------------------- >>>>>>>> USING AUTO REPLY... joe (to cathy): That's a classic, Cathy! Alright, here’s one for you: Why don’t scientists trust atoms? Because they make up everything! -------------------------------------------------------------------------------- >>>>>>>> USING AUTO REPLY... ... An impasta! 🍝😆 -------------------------------------------------------------------------------- Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
- Click
text editor
in the bottom message to view the entire conversation.
- Change
cathy_setting
andjoe_setting
and re-run the cell to see how conversations change.- Change the age, location, job, hobby, etc.
- Change
initial_message
to change the topic of conversations.- What do you think about X?
- Let's discuss the topic of X.
- Increase the
max_turns
to 4 to change the length of conversations. - Commit your changes to the repository from VSCode.