【NVIDIA AIQ】自定义函数实践

NVIDIA Agent Intelligence Toolkit自定义函数实践

定义工具函数

python 复制代码
import logging

from pydantic import BaseModel
from pydantic import Field
from pydantic import HttpUrl

from aiq.builder.builder import Builder
from aiq.builder.function_info import FunctionInfo
from aiq.cli.register_workflow import register_function
from aiq.data_models.function import FunctionBaseConfig

logger = logging.getLogger(__name__)

# 工具类
class CustomToolConfig(FunctionBaseConfig, name="custom_tool"):
    """ 测试自定义工具调用 """
    

# 注册工具函数
@register_function(config_type=CustomToolConfig)
async def custom_tool(config: CustomToolConfig, builder: Builder):

  	# 工具函数逻辑处理
    async def _custom_tool_test(text: str) -> str:
        return '这是一个自定义工具调用测试${text}'

    # 逻辑导出调用
    yield FunctionInfo.from_fn(
        _custom_tool_test,
        description="这是一个自定义工具调用测试",
    )

注册: 工具导出

  • aiq/tool/register.py
python 复制代码
from . import custom_tool

配置引用

yaml 复制代码
# NVIDIA NeMo Agent Toolkit 黑客松配置
# 支持用户自定义OpenAI兼容API

general:
  use_uvloop: true

functions:
  custom_tool:
    _type: custom_tool
    description: "自定义工具测试"

workflow:
  _type: react_agent
  tool_names:
    - custom_tool
  llm_name: default_llm
  verbose: true
  parse_agent_response_max_retries: 3
  max_iterations: 10

测试验证

输入关键字,触发AI调用

终端调用打印

参考资源

NVIDIA Agent Intelligence Toolkit

Custom Functions

相关推荐
拾贰_C5 分钟前
【anaconda】anaconda安装配置,git安装配置以及pytorch安装
人工智能·pytorch·git
荼蘼13 分钟前
Dlib+OpenCV 人脸轮廓绘制
人工智能·opencv·计算机视觉
九河云15 分钟前
物流仓储自动化升级:物道供应链 AGV 机器人实现分拣效率提升 60%
人工智能·科技·物联网·机器人·自动化
strongwyy19 分钟前
esp32墨水屏学习3
学习
mldong21 分钟前
保姆级教程!手把手教你搭建FastAPI + Vue3前后端分离项目
vue.js·python·全栈
_dindong21 分钟前
Linux系统编程:线程概念
linux·运维·笔记·学习
正点原子22 分钟前
正点原子 x STM32:智能加速边缘AI应用开发!
人工智能·stm32·嵌入式硬件
金井PRATHAMA29 分钟前
GraphRAG(知识图谱结合大模型)对人工智能中自然语言处理的深层语义分析的影响与启示
人工智能·自然语言处理·知识图谱
CCSBRIDGE1 小时前
Browser-Use 的实现原理
人工智能
愚公搬代码1 小时前
【愚公系列】《人工智能70年》044-数据科学崛起(安全与隐私,硬币的另一面)
人工智能·安全