DB-GPT扩展自定义Agent配置说明

简介

文章主要介绍了如何扩展一个自定义Agent,这里是用官方提供的总结摘要的Agent做了个示例,先给大家看下显示效果

代码目录

博主将代码放在core目录了,后续经过对源码的解读感觉放在dbgpt_serve.agent.agents.expand目录下可能更合适,大家自行把控即可

代码详情

summarizer_action.py

from typing import Optional

from pydantic import BaseModel, Field

from dbgpt.vis import Vis

from dbgpt.agent import Action, ActionOutput, AgentResource, ResourceType

from dbgpt.agent.util import cmp_string_equal

NOT_RELATED_MESSAGE = "Did not find the information you want."

# The parameter object that the Action that the current Agent needs to execute needs to output.

class SummaryActionInput(BaseModel):

    summary: str = Field(

        ...,

        description="The summary content",

    )

class SummaryAction(Action[SummaryActionInput]):

    def __init__(self, **kwargs):

        super().__init__(**kwargs)

    @property

    def resource_need(self) -> Optional[ResourceType]:

        # The resource type that the current Agent needs to use

        # here we do not need to use resources, just return None

        return None

    @property

    def render_protocol(self) -> Optional[Vis]:

        # The visualization rendering protocol that the current Agent needs to use

        # here we do not need to use visualization rendering, just return None

        return None

    @property

    def out_model_type(self):

        return SummaryActionInput

    async def run(

            self,

            ai_message: str,

            resource: Optional[AgentResource] = None,

            rely_action_out: Optional[ActionOutput] = None,

            need_vis_render: bool = True,

            **kwargs,

    ) -> ActionOutput:

        """Perform the action.

        The entry point for actual execution of Action. Action execution will be

        automatically initiated after model inference.

        """

        try:

            # Parse the input message

            param: SummaryActionInput = self._input_convert(ai_message, SummaryActionInput)

        except Exception:

            return ActionOutput(

                is_exe_success=False,

                content="The requested correctly structured answer could not be found, "

                        f"ai message: {ai_message}",

            )

        # Check if the summary content is not related to user questions

        if param.summary and cmp_string_equal(

                param.summary,

                NOT_RELATED_MESSAGE,

                ignore_case=True,

                ignore_punctuation=True,

                ignore_whitespace=True,

        ):

            return ActionOutput(

                is_exe_success=False,

                content="the provided text content is not related to user questions at all."

                        f"ai message: {ai_message}",

            )

        else:

            return ActionOutput(

                is_exe_success=True,

                content=param.summary,

            )

summarizer_agent.py

from typing import Optional

from pydantic import BaseModel, Field

from dbgpt.vis import Vis

from dbgpt.agent import Action, ActionOutput, AgentResource, ResourceType

from dbgpt.agent.util import cmp_string_equal

NOT_RELATED_MESSAGE = "Did not find the information you want."

# The parameter object that the Action that the current Agent needs to execute needs to output.

class SummaryActionInput(BaseModel):

    summary: str = Field(

        ...,

        description="The summary content",

    )

class SummaryAction(Action[SummaryActionInput]):

    def __init__(self, **kwargs):

        super().__init__(**kwargs)

    @property

    def resource_need(self) -> Optional[ResourceType]:

        # The resource type that the current Agent needs to use

        # here we do not need to use resources, just return None

        return None

    @property

    def render_protocol(self) -> Optional[Vis]:

        # The visualization rendering protocol that the current Agent needs to use

        # here we do not need to use visualization rendering, just return None

        return None

    @property

    def out_model_type(self):

        return SummaryActionInput

    async def run(

            self,

            ai_message: str,

            resource: Optional[AgentResource] = None,

            rely_action_out: Optional[ActionOutput] = None,

            need_vis_render: bool = True,

            **kwargs,

    ) -> ActionOutput:

        """Perform the action.

        The entry point for actual execution of Action. Action execution will be

        automatically initiated after model inference.

        """

        try:

            # Parse the input message

            param: SummaryActionInput = self._input_convert(ai_message, SummaryActionInput)

        except Exception:

            return ActionOutput(

                is_exe_success=False,

                content="The requested correctly structured answer could not be found, "

                        f"ai message: {ai_message}",

            )

        # Check if the summary content is not related to user questions

        if param.summary and cmp_string_equal(

                param.summary,

                NOT_RELATED_MESSAGE,

                ignore_case=True,

                ignore_punctuation=True,

                ignore_whitespace=True,

        ):

            return ActionOutput(

                is_exe_success=False,

                content="the provided text content is not related to user questions at all."

                        f"ai message: {ai_message}",

            )

        else:

            return ActionOutput(

                is_exe_success=True,

                content=param.summary,

            )

这样重启项目就能看到自定义的agent了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/bicheng/82491.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android 架构演进之路:从 MVC 到 MVI,拥抱单向数据流的革命

在移动应用开发的世界里,架构模式的演进从未停歇。从早期的 MVC 到后来的 MVP、MVVM,每一次变革都在尝试解决前一代架构的痛点。而今天,我们将探讨一种全新的架构模式 ——MVI(Model-View-Intent),它借鉴了…

【YOLOv8-pose部署至RK3588】模型训练→转换RKNN→开发板部署

已在GitHub开源与本博客同步的YOLOv8_RK3588_object_pose 项目,地址:https://github.com/A7bert777/YOLOv8_RK3588_object_pose 详细使用教程,可参考README.md或参考本博客第六章 模型部署 文章目录 一、项目回顾二、文件梳理三、YOLOv8-pose…

集成30+办公功能的实用工具

软件介绍 本文介绍的软件是千峰办公助手。 软件功能概述与开发目的 千峰办公助手集成了自动任务、系统工具、文件工具、PDF工具、OCR图文识别、文字处理、电子表格七个模块,拥有30余项实用功能。作者开发该软件的目的是解决常见办公痛点,把机械操作交…

IDEA启动报错:Cannot invoke “org.flowable.common.engine.impl.persistence.ent

1.问题 项目启动报错信息 java.lang.NullPointerException: Cannot invoke "org.flowable.common.engine.impl.persistence.ent 2.问题解析 出现这个问题是在项目中集成了Flowable或Activiti工作流,开启自动创建工作流创建的表,因为不同环境的数据…

网络安全--PHP第三天

今天学习文件上传的相关知识 上传的前端页面如下 upload.html <!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"&g…

【愚公系列】《生产线数字化设计与仿真》004-颜色分类站仿真(基础概念)

🌟【技术大咖愚公搬代码:全栈专家的成长之路,你关注的宝藏博主在这里!】🌟 📣开发者圈持续输出高质量干货的"愚公精神"践行者——全网百万开发者都在追更的顶级技术博主! 👉 江湖人称"愚公搬代码",用七年如一日的精神深耕技术领域,以"…

基于 uni-app + <movable-view>拖拽实现的标签排序-适用于微信小程序、H5等多端

在实际业务中&#xff0c;我们经常遇到「标签排序」或「菜单调整」的场景。微信小程序原生的 movable-view 为我们提供了一个简单、高效的拖拽能力&#xff0c;结合 Vue3 uni-app 的组合&#xff0c;我们可以实现一个体验良好的标签管理界面。 核心组件&#xff1a;<movab…

一些较好的学习方法

1、网上有一些非常经典的电路&#xff0c;而且有很多视频博主做了详细的讲解。 2、有一部分拆解的UP主&#xff0c;拆解后会还原该器件的原理图&#xff0c;并一步步做讲解。 3、有两本书&#xff0c;数电、模电&#xff0c;这两本书中的内容很多都值得学习。 5、某宝上卖的…

《1.1_4计算机网络的分类|精讲篇|附X-mind思维导图》

网络相关知识 按使用范围分类 公用网 由电信部门或其他提供通信服务的经营部门组建、管理和控制&#xff0c;向全社会提供服务的网络。 专用网 由某个单位或部门组建、仅供本单位或部门内部使用的网络。 按传输介质分类 有线网络 如&#xff1a;双绞线、同轴电缆、光纤…

Git 和 GitHub 学习指南本地 Git 配置、基础命令、GitHub 上传流程、企业开发中 Git 的使用流程、以及如何将代码部署到生产服务器

Windows 上 Git 安装与配置 下载安装&#xff1a;访问 Git 官方网站下载适用于 Windows 的安装程序。运行安装包时会出现许可协议、安装目录、组件选择等界面&#xff08;如下图&#xff09;。在“Select Components”页面建议勾选 Git Bash Here 等选项&#xff0c;以便在资源…

航空航天领域对滚珠丝杆的精度要求有多高?

航空航天领域对滚珠丝杆的精度要求非常高&#xff0c;尤其是飞行器、火箭和卫星等载具的导航和定位系统都需要高精度的滚珠丝杆&#xff0c;以确保高精度的位置控制和稳定的导航性能。那么&#xff0c;航空航天领域对滚珠丝杆的精度要求有多高&#xff1f; 1、定位精度&#xf…

技术篇-2.5.Matlab应用场景及开发工具安装

Matlab 在数学建模和数值分析等领域具有无可替代的地位。它几乎涵盖所有常见数学算法的内置函数库&#xff0c;使得从数据预处理、方程求解到优化算法的实现&#xff0c;无需编写大量底层代码即可快速完成&#xff1b;同时&#xff0c;Matlab 强大的可视化能力&#xff0c;可以…

Vtk概览1

vtk环境搭建 见&#xff08;VTK开发环境配置(Visual Studio C)-详细图文教程-CSDN博客&#xff09; 在学习vtk图形图像进阶的第二章时&#xff0c;通过vs2022建的控制台程序&#xff0c;编写运行示例2.1 发现 不显示图像。 #include <iostream> #include<vtkRenderW…

【数据集】基于ubESTARFM法的100m 地温LST数据集(澳大利亚)

目录 数据概述一、输入数据与处理二、融合算法1. ESTARFM(Enhanced STARFM)2. ubESTARFM(Unbiased ESTARFM)代码实现数据下载参考根据论文《Generating daily 100 m resolution land surface temperature estimates continentally using an unbiased spatiotemporal fusion…

Lucide:一款精美的开源矢量图标库,前端图标新选择

名人说:博观而约取,厚积而薄发。——苏轼《稼说送张琥》 创作者:Code_流苏(CSDN)(一个喜欢古诗词和编程的Coder😊) 目录 一、前言:为何选择 Lucide?二、Lucide 是什么?1. 基本介绍2. Lucide vs Feather三、如何在项目中使用 Lucide?1. 安装图标包(以 React 为例)2…

BeanUtil和BeanUtils有什么区别

BeanUtil 和 BeanUtils 是两个常见的工具类&#xff0c;通常用于 Java 开发中处理对象之间的属性复制或转换。它们的功能可能看起来相似&#xff0c;但实际上它们来自不同的库&#xff0c;并且在实现细节和使用方式上存在一些差异。 以下是它们的主要区别&#xff1a; 1. 来源…

【CF】Day66——Edu 168.D + CF 853 (Div. 2).C (树 + 二分 + 贪心 | 组合数学)

D. Maximize the Root 题目&#xff1a; 思路&#xff1a; 树上二分&#xff0c;中下题 我们可以发现如果 x 可以&#xff0c;那么 x - 1 肯定也可以&#xff0c;所以可以直接二分答案 具体的&#xff0c;我们每次二分能增加的值 mid &#xff0c;如果 a[i] < mid&#xf…

生成对抗网络(GANs)中的损失函数公式 判别器最优解D^*(x)的推导

https://www.bilibili.com/video/BV1YyHSekEE2 这张图片展示的是生成对抗网络&#xff08;GANs&#xff09;中的损失函数公式&#xff0c;特别是针对判别器&#xff08;Discriminator&#xff09;和生成器&#xff08;Generator&#xff09;的优化目标。让我们用Markdown格式逐…

分布式爬虫架构设计

随着互联网数据的爆炸式增长&#xff0c;单机爬虫已经难以满足大规模数据采集的需求。分布式爬虫应运而生&#xff0c;它通过多节点协作&#xff0c;实现了数据采集的高效性和容错性。本文将深入探讨分布式爬虫的架构设计&#xff0c;包括常见的架构模式、关键技术组件、完整项…

[java]eclipse中windowbuilder插件在线安装

目录 一、打开eclipse 二、打开插件市场 三、输入windowbuilder&#xff0c;点击install 四、进入安装界面 五、勾选我同意... 重启即可 一、打开eclipse 二、打开插件市场 三、输入windowbuilder&#xff0c;点击install 四、进入安装界面 五、勾选我同意... 重启即可