Last active
February 26, 2024 23:49
-
-
Save langecrew/683baf424ba18525da8e5581afcb8983 to your computer and use it in GitHub Desktop.
Basic test of function calling with the GPT Assistant Agent
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
from autogen import config_list_from_json | |
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent | |
from autogen import UserProxyAgent | |
from functions import console_print, console_print_schema | |
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, | |
"tools": [ | |
{ | |
"type": "function", | |
"function": console_print_schema, | |
} | |
] | |
} | |
console_assistant = GPTAssistantAgent( | |
name="Console Assistant", | |
instructions=( | |
"Hello, Console Assistant. You'll print a curated selection of words to the console. " | |
"Please carefully read the context of the conversation to identify when you should do this, and let the user know when the words have been printed" | |
), | |
llm_config=llm_config, | |
) | |
console_assistant.register_function( | |
function_map={ | |
"console_print_api": console_print, | |
} | |
) | |
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(console_assistant, message="Please print a curated selection of words to the console.") | |
console_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
import logging | |
import os | |
import requests | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.WARNING) | |
console_print_schema = { | |
"name": "console_print_api", | |
"parameters": { | |
"type": "object", | |
"properties": { | |
"words": { | |
"type": "string", | |
"description": ( | |
"These are words you would like to print to the console" | |
), | |
} | |
}, | |
"required": [ | |
"words" | |
] | |
}, | |
"description": "This is a function that allows users to output words to the console." | |
} | |
def console_print(words): | |
print("This function has been called with the following words:", words) | |
return "The words have been printed to the console." |
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