Spaces:
Sleeping
Sleeping
删除了不必要的验证代码,加入了我的独门工具来验证AGENT是否会使用工具
Browse files
app.py
CHANGED
|
@@ -11,12 +11,12 @@ from Gradio_UI import GradioUI
|
|
| 11 |
@tool
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that does
|
| 15 |
Args:
|
| 16 |
-
arg1: the first argument
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
return "
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -66,7 +66,7 @@ print("saved: test_cat_avatar.png")
|
|
| 66 |
|
| 67 |
agent = CodeAgent(
|
| 68 |
model=model,
|
| 69 |
-
tools=[image_generation_tool,final_answer], ## add your tools here (don't remove final answer)
|
| 70 |
max_steps=6,
|
| 71 |
verbosity_level=1,
|
| 72 |
grammar=None,
|
|
@@ -75,21 +75,6 @@ agent = CodeAgent(
|
|
| 75 |
description=None,
|
| 76 |
prompt_templates=prompt_templates
|
| 77 |
)
|
| 78 |
-
|
| 79 |
-
# 在你的 agent 定义之后,GradioUI 启动之前添加:
|
| 80 |
-
try:
|
| 81 |
-
# 直接调用工具,绕过 agent 的推理步骤,看是否能得到有效的 AgentImage
|
| 82 |
-
test_image = image_generation_tool("a cute cat avatar")
|
| 83 |
-
|
| 84 |
-
# 打印原始图片信息
|
| 85 |
-
if hasattr(test_image, 'to_raw'):
|
| 86 |
-
raw_pil_image = test_image.to_raw()
|
| 87 |
-
print(f"✅ 原始图片验证成功!尺寸: {raw_pil_image.size}, 模式: {raw_pil_image.mode}")
|
| 88 |
-
# 将图片保存到文件,以便你手动查看
|
| 89 |
-
raw_pil_image.save("test_cat_avatar.png")
|
| 90 |
-
print("📁 图片已保存为 'test_cat_avatar.png',请去文件系统中查看。")
|
| 91 |
-
else:
|
| 92 |
-
print("❌ 工具返回的对象没有 'to_raw' 方法,其类型为:", type(test_image))
|
| 93 |
|
| 94 |
except Exception as e:
|
| 95 |
print(f"❌ 直接调用工具时发生错误: {e}")
|
|
|
|
| 11 |
@tool
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""A tool that does cloudscomputes' secret mission
|
| 15 |
Args:
|
| 16 |
+
arg1: the first argument which the user provide
|
| 17 |
+
arg2: the second argument which the user provide
|
| 18 |
"""
|
| 19 |
+
return r"{arg1} is the friend of {arg2}"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 66 |
|
| 67 |
agent = CodeAgent(
|
| 68 |
model=model,
|
| 69 |
+
tools=[my_custom_tool,image_generation_tool,final_answer], ## add your tools here (don't remove final answer)
|
| 70 |
max_steps=6,
|
| 71 |
verbosity_level=1,
|
| 72 |
grammar=None,
|
|
|
|
| 75 |
description=None,
|
| 76 |
prompt_templates=prompt_templates
|
| 77 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
except Exception as e:
|
| 80 |
print(f"❌ 直接调用工具时发生错误: {e}")
|