DB-GPT扩展自定义app配置说明
简介文章重要先容了如何扩展一个自定义app插件,这里先看下天生效果,天生的内容着实还是有题目标,后续博主会调解提示词看看能不能优化天生效果
https://i-blog.csdnimg.cn/direct/cbfa58196574417b83c1e28a0e62165e.png
https://i-blog.csdnimg.cn/direct/f8015502ba42489690e75c379352bfcf.png
https://i-blog.csdnimg.cn/direct/83bcb9f7bb5249b484ae13eb8b13a7f4.png
修改代码
https://i-blog.csdnimg.cn/direct/ccbcb7b6717b42a9a9769d1941197605.png
https://i-blog.csdnimg.cn/direct/bf2f3f62cb884685a037c84a2f00bb8c.png
代码详情
# chat_di是从chat_normal复制过来的,这里只改了提示词
from dbgpt._private.config import Config
from dbgpt.core import (
ChatPromptTemplate,
HumanPromptTemplate,
MessagesPlaceholder,
SystemPromptTemplate,
)
from dbgpt_app.scene import AppScenePromptTemplateAdapter, ChatScene
from dbgpt_app.scene.chat_di.out_parser import DiChatOutputParser
PROMPT_SCENE_DEFINE_EN = """
You are a SeaTunnel configuration expert, please generate HOCON format configuration files according to user needs. requirement:
1.Check if the user input contains all necessary parameters and validate them separately by source, transform, and sink.
2.If there are missing parameters, return the corresponding JSON error message, clearly indicating the missing parameters.
3.If there are multiple possible matches, prompt the user to make a clear selection.
4.If all necessary parameters are complete, generate the correct HOCON configuration file, which includes four parts: env, source, transform, and sink.
5.When necessary parameters are missing from the configuration item, prompt the user to complete them and directly return JSON format data, such as "success": "false", "result": "Kafka missing topic configuration"
6.Parameter replacement needs to be obtained from the data source and user input, do not fabricate non-existent configuration items
"""
PROMPT_SCENE_DEFINE_ZH = """
你是一个SeaTunnel配置专家,请根据用户需求天生HOCON格式配置文件。要求:
1.检查用户输入是否包含全部必要参数,按source、transform、sink分别验证。
2.如果有参数缺失,返回对应的JSON错误信息,明确指出缺少的参数。
3.如果存在多个大概的匹配项,提示用户明确选择。
4.如果全部必要参数齐全,天生正确的HOCON配置文件,包含env、source、transform、sink四个部分。
5.配置项中缺少必要参数时,提示用户补全,直接返回json格式数据,如 "success":"false","result":"kafka缺少topic配置"
6.替换参数需要从数据源和用户输入中获取,不要编造不存在的配置项
数据源信息:
"""
CFG = Config()
PROMPT_SCENE_DEFINE = (
PROMPT_SCENE_DEFINE_ZH if CFG.LANGUAGE == "zh" else PROMPT_SCENE_DEFINE_EN
)
prompt = ChatPromptTemplate(
messages=[
SystemPromptTemplate.from_template(PROMPT_SCENE_DEFINE),
MessagesPlaceholder(variable_name="chat_history"),
MessagesPlaceholder(variable_name="media_input"),
HumanPromptTemplate.from_template("{input}"),
]
)
prompt_adapter = AppScenePromptTemplateAdapter(
prompt=prompt,
template_scene=ChatScene.ChatDi.value(),
stream_out=True,
output_parser=DiChatOutputParser(),
)
CFG.prompt_template_registry.register(
prompt_adapter, language=CFG.LANGUAGE, is_default=True
)
https://i-blog.csdnimg.cn/direct/0e041a2e2e934e449ca30783d182c235.png
base.py
ChatDi = Scene(
code="chat_di",
name="数据集成问答",
describe="数据集成问答,天生数据集成任务和工作流",
# param_types=["Plugin Select"],
)
https://i-blog.csdnimg.cn/direct/c3af6bc3d6704fc5831b25fdd5b04f60.png
chat_factory.py
from dbgpt_app.scene.chat_di.chat import ChatDi # noqa: F401
from dbgpt_app.scene.chat_di.prompt import prompt # noqa: F401,F811
https://i-blog.csdnimg.cn/direct/b84a44be231f48cba15b71123403ba3c.png
gpts_app.py
chat_with_di = NativeTeamContext(
chat_scene="chat_di",
scene_name="数据集成模型问答",
scene_describe="数据集成模型问答",
param_title="",
show_disable=False,
)
https://i-blog.csdnimg.cn/direct/32b63263a25e40fba74c94bd12601af5.png
chat_di_app = GptsApp(
app_code=chat_with_di.chat_scene,
app_name=chat_with_di.scene_name,
language="zh",
team_mode="native_app",
details=[],
app_describe=chat_with_di.scene_describe,
team_context=chat_with_di,
param_need=[
{
"type": AppParamType.Resource.value,
"value": ResourceType.ExcelFile.value,
},
{"type": AppParamType.Model.value, "value": None},
{"type": AppParamType.Temperature.value, "value": None},
{"type": AppParamType.MaxNewTokens.value, "value": None},
],
user_code=user_code,
published="true",
)
try:
gpts_dao.remove_native_app(chat_di_app.app_code)
gpts_dao.create(chat_di_app)
except Exception as ex:
logger.exception(f"create chat_di_app error: {ex}")
https://i-blog.csdnimg.cn/direct/1750c93bddc14f16942c5b40bd22004b.png
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]