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
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/82491.shtml
英文地址,請注明出處:http://en.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 四、進入安裝界面 五、勾選我同意... 重啟即可