|
|
@ -639,7 +639,9 @@ def python_calculator_execute(expression: str, **kwargs) -> str:
|
|
|
|
return f"Error: {e}"
|
|
|
|
return f"Error: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create Tool instances
|
|
|
|
# Create utility function to get default tools
|
|
|
|
|
|
|
|
def get_default_tools() -> List[Tool]:
|
|
|
|
|
|
|
|
"""Returns a list of default tools that can be used with OctoToolsSwarm."""
|
|
|
|
image_captioner = Tool(
|
|
|
|
image_captioner = Tool(
|
|
|
|
name="Image_Captioner_Tool",
|
|
|
|
name="Image_Captioner_Tool",
|
|
|
|
description="Generates a caption for an image.",
|
|
|
|
description="Generates a caption for an image.",
|
|
|
@ -688,18 +690,36 @@ calculator = Tool(
|
|
|
|
execute_func=python_calculator_execute,
|
|
|
|
execute_func=python_calculator_execute,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Create an OctoToolsSwarm agent
|
|
|
|
return [image_captioner, object_detector, web_search, calculator]
|
|
|
|
agent = OctoToolsSwarm(tools=[image_captioner, object_detector, web_search, calculator])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Run the agent with a query
|
|
|
|
|
|
|
|
# query = "Who is the president of US, final all the PM of humans?"
|
|
|
|
|
|
|
|
# # Create a dummy image file for testing
|
|
|
|
|
|
|
|
# with open("example.png", "w") as f:
|
|
|
|
|
|
|
|
# f.write("Dummy image content")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Only execute the example when this script is run directly
|
|
|
|
|
|
|
|
# if __name__ == "__main__":
|
|
|
|
|
|
|
|
# print("Running OctoToolsSwarm example...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Create an OctoToolsSwarm agent with default tools
|
|
|
|
|
|
|
|
# tools = get_default_tools()
|
|
|
|
|
|
|
|
# agent = OctoToolsSwarm(tools=tools)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Example query
|
|
|
|
|
|
|
|
# query = "What is the square root of the number of objects in this image?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Create a dummy image file for testing if it doesn't exist
|
|
|
|
# image_path = "example.png"
|
|
|
|
# image_path = "example.png"
|
|
|
|
|
|
|
|
# if not os.path.exists(image_path):
|
|
|
|
|
|
|
|
# with open(image_path, "w") as f:
|
|
|
|
|
|
|
|
# f.write("Dummy image content")
|
|
|
|
|
|
|
|
# print(f"Created dummy image file: {image_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Run the agent
|
|
|
|
# result = agent.run(query, image=image_path)
|
|
|
|
# result = agent.run(query, image=image_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Display results
|
|
|
|
|
|
|
|
# print("\n=== FINAL ANSWER ===")
|
|
|
|
# print(result["final_answer"])
|
|
|
|
# print(result["final_answer"])
|
|
|
|
# print(result["trajectory"]) # Uncomment to see the full trajectory
|
|
|
|
|
|
|
|
# print("\n".join(result["conversation"])) # Uncomment to see agent conversation
|
|
|
|
# print("\n=== TRAJECTORY SUMMARY ===")
|
|
|
|
|
|
|
|
# for step in result["trajectory"]:
|
|
|
|
|
|
|
|
# print(f"Step {step.get('step', 'N/A')}: {step.get('component', 'Unknown')}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# print("\nOctoToolsSwarm example completed.")
|