Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a verbose flag to let gpt assistant print more log #717

Merged
merged 5 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion autogen/agentchat/contrib/gpt_assistant_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(
instructions: Optional[str] = None,
llm_config: Optional[Union[Dict, bool]] = None,
overwrite_instructions: bool = False,
agent_config: Optional[Dict] = None,
):
"""
Args:
Expand All @@ -44,6 +45,8 @@ def __init__(
or build your own tools using Function calling. ref https://platform.openai.com/docs/assistants/tools
- file_ids: files used by retrieval in run
overwrite_instructions (bool): whether to overwrite the instructions of an existing assistant.
agent_config (dict): agent configuration.
- verbose (bool): whether to print out more assistant thread content
"""
# Use AutoGen OpenAIWrapper to create a client
oai_wrapper = OpenAIWrapper(**llm_config)
Expand Down Expand Up @@ -96,6 +99,7 @@ def __init__(
)

# lazly create thread
self._agent_config = agent_config or {}
self._openai_threads = {}
self._unread_index = defaultdict(int)
self.register_reply(Agent, GPTAssistantAgent._invoke_assistant)
Expand Down Expand Up @@ -197,7 +201,9 @@ def _get_run_response(self, thread, run):
actions = []
for tool_call in run.required_action.submit_tool_outputs.tool_calls:
function = tool_call.function
is_exec_success, tool_response = self.execute_function(function.dict())
is_exec_success, tool_response = self.execute_function(
function.dict(), self._agent_config.get("verbose", False)
)
tool_response["metadata"] = {
"tool_call_id": tool_call.id,
"run_id": run.id,
Expand Down
8 changes: 7 additions & 1 deletion autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ def _format_json_str(jstr):
result.append(char)
return "".join(result)

def execute_function(self, func_call):
def execute_function(self, func_call, verbose: bool = False):
"""Execute a function call and return the result.

Override this function to modify the way to execute a function call.
Expand Down Expand Up @@ -1135,6 +1135,12 @@ def execute_function(self, func_call):
else:
content = f"Error: Function {func_name} not found."

if verbose:
print(
colored(f"\nInput arguments: {arguments}\nOutput:\n{content}", "magenta"),
flush=True,
)

return is_exec_success, {
"name": func_name,
"role": "function",
Expand Down
60 changes: 45 additions & 15 deletions notebook/agentchat_oai_assistant_function_call.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -118,9 +118,17 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"assistant_id was None, creating a new assistant\n"
]
}
],
"source": [
"from autogen import config_list_from_json\n",
"from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent\n",
Expand All @@ -147,6 +155,9 @@
" \"Please carefully read the context of the conversation to identify the current analysis question or problem that needs addressing.\"\n",
" ),\n",
" llm_config=llm_config,\n",
" agent_config={\n",
" \"verbose\": True,\n",
" }\n",
")\n",
"oss_analyst.register_function(\n",
" function_map={\n",
Expand All @@ -166,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -180,20 +191,39 @@
"--------------------------------------------------------------------------------\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION ossinsight_data_api...\u001b[0m\n",
"\u001b[35m\n",
"Input arguments: {'question': 'Who are the top 10 developers with the most followers on GitHub?'}\n",
"Output: Question: Who are the top 10 developers with the most followers on GitHub?\n",
"\n",
"querySQL: SELECT `login` AS `user_login`, `followers` AS `followers` FROM `github_users` ORDER BY `followers` DESC LIMIT 10\n",
"\n",
"Result:\n",
" {'followers': 166730, 'user_login': 'torvalds'}\n",
" {'followers': 86239, 'user_login': 'yyx990803'}\n",
" {'followers': 77611, 'user_login': 'gaearon'}\n",
" {'followers': 72668, 'user_login': 'ruanyf'}\n",
" {'followers': 65415, 'user_login': 'JakeWharton'}\n",
" {'followers': 60972, 'user_login': 'peng-zhihui'}\n",
" {'followers': 58172, 'user_login': 'bradtraversy'}\n",
" {'followers': 52143, 'user_login': 'gustavoguanabara'}\n",
" {'followers': 51542, 'user_login': 'sindresorhus'}\n",
" {'followers': 49621, 'user_login': 'tj'}\u001b[0m\n",
"\u001b[33mOSS Analyst\u001b[0m (to user_proxy):\n",
"\n",
"The top 10 developers on GitHub with the most followers are:\n",
"\n",
"1. Linus Torvalds (`torvalds`) with 166,730 followers.\n",
"2. Evan You (`yyx990803`) with 86,239 followers.\n",
"3. Dan Abramov (`gaearon`) with 77,611 followers.\n",
"4. Ruan YiFeng (`ruanyf`) with 72,668 followers.\n",
"5. Jake Wharton (`JakeWharton`) with 65,415 followers.\n",
"6. Peng Zhihui (`peng-zhihui`) with 60,972 followers.\n",
"7. Brad Traversy (`bradtraversy`) with 58,172 followers.\n",
"8. Gustavo Guanabara (`gustavoguanabara`) with 52,143 followers.\n",
"9. Sindre Sorhus (`sindresorhus`) with 51,542 followers.\n",
"10. TJ Holowaychuk (`tj`) with 49,621 followers.\n",
"1. `torvalds` - 166,730 followers\n",
"2. `yyx990803` - 86,239 followers\n",
"3. `gaearon` - 77,611 followers\n",
"4. `ruanyf` - 72,668 followers\n",
"5. `JakeWharton` - 65,415 followers\n",
"6. `peng-zhihui` - 60,972 followers\n",
"7. `bradtraversy` - 58,172 followers\n",
"8. `gustavoguanabara` - 52,143 followers\n",
"9. `sindresorhus` - 51,542 followers\n",
"10. `tj` - 49,621 followers\n",
"\n",
"These are the developers who have the largest number of followers on GitHub, indicating high levels of influence and recognition in the open-source community.\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n",
Expand All @@ -204,7 +234,7 @@
"--------------------------------------------------------------------------------\n",
"\u001b[33mOSS Analyst\u001b[0m (to user_proxy):\n",
"\n",
"It seems like there is no question or further instructions provided in your last response. How may I assist you further with open source project analysis or any other inquiries you might have?\n",
"It seems there was no follow-up question or prompt. If you need further assistance or analysis on open source projects or developers, please let me know how I can help!\n",
"\n",
"\n",
"--------------------------------------------------------------------------------\n"
Expand Down
Loading