Skip to content

Commit

Permalink
Add required tools automatically in gradio when uploading files
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed May 30, 2024
1 parent aca7eba commit 118f0f2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions agency_swarm/agency/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,26 @@ def user(user_message, history):
nonlocal attachments
nonlocal recipient_agent

# Check if attachments contain file search or code interpreter types
def check_and_add_tools_in_attachments(attachments, recipient_agent):
for attachment in attachments:
for tool in attachment.get("tools", []):
if tool["type"] == "file_search":
if not any(isinstance(t, FileSearch) for t in recipient_agent.tools):
# Add FileSearch tool if it does not exist
recipient_agent.tools.append(FileSearch)
recipient_agent.client.beta.assistants.update(recipient_agent.id, tools=recipient_agent.get_oai_tools())
print("Added FileSearch tool to recipient agent to analyze the file.")
elif tool["type"] == "code_interpreter":
if not any(isinstance(t, CodeInterpreter) for t in recipient_agent.tools):
# Add CodeInterpreter tool if it does not exist
recipient_agent.tools.append(CodeInterpreter)
recipient_agent.client.beta.assistants.update(recipient_agent.id, tools=recipient_agent.get_oai_tools())
print("Added CodeInterpreter tool to recipient agent to analyze the file.")
return None

check_and_add_tools_in_attachments(attachments, recipient_agent)

if history is None:
history = []

Expand Down

0 comments on commit 118f0f2

Please sign in to comment.