Skip to content

Instantly share code, notes, and snippets.

@langecrew
Created January 3, 2024 00:08
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save langecrew/1aaae93f281b9c04dc043213f3527210 to your computer and use it in GitHub Desktop.
Save langecrew/1aaae93f281b9c04dc043213f3527210 to your computer and use it in GitHub Desktop.
Autogen Autobuild
import autogen
from autogen.agentchat.contrib.agent_builder import AgentBuilder
from autogen import config_list_from_json
config_path = "OAI_CONFIG_LIST"
config_list = config_list_from_json(
env_or_file="OAI_CONFIG_LIST",
filter_dict={
"model": [
"gpt-4-1106-preview",
]
}
)
cache_seed = None # Use an int to seed the response cache. Use None to disable caching.
default_llm_config = {
"config_list": config_list,
"temperature": 0,
"cache_seed": cache_seed
}
builder = AgentBuilder(config_path=config_path, builder_model="gpt-4-1106-preview", agent_model="gpt-4-1106-preview")
building_task = """Find open source weather data, and use it to make predictions.
For example, find a recent forecast on open-meteo and predict the next day's forecast."""
#The following line does not use OAI assistants. Comment out the following line to use OAI assistants below.
agent_list, agent_configs = builder.build(building_task, default_llm_config, coding=True)
#Uncomment the following line to use the OAI assistant to help you build the agent.
#agent_list, agent_configs = builder.build(building_task, default_llm_config, coding=True, use_oai_assistant=True)
execution_task = """Find a recent forecast on open-meteo and predict the next day's forecast."""
group_chat = autogen.GroupChat(agents=agent_list, messages=[], max_round=12)
manager = autogen.GroupChatManager(groupchat=group_chat, llm_config=default_llm_config)
agent_list[0].initiate_chat(manager, message=execution_task)
#Uncomment the following line to save the agent configs to a specified file
#builder.save("my_saved_configs.json")
#Uncomment the following line to load the agent configs from a specified file
#builder.load("my_saved_configs.json")
[
{
"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"
}
]
@Simonsarbunan86
Copy link

TypeError: AgentBuilder.init() got an unexpected keyword argument 'config_path'
(autogen-yp) (base) simon_sarbunan@SimonSarbunan-MacBook-Air Autobuild. % ,

I found an error when running autobuild in the terminal. please help me

@rhm2k
Copy link

rhm2k commented Jan 15, 2024

Re: the TypeError …
Line 24 of the script should be:

builder = AgentBuilder(config_file_or_env=config_path, builder_model="gpt-4-1106-preview", agent_model="gpt-4-1106-preview")

@langecrew
Copy link
Author

@Simonsarbunan86 @rhm2k my apologies, this must have changed since I originally created this code several weeks back.

@Simonsarbunan86 did the suggestion from @rhm2k help?

@Simonsarbunan86
Copy link

Thank you so much @Iangecrew and @rhm2k . I solved that problem using your code above.

@langecrew
Copy link
Author

@Simonsarbunan86 Awesome! That's great to hear!

@rhm2k Thank you for suggesting the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment