Created
November 14, 2023 14:28
-
-
Save langecrew/1379d2624437857a556d3d7cc650a4ec to your computer and use it in GitHub Desktop.
Basic test of Autogen + Open AI GPT Assistant API integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import os | |
from autogen import AssistantAgent | |
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent | |
from autogen import UserProxyAgent, config_list_from_json | |
new_config_list = config_list_from_json( | |
env_or_file="OAI_CONFIG_LIST", | |
filter_dict={ | |
"model": [ | |
"gpt-4-1106-preview", | |
] | |
} | |
) | |
assistant_id = None | |
llm_config = { | |
"config_list": new_config_list, | |
"assistant_id": assistant_id | |
#"cache_seed": 42 | |
} | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.WARNING) | |
gpt_assistant = GPTAssistantAgent(name="assistant", | |
instructions=AssistantAgent.DEFAULT_SYSTEM_MESSAGE, | |
llm_config=llm_config) | |
user_proxy = UserProxyAgent(name="user_proxy", | |
code_execution_config={ | |
"work_dir": "coding" | |
}, | |
is_termination_msg=lambda msg: "TERMINATE" in msg["content"], | |
human_input_mode="NEVER", | |
max_consecutive_auto_reply=1) | |
user_proxy.initiate_chat(gpt_assistant, message="Print hello world") | |
user_proxy.initiate_chat(gpt_assistant, message="Write py code to eval 2 + 2", clear_history=True) | |
gpt_assistant.delete_assistant() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"model": "gpt-4", | |
"api_key": "PASTE_YOUR_API_KEY_HERE" | |
}, | |
{ | |
"model": "gpt-4-1106-preview", | |
"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