Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yiranwu0 committed Nov 16, 2024
1 parent e441d90 commit c072c4a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ def _append_oai_message(self, message: Union[Dict, str], role, conversation_id:

if message.get("role") in ["function", "tool"]:
oai_message["role"] = message.get("role")
if "tool_responses" in oai_message:
for tool_response in oai_message["tool_responses"]:
tool_response["content"] = str(tool_response["content"])
elif "override_role" in message:
# If we have a direction to override the role then set the
# role accordingly. Used to customise the role for the
Expand Down Expand Up @@ -791,15 +794,16 @@ async def a_send(
"Message can't be converted into a valid ChatCompletion message. Either content or function_call must be provided."
)

def _print_received_message(self, message: Union[Dict, str], sender: Agent):
def _print_received_message(self, message: Union[Dict, str], sender: Agent, skip_head: bool = False):
iostream = IOStream.get_default()
# print the message received
iostream.print(colored(sender.name, "yellow"), "(to", f"{self.name}):\n", flush=True)
if not skip_head:
iostream.print(colored(sender.name, "yellow"), "(to", f"{self.name}):\n", flush=True)
message = self._message_to_dict(message)

if message.get("tool_responses"): # Handle tool multi-call responses
for tool_response in message["tool_responses"]:
self._print_received_message(tool_response, sender)
self._print_received_message(tool_response, sender, skip_head=True)
if message.get("role") == "tool":
return # If role is tool, then content is just a concatenation of all tool_responses

Expand Down Expand Up @@ -2288,7 +2292,7 @@ def _format_json_str(jstr):
result.append(char)
return "".join(result)

def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict[str, str]]:
def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict[str, Any]]:
"""Execute a function call and return the result.
Override this function to modify the way to execute function and tool calls.
Expand Down Expand Up @@ -2342,7 +2346,7 @@ def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict
return is_exec_success, {
"name": func_name,
"role": "function",
"content": str(content),
"content": content,
}

async def a_execute_function(self, func_call):
Expand Down Expand Up @@ -2397,7 +2401,7 @@ async def a_execute_function(self, func_call):
return is_exec_success, {
"name": func_name,
"role": "function",
"content": str(content),
"content": content,
}

def generate_init_message(self, message: Union[Dict, str, None], **kwargs) -> Union[str, Dict]:
Expand Down

0 comments on commit c072c4a

Please sign in to comment.