feat(python进阶): 新增模块与包课程
This commit is contained in:
29
02_python进阶/2_1_模块与包/agent_tools.py
Normal file
29
02_python进阶/2_1_模块与包/agent_tools.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# 第 2-1 课示例:自定义模块
|
||||
#
|
||||
# 模块就是一个 Python 文件。
|
||||
# 这个文件集中保存与 Agent 工具有关的函数,供其他文件导入使用。
|
||||
|
||||
|
||||
DEFAULT_TOOLS = ["搜索", "终端"]
|
||||
|
||||
|
||||
def get_tool_count(tools):
|
||||
"""返回工具列表中的工具数量。"""
|
||||
return len(tools)
|
||||
|
||||
|
||||
def build_agent_description(name, model):
|
||||
"""根据名称和模型生成 Agent 描述。"""
|
||||
return f"{name} 使用 {model} 模型"
|
||||
|
||||
|
||||
def show_module_test():
|
||||
"""输出本模块的测试结果。"""
|
||||
print("正在测试 agent_tools 模块。")
|
||||
print(f"默认工具数量:{get_tool_count(DEFAULT_TOOLS)}")
|
||||
|
||||
|
||||
# 只有直接运行本文件时,才执行下面的测试代码。
|
||||
# 其他文件导入本模块时,不会自动执行测试。
|
||||
if __name__ == "__main__":
|
||||
show_module_test()
|
||||
Reference in New Issue
Block a user