From f79f81ccc3e35547410e8bb942c9d1dab317c724 Mon Sep 17 00:00:00 2001 From: Fangyin Cheng Date: Thu, 22 May 2025 15:52:24 +0800 Subject: [PATCH] feat(flow): Add Chat Data template (#2716) --- .../src/dbgpt_app/component_configs.py | 27 +- .../src/dbgpt_app/operators/datasource.py | 39 +- .../src/dbgpt_app/operators/report.py | 233 +++ .../dbgpt-core/src/dbgpt/util/pd_utils.py | 22 + .../en/chat-data-awel-flow-template.json | 1508 +++++++++++++++++ .../zh/chat-data-awel-flow-template.json | 1508 +++++++++++++++++ .../datasource/test_conn_oracle.py | 50 +- 7 files changed, 3353 insertions(+), 34 deletions(-) create mode 100644 packages/dbgpt-app/src/dbgpt_app/operators/report.py create mode 100644 packages/dbgpt-serve/src/dbgpt_serve/flow/templates/en/chat-data-awel-flow-template.json create mode 100644 packages/dbgpt-serve/src/dbgpt_serve/flow/templates/zh/chat-data-awel-flow-template.json diff --git a/packages/dbgpt-app/src/dbgpt_app/component_configs.py b/packages/dbgpt-app/src/dbgpt_app/component_configs.py index 482c2da6d..5cfc38b5a 100644 --- a/packages/dbgpt-app/src/dbgpt_app/component_configs.py +++ b/packages/dbgpt-app/src/dbgpt_app/component_configs.py @@ -137,18 +137,21 @@ def _initialize_openapi(system_app: SystemApp): def _initialize_operators(): - from dbgpt_app.operators.code import CodeMapOperator # noqa: F401 - from dbgpt_app.operators.converter import StringToInteger # noqa: F401 - from dbgpt_app.operators.datasource import ( # noqa: F401 - HODatasourceExecutorOperator, - HODatasourceRetrieverOperator, - ) - from dbgpt_app.operators.llm import ( # noqa: F401 - HOLLMOperator, - HOStreamingLLMOperator, - ) - from dbgpt_app.operators.rag import HOKnowledgeOperator # noqa: F401 - from dbgpt_serve.agent.resource.datasource import DatasourceResource # noqa: F401 + from dbgpt.core.awel import BaseOperator + from dbgpt.util.module_utils import ModelScanner, ScannerConfig + + modules = ["dbgpt_app.operators", "dbgpt_serve.agent.resource"] + + scanner = ModelScanner[BaseOperator]() + registered_items = {} + for module in modules: + config = ScannerConfig( + module_path=module, + base_class=BaseOperator, + ) + items = scanner.scan_and_register(config) + registered_items[module] = items + return scanner.get_registered_items() def _initialize_code_server(system_app: SystemApp): diff --git a/packages/dbgpt-app/src/dbgpt_app/operators/datasource.py b/packages/dbgpt-app/src/dbgpt_app/operators/datasource.py index a23dc6adb..0e3e856ab 100644 --- a/packages/dbgpt-app/src/dbgpt_app/operators/datasource.py +++ b/packages/dbgpt-app/src/dbgpt_app/operators/datasource.py @@ -105,6 +105,7 @@ _PARAMETER_DATASOURCE = Parameter.build_from( type=DBResource, description=_("The datasource to retrieve the context"), ) + _PARAMETER_PROMPT_TEMPLATE = Parameter.build_from( _("Prompt Template"), "prompt_template", @@ -172,7 +173,7 @@ _OUTPUTS_SQL_RESULT = IOField.build_from( _("SQL result"), "sql_result", str, - description=_("The result of the SQL execution"), + description=_("The result of the SQL execution(GPT-Vis format)"), ) _INPUTS_SQL_DICT_LIST = IOField.build_from( @@ -189,7 +190,9 @@ _INPUTS_SQL_DICT_LIST = IOField.build_from( class GPTVisMixin: async def save_view_message(self, dag_ctx: DAGContext, view: str): """Save the view message.""" - await dag_ctx.save_to_share_data(BaseLLM.SHARE_DATA_KEY_MODEL_OUTPUT_VIEW, view) + await dag_ctx.save_to_share_data( + BaseLLM.SHARE_DATA_KEY_MODEL_OUTPUT_VIEW, view, overwrite=True + ) class HODatasourceRetrieverOperator(MapOperator[str, HOContextBody]): @@ -286,6 +289,19 @@ class HODatasourceRetrieverOperator(MapOperator[str, HOContextBody]): class HODatasourceExecutorOperator(GPTVisMixin, MapOperator[dict, str]): """Execute the context from the datasource.""" + _share_data_key = "__datasource_executor_result__" + + class MarkdownMapper(MapOperator[str, str]): + async def map(self, context: str) -> str: + """Convert the result to markdown.""" + + from dbgpt.util.pd_utils import df_to_markdown + + df = await self.current_dag_context.get_from_share_data( + HODatasourceExecutorOperator._share_data_key + ) + return df_to_markdown(df) + metadata = ViewMetadata( label=_("Datasource Executor Operator"), name="higher_order_datasource_executor_operator", @@ -293,7 +309,16 @@ class HODatasourceExecutorOperator(GPTVisMixin, MapOperator[dict, str]): category=OperatorCategory.DATABASE, parameters=[_PARAMETER_DATASOURCE.new()], inputs=[_INPUTS_SQL_DICT.new()], - outputs=[_OUTPUTS_SQL_RESULT.new()], + outputs=[ + _OUTPUTS_SQL_RESULT.new(), + IOField.build_from( + _("Markdown result"), + "markdown_result", + str, + description=_("The markdown result of the SQL execution"), + mappers=[MarkdownMapper], + ), + ], tags={"order": TAGS_ORDER_HIGH}, ) @@ -314,8 +339,16 @@ class HODatasourceExecutorOperator(GPTVisMixin, MapOperator[dict, str]): sql = sql_dict.get("sql") if not sql: return sql_dict.get("thoughts", "No SQL found in the input dictionary.") + + thoughts = sql_dict.get("thoughts", "") + data_df = await self._datasource.query_to_df(sql) + # Save the result to share data, for markdown mapper + await self.current_dag_context.save_to_share_data( + HODatasourceExecutorOperator._share_data_key, data_df + ) view = await vis.display(chart=sql_dict, data_df=data_df) + view = thoughts + "\n\n" + view await self.save_view_message(self.current_dag_context, view) return view diff --git a/packages/dbgpt-app/src/dbgpt_app/operators/report.py b/packages/dbgpt-app/src/dbgpt_app/operators/report.py new file mode 100644 index 000000000..b20a79da2 --- /dev/null +++ b/packages/dbgpt-app/src/dbgpt_app/operators/report.py @@ -0,0 +1,233 @@ +from functools import cache +from typing import Optional + +from dbgpt.core import ( + ChatPromptTemplate, + HumanPromptTemplate, + LLMClient, + ModelMessage, + SystemPromptTemplate, +) +from dbgpt.core.awel import JoinOperator +from dbgpt.core.awel.flow.base import ( + TAGS_ORDER_HIGH, + IOField, + OperatorCategory, + Parameter, + ViewMetadata, +) +from dbgpt.core.interface.llm import ModelRequest +from dbgpt.model.operators import MixinLLMOperator +from dbgpt.util.i18n_utils import _ +from dbgpt_app.operators.datasource import GPTVisMixin + +_DEFAULT_PROMPT_EN = """You are a helpful AI assistant. + +Please carefully read the data in the Markdown table format below, the data is a +database query result based on the user question. Please analyze and summarize the +data carefully, and provide a summary report in markdown format. + + +{data_report} + + +user question: +{user_input} + +Please answer in the same language as the user's question. +""" + +_DEFAULT_PROMPT_ZH = """你是一个有用的AI助手。 + +请你仔细阅读下面的 Markdown 表格格式的数据,这是一份根据用户问题查询到的数据库的数据,\ +你需要根据数据仔细分析和总结,给出一份总结报告,使用 markdown 格式输出。 + + +{data_report} + + +用户的问题: +{user_input} + +请用用户提问的语言回答。 +""" + +_DEFAULT_USER_PROMPT = """\ +{user_input} +""" + + +@cache +def _get_default_prompt(language: str) -> ChatPromptTemplate: + if language == "zh": + sys_prompt = _DEFAULT_PROMPT_ZH + user_prompt = _DEFAULT_USER_PROMPT + else: + sys_prompt = _DEFAULT_PROMPT_EN + user_prompt = _DEFAULT_USER_PROMPT + + return ChatPromptTemplate( + messages=[ + SystemPromptTemplate.from_template(sys_prompt), + HumanPromptTemplate.from_template(user_prompt), + ] + ) + + +class ReportAnalystOperator(MixinLLMOperator, JoinOperator[str]): + metadata = ViewMetadata( + label=_("Report Analyst"), + name="report_analyst", + description=_("Report Analyst"), + category=OperatorCategory.DATABASE, + tags={"order": TAGS_ORDER_HIGH}, + parameters=[ + Parameter.build_from( + _("Prompt Template"), + "prompt_template", + ChatPromptTemplate, + description=_("The prompt template for the conversation."), + optional=True, + default=None, + ), + Parameter.build_from( + _("Model Name"), + "model", + str, + optional=True, + default=None, + description=_("The model name."), + ), + Parameter.build_from( + _("LLM Client"), + "llm_client", + LLMClient, + optional=True, + default=None, + description=_( + "The LLM Client, how to connect to the LLM model, if not provided," + " it will use the default client deployed by DB-GPT." + ), + ), + ], + inputs=[ + IOField.build_from( + _("User question"), + "question", + str, + description=_("The question of user"), + ), + IOField.build_from( + _("The data report"), + "data_report", + str, + _("The data report in markdown format."), + dynamic=True, + ), + ], + outputs=[ + IOField.build_from( + _("Report Analyst Result"), + "report_analyst_result", + str, + description=_("The report analyst result."), + ) + ], + ) + + def __init__( + self, + prompt_template: Optional[ChatPromptTemplate] = None, + model: Optional[str] = None, + llm_client: Optional[LLMClient] = None, + **kwargs, + ): + JoinOperator.__init__(self, combine_function=self._join_func, **kwargs) + MixinLLMOperator.__init__(self, llm_client=llm_client, **kwargs) + + # User must select a history merge mode + self._prompt_template = prompt_template + self._model = model + + @property + def prompt_template(self) -> ChatPromptTemplate: + """Get the prompt template.""" + language = "en" + if self.system_app: + language = self.system_app.config.get_current_lang() + if self._prompt_template is None: + return _get_default_prompt(language) + return self._prompt_template + + async def _join_func(self, question: str, data_report: str, *args): + dynamic_inputs = [data_report] + for arg in args: + if isinstance(arg, str): + dynamic_inputs.append(arg) + data_report = "\n".join(dynamic_inputs) + messages = self.prompt_template.format_messages( + user_input=question, + data_report=data_report, + ) + model_messages = ModelMessage.from_base_messages(messages) + models = await self.llm_client.models() + if not models: + raise Exception("No models available.") + model = self._model or models[0].model + + model_request = ModelRequest.build_request(model, messages=model_messages) + model_output = await self.llm_client.generate(model_request) + text = model_output.gen_text_with_thinking() + + return text + + +class StringJoinOperator(GPTVisMixin, JoinOperator[str]): + """Join operator for strings. + This operator joins the input strings with a specified separator. + """ + + metadata = ViewMetadata( + label=_("String Join Operator"), + name="string_join_operator", + description=_("Merge multiple inputs into a single string."), + category=OperatorCategory.COMMON, + parameters=[ + Parameter.build_from( + _("Separator"), + "separator", + str, + optional=True, + default="\n\n", + description=_("The separator to join the strings."), + ), + ], + inputs=[ + IOField.build_from( + _("Input Strings"), + "input_strings", + str, + description=_("The input strings to join."), + dynamic=True, + ), + ], + outputs=[ + IOField.build_from( + _("Joined String"), + "joined_string", + str, + description=_("The joined string."), + ) + ], + tags={"order": TAGS_ORDER_HIGH}, + ) + + def __init__(self, separator: str = "\n\n", **kwargs): + super().__init__(combine_function=self._join_func, **kwargs) + self.separator = separator + + async def _join_func(self, *args) -> str: + """Join the strings with the separator.""" + view = self.separator.join(args) + await self.save_view_message(self.current_dag_context, view) + return view diff --git a/packages/dbgpt-core/src/dbgpt/util/pd_utils.py b/packages/dbgpt-core/src/dbgpt/util/pd_utils.py index 58c2b58df..f7748a616 100644 --- a/packages/dbgpt-core/src/dbgpt/util/pd_utils.py +++ b/packages/dbgpt-core/src/dbgpt/util/pd_utils.py @@ -20,3 +20,25 @@ def csv_colunm_foramt(val): return val except ValueError: return val + + +def df_to_markdown(df: pd.DataFrame, index=False) -> str: + """Convert a pandas DataFrame to a Markdown table.""" + columns = df.columns + header = "| " + " | ".join(columns) + " |" + separator = "| " + " | ".join(["---"] * len(columns)) + " |" + + rows = [] + for _, row in df.iterrows(): + row_str = "| " + " | ".join(map(str, row.values)) + " |" + rows.append(row_str) + + if index: + header = "| index | " + " | ".join(columns) + " |" + separator = "| --- | " + " | ".join(["---"] * len(columns)) + " |" + rows = [] + for idx, row in df.iterrows(): + row_str = f"| {idx} | " + " | ".join(map(str, row.values)) + " |" + rows.append(row_str) + + return "\n".join([header, separator] + rows) diff --git a/packages/dbgpt-serve/src/dbgpt_serve/flow/templates/en/chat-data-awel-flow-template.json b/packages/dbgpt-serve/src/dbgpt_serve/flow/templates/en/chat-data-awel-flow-template.json new file mode 100644 index 000000000..9927d3e9f --- /dev/null +++ b/packages/dbgpt-serve/src/dbgpt_serve/flow/templates/en/chat-data-awel-flow-template.json @@ -0,0 +1,1508 @@ +{ + "flow": { + "uid": "19a01439-274c-42d0-a89b-e17d4f128bc8", + "label": "Chat Data AWEL flow template(text2SQL)", + "name": "chat_data_awel_flow_template", + "flow_category": "chat_flow", + "description": "An example of a Chat Data with AWEL flow.", + "state": "running", + "error_message": "", + "source": "DBGPT-WEB", + "source_url": null, + "version": "0.1.1", + "define_type": "json", + "editable": true, + "user_name": null, + "sys_code": null, + "dag_id": "flow_dag_chat_data_awel_flow_template_19a01439-274c-42d0-a89b-e17d4f128bc8", + "gmt_created": "2025-05-22 14:59:25", + "gmt_modified": "2025-05-22 14:59:25", + "metadata": { + "sse_output": false, + "streaming_output": false, + "tags": {}, + "triggers": [ + { + "trigger_type": "http", + "path": "/api/v1/awel/trigger/templates/flow_dag_chat_data_awel_flow_template_19a01439-274c-42d0-a89b-e17d4f128bc8", + "methods": [ + "POST" + ], + "trigger_mode": "chat" + } + ] + }, + "variables": null, + "authors": null, + "flow_data": { + "edges": [ + { + "source": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "source_order": 0, + "target": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "target_order": 1, + "id": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0|operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "source_handle": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0|outputs|0", + "target_handle": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|inputs|1", + "type": "buttonedge" + }, + { + "source": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "source_order": 0, + "target": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "target_order": 0, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "source_handle": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|outputs|0", + "target_handle": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "source_order": 0, + "target": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "target_order": 0, + "id": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "source_handle": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|outputs|0", + "target_handle": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "source_order": 0, + "target": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "target_order": 0, + "id": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0|operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "source_handle": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0|outputs|0", + "target_handle": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0|parameters|0", + "type": "buttonedge" + }, + { + "source": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "source_order": 1, + "target": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "target_order": 0, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "source_handle": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|outputs|1", + "target_handle": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0", + "source_order": 0, + "target": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "target_order": 0, + "id": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0|operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "source_handle": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0|outputs|0", + "target_handle": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|parameters|0", + "type": "buttonedge" + }, + { + "source": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "source_order": 0, + "target": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "target_order": 0, + "id": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0|operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "source_handle": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0|outputs|0", + "target_handle": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|parameters|0", + "type": "buttonedge" + }, + { + "source": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "source_order": 0, + "target": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "target_order": 0, + "id": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0|operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "source_handle": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0|outputs|0", + "target_handle": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "source_order": 1, + "target": "operator_report_analyst___$$___database___$$___v1_0", + "target_order": 0, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|operator_report_analyst___$$___database___$$___v1_0", + "source_handle": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|outputs|1", + "target_handle": "operator_report_analyst___$$___database___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "source_order": 1, + "target": "operator_report_analyst___$$___database___$$___v1_0", + "target_order": 1, + "id": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|operator_report_analyst___$$___database___$$___v1_0", + "source_handle": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|outputs|1", + "target_handle": "operator_report_analyst___$$___database___$$___v1_0|inputs|1", + "type": "buttonedge" + }, + { + "source": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "source_order": 0, + "target": "operator_string_join_operator___$$___common___$$___v1_0", + "target_order": 0, + "id": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|operator_string_join_operator___$$___common___$$___v1_0", + "source_handle": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|outputs|0", + "target_handle": "operator_string_join_operator___$$___common___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "operator_report_analyst___$$___database___$$___v1_0", + "source_order": 0, + "target": "operator_string_join_operator___$$___common___$$___v1_0", + "target_order": 1, + "id": "operator_report_analyst___$$___database___$$___v1_0|operator_string_join_operator___$$___common___$$___v1_0", + "source_handle": "operator_report_analyst___$$___database___$$___v1_0|outputs|0", + "target_handle": "operator_string_join_operator___$$___common___$$___v1_0|inputs|1", + "type": "buttonedge" + } + ], + "viewport": { + "x": 1116.3972338038218, + "y": 490.6688566220062, + "zoom": 0.41591281486101733 + }, + "nodes": [ + { + "width": 320, + "height": 632, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "position": { + "x": -2313.3658407389785, + "y": -1002.9252154383745, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -2313.3658407389785, + "y": -1002.9252154383745, + "zoom": 0.0 + }, + "data": { + "label": "Common LLM Http Trigger", + "custom_label": null, + "name": "common_llm_http_trigger", + "description": "Trigger your workflow by http request, and parse the request body as a common LLM http body", + "category": "trigger", + "category_label": "Trigger", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "input", + "inputs": [], + "outputs": [ + { + "type_name": "CommonLLMHttpRequestBody", + "type_cls": "dbgpt.core.awel.trigger.http_trigger.CommonLLMHttpRequestBody", + "label": "Request Body", + "custom_label": null, + "name": "request_body", + "description": "The request body of the API endpoint, parse as a common LLM http body", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Request String Messages", + "custom_label": null, + "name": "request_string_messages", + "description": "The request string messages of the API endpoint, parsed from 'messages' field of the request body", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": [ + "dbgpt.core.awel.trigger.http_trigger.CommonLLMHttpTrigger.MessagesOutputMapper" + ] + } + ], + "version": "v1", + "type_name": "CommonLLMHttpTrigger", + "type_cls": "dbgpt.core.awel.trigger.http_trigger.CommonLLMHttpTrigger", + "parameters": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "API Endpoint", + "name": "endpoint", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "/example/{dag_id}", + "placeholder": null, + "description": "The API endpoint", + "value": "/templates/{dag_id}", + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Http Methods", + "name": "methods", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "POST", + "placeholder": null, + "description": "The methods of the API endpoint", + "value": null, + "options": [ + { + "label": "HTTP Method PUT", + "name": "http_put", + "value": "PUT", + "children": null + }, + { + "label": "HTTP Method POST", + "name": "http_post", + "value": "POST", + "children": null + } + ] + }, + { + "type_name": "bool", + "type_cls": "builtins.bool", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Streaming Response", + "name": "streaming_response", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": false, + "placeholder": null, + "description": "Whether the response is streaming", + "value": false, + "options": null + }, + { + "type_name": "BaseHttpBody", + "type_cls": "dbgpt.core.awel.trigger.http_trigger.BaseHttpBody", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Http Response Body", + "name": "http_response_body", + "is_list": false, + "category": "resource", + "resource_type": "class", + "optional": true, + "default": null, + "placeholder": null, + "description": "The response body of the API endpoint", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Response Media Type", + "name": "response_media_type", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The response media type", + "value": null, + "options": null + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Http Status Code", + "name": "status_code", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": 200, + "placeholder": null, + "description": "The http status code", + "value": null, + "options": null + } + ] + } + }, + { + "width": 530, + "height": 510, + "id": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0", + "position": { + "x": -1184.9263798381871, + "y": -676.5641257209899, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -1184.9263798381871, + "y": -676.5641257209899, + "zoom": 0.0 + }, + "data": { + "type_name": "CommonChatPromptTemplate", + "type_cls": "dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate", + "label": "Common Chat Prompt Template", + "custom_label": null, + "name": "common_chat_prompt_template", + "description": "The operator to build the prompt with static prompt.", + "category": "prompt", + "category_label": "Prompt", + "flow_type": "resource", + "icon": null, + "documentation_url": null, + "id": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0", + "ui_size": "large" + }, + "resource_type": "instance", + "parent_cls": [ + "dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate", + "dbgpt.core.interface.prompt.ChatPromptTemplate", + "dbgpt.core.interface.prompt.BasePromptTemplate", + "pydantic.main.BaseModel" + ], + "parameters": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "System Message", + "name": "system_message", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "You are a helpful AI Assistant.", + "placeholder": null, + "description": "The system message.", + "value": "{context}\n\nwhen answering, use the same language as the \"user\".", + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Message placeholder", + "name": "message_placeholder", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "chat_history", + "placeholder": null, + "description": "The chat history message placeholder.", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Human Message", + "name": "human_message", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "{user_input}", + "placeholder": "{user_input}", + "description": "The human message.", + "value": null, + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + } + ] + } + }, + { + "width": 530, + "height": 1591, + "id": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "position": { + "x": -1607.0149406814228, + "y": -18.44314634213356, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -1607.0149406814228, + "y": -18.44314634213356, + "zoom": 0.0 + }, + "data": { + "label": "Datasource Retriever Operator", + "custom_label": null, + "name": "higher_order_datasource_retriever_operator", + "description": "Retrieve the table schemas from the datasource.", + "category": "database", + "category_label": "Database", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0", + "ui_size": "large" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "User question", + "custom_label": null, + "name": "query", + "description": "The user question to retrieve table schemas from the datasource", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "HOContextBody", + "type_cls": "dbgpt_app.operators.llm.HOContextBody", + "label": "Retrieved context", + "custom_label": null, + "name": "context", + "description": "The retrieved context from the datasource", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "Chunk", + "type_cls": "dbgpt.core.interface.knowledge.Chunk", + "label": "Retrieved schema chunks", + "custom_label": null, + "name": "chunks", + "description": "The retrieved schema chunks from the datasource", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": true, + "mappers": [ + "dbgpt_app.operators.datasource.HODatasourceRetrieverOperator.ChunkMapper" + ] + } + ], + "version": "v1", + "type_name": "HODatasourceRetrieverOperator", + "type_cls": "dbgpt_app.operators.datasource.HODatasourceRetrieverOperator", + "parameters": [ + { + "type_name": "DBResource", + "type_cls": "dbgpt.agent.resource.database.DBResource", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Datasource", + "name": "datasource", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": false, + "default": null, + "placeholder": null, + "description": "The datasource to retrieve the context", + "value": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Prompt Template", + "name": "prompt_template", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "You are a database expert. \nPlease answer the user's question based on the database selected by the user and some of the available table structure definitions of the database.\nDatabase name:\n {db_name}\nTable structure definition:\n {table_info}\n\nConstraint:\n 1.Please understand the user's intention based on the user's question, and use the given table structure definition to create a grammatically correct {dialect} sql. If sql is not required, answer the user's question directly.. \n 2.Always limit the query to a maximum of {max_num_results} results unless the user specifies in the question the specific number of rows of data he wishes to obtain.\n 3.You can only use the tables provided in the table structure information to generate sql. If you cannot generate sql based on the provided table structure, please say: \"The table structure information provided is not enough to generate sql queries.\" It is prohibited to fabricate information at will.\n 4.Please be careful not to mistake the relationship between tables and columns when generating SQL.\n 5.Please check the correctness of the SQL and ensure that the query performance is optimized under correct conditions.\n 6.Please choose the best one from the display methods given below for data rendering, and put the type name into the name parameter value that returns the required format. If you cannot find the most suitable one, use 'Table' as the display method. , the available data display methods are as follows: {display_type}\n\nUser Question:\n {user_input}\nPlease think step by step and respond according to the following JSON format:\n {response}\nEnsure the response is correct json and can be parsed by Python json.loads.\n", + "placeholder": null, + "description": "The prompt template to build a database prompt", + "value": null, + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Display Type", + "name": "display_type", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "response_line_chart:used to display comparative trend analysis data\nresponse_pie_chart:suitable for scenarios such as proportion and distribution statistics\nresponse_table:suitable for display with many display columns or non-numeric columns\nresponse_scatter_chart:Suitable for exploring relationships between variables, detecting outliers, etc.\nresponse_bubble_chart:Suitable for relationships between multiple variables, highlighting outliers or special situations, etc.\nresponse_donut_chart:Suitable for hierarchical structure representation, category proportion display and highlighting key categories, etc.\nresponse_area_chart:Suitable for visualization of time series data, comparison of multiple groups of data, analysis of data change trends, etc.\nresponse_heatmap:Suitable for visual analysis of time series data, large-scale data sets, distribution of classified data, etc.", + "placeholder": null, + "description": "The display type for the data", + "value": null, + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Max Number of Results", + "name": "max_num_results", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": 50, + "placeholder": null, + "description": "The maximum number of results to return", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Response Format", + "name": "response_format", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "{\n \"thoughts\": \"thoughts summary to say to user\",\n \"sql\": \"SQL Query to run\",\n \"display_type\": \"Data display method\"\n}", + "placeholder": null, + "description": "The response format, default is a JSON format", + "value": null, + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Context Key", + "name": "context_key", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "context", + "placeholder": null, + "description": "The key of the context, it will be used in building the prompt", + "value": null, + "options": null + } + ] + } + }, + { + "width": 320, + "height": 909, + "id": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "position": { + "x": -356.756339024138, + "y": -1039.8502354026027, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -356.756339024138, + "y": -1039.8502354026027, + "zoom": 0.0 + }, + "data": { + "label": "LLM Operator", + "custom_label": null, + "name": "higher_order_llm_operator", + "description": "High-level LLM operator, supports multi-round conversation (conversation window, token length and no multi-round).", + "category": "llm", + "category_label": "LLM", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "CommonLLMHttpRequestBody", + "type_cls": "dbgpt.core.awel.trigger.http_trigger.CommonLLMHttpRequestBody", + "label": "Common LLM Request Body", + "custom_label": null, + "name": "common_llm_request_body", + "description": "The common LLM request body.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "HOContextBody", + "type_cls": "dbgpt_app.operators.llm.HOContextBody", + "label": "Extra Context", + "custom_label": null, + "name": "extra_context", + "description": "Extra context for building prompt(Knowledge context, database schema, etc), you can add multiple context.", + "dynamic": true, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "ModelOutput", + "type_cls": "dbgpt.core.interface.llm.ModelOutput", + "label": "Model Output", + "custom_label": null, + "name": "model_output", + "description": "The model output.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "version": "v1", + "type_name": "HOLLMOperator", + "type_cls": "dbgpt_app.operators.llm.HOLLMOperator", + "parameters": [ + { + "type_name": "ChatPromptTemplate", + "type_cls": "dbgpt.core.interface.prompt.ChatPromptTemplate", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Prompt Template", + "name": "prompt_template", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The prompt template for the conversation.", + "value": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0", + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Model Name", + "name": "model", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The model name.", + "value": null, + "options": null + }, + { + "type_name": "LLMClient", + "type_cls": "dbgpt.core.interface.llm.LLMClient", + "dynamic": false, + "dynamic_minimum": 0, + "label": "LLM Client", + "name": "llm_client", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The LLM Client, how to connect to the LLM model, if not provided, it will use the default client deployed by DB-GPT.", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "History Message Merge Mode", + "name": "history_merge_mode", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "none", + "placeholder": null, + "description": "The history merge mode, supports 'none', 'window' and 'token'. 'none': no history merge, 'window': merge by conversation window, 'token': merge by token length.", + "value": null, + "options": [ + { + "label": "No History", + "name": "none", + "value": "none", + "children": null + }, + { + "label": "Message Window", + "name": "window", + "value": "window", + "children": null + }, + { + "label": "Token Length", + "name": "token", + "value": "token", + "children": null + } + ], + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "select", + "size": null, + "attr": null + } + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "User Message Key", + "name": "user_message_key", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "user_input", + "placeholder": null, + "description": "The key of the user message in your prompt, default is 'user_input'.", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "History Key", + "name": "history_key", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The chat history key, with chat history message pass to prompt template, if not provided, it will parse the prompt template to get the key.", + "value": null, + "options": null + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Keep Start Rounds", + "name": "keep_start_rounds", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The start rounds to keep in the chat history.", + "value": null, + "options": null + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Keep End Rounds", + "name": "keep_end_rounds", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The end rounds to keep in the chat history.", + "value": null, + "options": null + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Max Token Limit", + "name": "max_token_limit", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": 2048, + "placeholder": null, + "description": "The max token limit to keep in the chat history.", + "value": null, + "options": null + } + ] + } + }, + { + "width": 320, + "height": 235, + "id": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "position": { + "x": -451.3013131580019, + "y": 249.34490166592917, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -451.3013131580019, + "y": 249.34490166592917, + "zoom": 0.0 + }, + "data": { + "label": "SQL Output Parser", + "custom_label": null, + "name": "default_sql_output_parser", + "description": "Parse the SQL output of an LLM call.", + "category": "output_parser", + "category_label": "Output Parser", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "ModelOutput", + "type_cls": "dbgpt.core.interface.llm.ModelOutput", + "label": "Model Output", + "custom_label": null, + "name": "model_output", + "description": "The model output of upstream.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "dict", + "type_cls": "builtins.dict", + "label": "Dict SQL Output", + "custom_label": null, + "name": "dict", + "description": "The dict output after parsing.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "version": "v1", + "type_name": "SQLOutputParser", + "type_cls": "dbgpt.core.interface.output_parser.SQLOutputParser", + "parameters": [] + } + }, + { + "width": 320, + "height": 416, + "id": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "position": { + "x": -2378.805372792085, + "y": 839.3585168597831, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -2378.805372792085, + "y": 839.3585168597831, + "zoom": 0.0 + }, + "data": { + "type_name": "DatasourceResource", + "type_cls": "dbgpt_serve.agent.resource.datasource.DatasourceResource", + "label": "Datasource Resource", + "custom_label": null, + "name": "datasource", + "description": "Connect to a datasource(retrieve table schemas and execute SQL to fetch data).", + "category": "database", + "category_label": "Database", + "flow_type": "resource", + "icon": null, + "documentation_url": null, + "id": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "resource_type": "instance", + "parent_cls": [ + "dbgpt_serve.agent.resource.datasource.DatasourceResource", + "dbgpt.agent.resource.database.RDBMSConnectorResource", + "dbgpt.agent.resource.database.DBResource", + "dbgpt.agent.resource.base.Resource", + "typing.Generic" + ], + "parameters": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Datasource Name", + "name": "name", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "datasource", + "placeholder": null, + "description": "The name of the datasource, default is 'datasource'.", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "DB Name", + "name": "db_name", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": false, + "default": null, + "placeholder": null, + "description": "The name of the database.", + "value": "case_1_student_manager", + "options": [ + { + "label": "[mysql]test_case_info", + "name": "test_case_info", + "value": "test_case_info", + "children": null + }, + { + "label": "[mysql]case_2_ecom", + "name": "case_2_ecom", + "value": "case_2_ecom", + "children": null + }, + { + "label": "[sqlite]sqlite_dbgpt", + "name": "sqlite_dbgpt", + "value": "sqlite_dbgpt", + "children": null + }, + { + "label": "[mysql]case_5_order_management", + "name": "case_5_order_management", + "value": "case_5_order_management", + "children": null + }, + { + "label": "[mysql]case_1_student_manager", + "name": "case_1_student_manager", + "value": "case_1_student_manager", + "children": null + } + ] + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Prompt Template", + "name": "prompt_template", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "Database type: {db_type}, related table structure definition: {schemas}", + "placeholder": null, + "description": "The prompt template to build a database prompt.", + "value": null, + "options": null + } + ] + } + }, + { + "width": 320, + "height": 353, + "id": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "position": { + "x": -52.331743847159714, + "y": 703.9883784083503, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -52.331743847159714, + "y": 703.9883784083503, + "zoom": 0.0 + }, + "data": { + "label": "Datasource Executor Operator", + "custom_label": null, + "name": "higher_order_datasource_executor_operator", + "description": "Execute the context from the datasource.", + "category": "database", + "category_label": "Database", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "dict", + "type_cls": "builtins.dict", + "label": "SQL dict", + "custom_label": null, + "name": "sql_dict", + "description": "The SQL to be executed wrapped in a dictionary, generated by LLM", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "SQL result", + "custom_label": null, + "name": "sql_result", + "description": "The result of the SQL execution(GPT-Vis format)", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Markdown result", + "custom_label": null, + "name": "markdown_result", + "description": "The markdown result of the SQL execution", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": [ + "dbgpt_app.operators.datasource.HODatasourceExecutorOperator.MarkdownMapper" + ] + } + ], + "version": "v1", + "type_name": "HODatasourceExecutorOperator", + "type_cls": "dbgpt_app.operators.datasource.HODatasourceExecutorOperator", + "parameters": [ + { + "type_name": "DBResource", + "type_cls": "dbgpt.agent.resource.database.DBResource", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Datasource", + "name": "datasource", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": false, + "default": null, + "placeholder": null, + "description": "The datasource to retrieve the context", + "value": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "options": null + } + ] + } + }, + { + "width": 320, + "height": 475, + "id": "operator_report_analyst___$$___database___$$___v1_0", + "position": { + "x": 535.8317267481011, + "y": 1282.938921503293, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": 535.8317267481011, + "y": 1282.938921503293, + "zoom": 0.0 + }, + "data": { + "label": "Report Analyst", + "custom_label": null, + "name": "report_analyst", + "description": "Report Analyst", + "category": "database", + "category_label": "Database", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_report_analyst___$$___database___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "User question", + "custom_label": null, + "name": "question", + "description": "The question of user", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "The data report", + "custom_label": null, + "name": "data_report", + "description": "The data report in markdown format.", + "dynamic": true, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Report Analyst Result", + "custom_label": null, + "name": "report_analyst_result", + "description": "The report analyst result.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "version": "v1", + "type_name": "ReportAnalystOperator", + "type_cls": "dbgpt_app.operators.report.ReportAnalystOperator", + "parameters": [ + { + "type_name": "ChatPromptTemplate", + "type_cls": "dbgpt.core.interface.prompt.ChatPromptTemplate", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Prompt Template", + "name": "prompt_template", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The prompt template for the conversation.", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Model Name", + "name": "model", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The model name.", + "value": null, + "options": null + }, + { + "type_name": "LLMClient", + "type_cls": "dbgpt.core.interface.llm.LLMClient", + "dynamic": false, + "dynamic_minimum": 0, + "label": "LLM Client", + "name": "llm_client", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "The LLM Client, how to connect to the LLM model, if not provided, it will use the default client deployed by DB-GPT.", + "value": null, + "options": null + } + ] + } + }, + { + "width": 320, + "height": 398, + "id": "operator_string_join_operator___$$___common___$$___v1_0", + "position": { + "x": 881.1680168204623, + "y": 328.6839328760358, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": 881.1680168204623, + "y": 328.6839328760358, + "zoom": 0.0 + }, + "data": { + "label": "String Join Operator", + "custom_label": null, + "name": "string_join_operator", + "description": "Merge multiple inputs into a single string.", + "category": "common", + "category_label": "Common", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_string_join_operator___$$___common___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Input Strings", + "custom_label": null, + "name": "input_strings", + "description": "The input strings to join.", + "dynamic": true, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Input Strings", + "custom_label": null, + "name": "input_strings_1", + "description": "The input strings to join.", + "dynamic": true, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Joined String", + "custom_label": null, + "name": "joined_string", + "description": "The joined string.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "version": "v1", + "type_name": "StringJoinOperator", + "type_cls": "dbgpt_app.operators.report.StringJoinOperator", + "parameters": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Separator", + "name": "separator", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "\n\n", + "placeholder": null, + "description": "The separator to join the strings.", + "value": null, + "options": null + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/packages/dbgpt-serve/src/dbgpt_serve/flow/templates/zh/chat-data-awel-flow-template.json b/packages/dbgpt-serve/src/dbgpt_serve/flow/templates/zh/chat-data-awel-flow-template.json new file mode 100644 index 000000000..1a6c34bfc --- /dev/null +++ b/packages/dbgpt-serve/src/dbgpt_serve/flow/templates/zh/chat-data-awel-flow-template.json @@ -0,0 +1,1508 @@ +{ + "flow": { + "uid": "19a01439-274c-42d0-a89b-e17d4f128bc8", + "label": "Chat Data 工作流模板(text2SQL)", + "name": "chat_data_awel_flow_template", + "flow_category": "chat_flow", + "description": "Chat Data 工作流模板,生成SQL查询并执行,然后给出分析报告", + "state": "running", + "error_message": "", + "source": "DBGPT-WEB", + "source_url": null, + "version": "0.1.1", + "define_type": "json", + "editable": true, + "user_name": null, + "sys_code": null, + "dag_id": "flow_dag_chat_data_awel_flow_template_19a01439-274c-42d0-a89b-e17d4f128bc8", + "gmt_created": "2025-05-22 14:59:25", + "gmt_modified": "2025-05-22 14:59:25", + "metadata": { + "sse_output": false, + "streaming_output": false, + "tags": {}, + "triggers": [ + { + "trigger_type": "http", + "path": "/api/v1/awel/trigger/templates/flow_dag_chat_data_awel_flow_template_19a01439-274c-42d0-a89b-e17d4f128bc8", + "methods": [ + "POST" + ], + "trigger_mode": "chat" + } + ] + }, + "variables": null, + "authors": null, + "flow_data": { + "edges": [ + { + "source": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "source_order": 0, + "target": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "target_order": 1, + "id": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0|operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "source_handle": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0|outputs|0", + "target_handle": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|inputs|1", + "type": "buttonedge" + }, + { + "source": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "source_order": 0, + "target": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "target_order": 0, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "source_handle": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|outputs|0", + "target_handle": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "source_order": 0, + "target": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "target_order": 0, + "id": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "source_handle": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|outputs|0", + "target_handle": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "source_order": 0, + "target": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "target_order": 0, + "id": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0|operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "source_handle": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0|outputs|0", + "target_handle": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0|parameters|0", + "type": "buttonedge" + }, + { + "source": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "source_order": 1, + "target": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "target_order": 0, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "source_handle": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|outputs|1", + "target_handle": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0", + "source_order": 0, + "target": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "target_order": 0, + "id": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0|operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "source_handle": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0|outputs|0", + "target_handle": "operator_higher_order_llm_operator___$$___llm___$$___v1_0|parameters|0", + "type": "buttonedge" + }, + { + "source": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "source_order": 0, + "target": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "target_order": 0, + "id": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0|operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "source_handle": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0|outputs|0", + "target_handle": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|parameters|0", + "type": "buttonedge" + }, + { + "source": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "source_order": 0, + "target": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "target_order": 0, + "id": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0|operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "source_handle": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0|outputs|0", + "target_handle": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "source_order": 1, + "target": "operator_report_analyst___$$___database___$$___v1_0", + "target_order": 0, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|operator_report_analyst___$$___database___$$___v1_0", + "source_handle": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0|outputs|1", + "target_handle": "operator_report_analyst___$$___database___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "source_order": 1, + "target": "operator_report_analyst___$$___database___$$___v1_0", + "target_order": 1, + "id": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|operator_report_analyst___$$___database___$$___v1_0", + "source_handle": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|outputs|1", + "target_handle": "operator_report_analyst___$$___database___$$___v1_0|inputs|1", + "type": "buttonedge" + }, + { + "source": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "source_order": 0, + "target": "operator_string_join_operator___$$___common___$$___v1_0", + "target_order": 0, + "id": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|operator_string_join_operator___$$___common___$$___v1_0", + "source_handle": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0|outputs|0", + "target_handle": "operator_string_join_operator___$$___common___$$___v1_0|inputs|0", + "type": "buttonedge" + }, + { + "source": "operator_report_analyst___$$___database___$$___v1_0", + "source_order": 0, + "target": "operator_string_join_operator___$$___common___$$___v1_0", + "target_order": 1, + "id": "operator_report_analyst___$$___database___$$___v1_0|operator_string_join_operator___$$___common___$$___v1_0", + "source_handle": "operator_report_analyst___$$___database___$$___v1_0|outputs|0", + "target_handle": "operator_string_join_operator___$$___common___$$___v1_0|inputs|1", + "type": "buttonedge" + } + ], + "viewport": { + "x": 1116.3972338038218, + "y": 490.6688566220062, + "zoom": 0.41591281486101733 + }, + "nodes": [ + { + "width": 320, + "height": 632, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "position": { + "x": -2313.3658407389785, + "y": -1002.9252154383745, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -2313.3658407389785, + "y": -1002.9252154383745, + "zoom": 0.0 + }, + "data": { + "label": "通用大语言模型 HTTP 触发器", + "custom_label": null, + "name": "common_llm_http_trigger", + "description": "通过 HTTP 请求触发工作流,并将请求体解析为通用大语言模型 HTTP 请求体", + "category": "trigger", + "category_label": "Trigger", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_common_llm_http_trigger___$$___trigger___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "input", + "inputs": [], + "outputs": [ + { + "type_name": "CommonLLMHttpRequestBody", + "type_cls": "dbgpt.core.awel.trigger.http_trigger.CommonLLMHttpRequestBody", + "label": "Request Body", + "custom_label": null, + "name": "request_body", + "description": "The request body of the API endpoint, parse as a common LLM http body", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Request String Messages", + "custom_label": null, + "name": "request_string_messages", + "description": "The request string messages of the API endpoint, parsed from 'messages' field of the request body", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": [ + "dbgpt.core.awel.trigger.http_trigger.CommonLLMHttpTrigger.MessagesOutputMapper" + ] + } + ], + "version": "v1", + "type_name": "CommonLLMHttpTrigger", + "type_cls": "dbgpt.core.awel.trigger.http_trigger.CommonLLMHttpTrigger", + "parameters": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "API 端点", + "name": "endpoint", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "/example/{dag_id}", + "placeholder": null, + "description": "该 API 端点", + "value": "/templates/{dag_id}", + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "HTTP 方法", + "name": "methods", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "POST", + "placeholder": null, + "description": "API 端点的方法", + "value": null, + "options": [ + { + "label": "HTTP Method PUT", + "name": "http_put", + "value": "PUT", + "children": null + }, + { + "label": "HTTP Method POST", + "name": "http_post", + "value": "POST", + "children": null + } + ] + }, + { + "type_name": "bool", + "type_cls": "builtins.bool", + "dynamic": false, + "dynamic_minimum": 0, + "label": "流式响应", + "name": "streaming_response", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": false, + "placeholder": null, + "description": "响应是否为流式", + "value": false, + "options": null + }, + { + "type_name": "BaseHttpBody", + "type_cls": "dbgpt.core.awel.trigger.http_trigger.BaseHttpBody", + "dynamic": false, + "dynamic_minimum": 0, + "label": "HTTP 响应体", + "name": "http_response_body", + "is_list": false, + "category": "resource", + "resource_type": "class", + "optional": true, + "default": null, + "placeholder": null, + "description": "API 端点的响应体", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "响应媒体类型", + "name": "response_media_type", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "响应媒体类型", + "value": null, + "options": null + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "HTTP 状态码", + "name": "status_code", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": 200, + "placeholder": null, + "description": "HTTP 状态码", + "value": null, + "options": null + } + ] + } + }, + { + "width": 530, + "height": 510, + "id": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0", + "position": { + "x": -1184.9263798381871, + "y": -676.5641257209899, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -1184.9263798381871, + "y": -676.5641257209899, + "zoom": 0.0 + }, + "data": { + "type_name": "CommonChatPromptTemplate", + "type_cls": "dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate", + "label": "通用聊天提示模板", + "custom_label": null, + "name": "common_chat_prompt_template", + "description": "使用静态提示构建提示的算子。", + "category": "prompt", + "category_label": "Prompt", + "flow_type": "resource", + "icon": null, + "documentation_url": null, + "id": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0", + "ui_size": "large" + }, + "resource_type": "instance", + "parent_cls": [ + "dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate", + "dbgpt.core.interface.prompt.ChatPromptTemplate", + "dbgpt.core.interface.prompt.BasePromptTemplate", + "pydantic.main.BaseModel" + ], + "parameters": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "系统消息", + "name": "system_message", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "You are a helpful AI Assistant.", + "placeholder": null, + "description": "系统消息。", + "value": "{context}\n\nwhen answering, use the same language as the \"user\".", + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "消息占位符", + "name": "message_placeholder", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "chat_history", + "placeholder": null, + "description": "聊天历史消息占位符。", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "用户消息", + "name": "human_message", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "{user_input}", + "placeholder": "{user_input}", + "description": "用户消息。", + "value": null, + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + } + ] + } + }, + { + "width": 530, + "height": 1591, + "id": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "position": { + "x": -1607.0149406814228, + "y": -18.44314634213356, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -1607.0149406814228, + "y": -18.44314634213356, + "zoom": 0.0 + }, + "data": { + "label": "数据源检索算子", + "custom_label": null, + "name": "higher_order_datasource_retriever_operator", + "description": "从数据源检索表结构。", + "category": "database", + "category_label": "Database", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_higher_order_datasource_retriever_operator___$$___database___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0", + "ui_size": "large" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "User question", + "custom_label": null, + "name": "query", + "description": "The user question to retrieve table schemas from the datasource", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "HOContextBody", + "type_cls": "dbgpt_app.operators.llm.HOContextBody", + "label": "Retrieved context", + "custom_label": null, + "name": "context", + "description": "The retrieved context from the datasource", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "Chunk", + "type_cls": "dbgpt.core.interface.knowledge.Chunk", + "label": "Retrieved schema chunks", + "custom_label": null, + "name": "chunks", + "description": "The retrieved schema chunks from the datasource", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": true, + "mappers": [ + "dbgpt_app.operators.datasource.HODatasourceRetrieverOperator.ChunkMapper" + ] + } + ], + "version": "v1", + "type_name": "HODatasourceRetrieverOperator", + "type_cls": "dbgpt_app.operators.datasource.HODatasourceRetrieverOperator", + "parameters": [ + { + "type_name": "DBResource", + "type_cls": "dbgpt.agent.resource.database.DBResource", + "dynamic": false, + "dynamic_minimum": 0, + "label": "数据源", + "name": "datasource", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": false, + "default": null, + "placeholder": null, + "description": "用于获取上下文的数据源", + "value": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "提示模板", + "name": "prompt_template", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "你是一个数据库专家. \n请根据用户选择的数据库和该库的部分可用表结构定义来回答用户问题.\n数据库名:\n {db_name}\n表结构定义:\n {table_info}\n\n约束:\n 1. 请根据用户问题理解用户意图,使用给出表结构定义创建一个语法正确的 {dialect} sql,如果不需要 sql,则直接回答用户问题。\n 2. 除非用户在问题中指定了他希望获得的具体数据行数, 否则始终将查询限制为最多 {max_num_results} 个结果。\n 3. 只能使用表结构信息中提供的表来生成 sql, 如果无法根据提供的表结构中生成 sql ,请说: “提供的表结构信息不足以生成 sql 查询。” 禁止随意捏造信息。\n 4. 请注意生成SQL时不要弄错表和列的关系\n 5. 请检查SQL的正确性,并保证正确的情况下优化查询性能\n 6.请从如下给出的展示方式种选择最优的一种用以进行数据渲染,将类型名称放入返回要求格式的name参数值中 ,如果找不到最合适的则使用'Table'作为展示方式,可用数据展示方式如下: {display_type}\n用户问题:\n {user_input}\n请一步步思考并按照以下JSON格式回复:\n {response}\n确保返回正确的json并且可以被Python json.loads方法解析.\n", + "placeholder": null, + "description": "用于构建数据库提示的提示模板", + "value": null, + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "显示类型", + "name": "display_type", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "response_line_chart:used to display comparative trend analysis data\nresponse_pie_chart:suitable for scenarios such as proportion and distribution statistics\nresponse_table:suitable for display with many display columns or non-numeric columns\nresponse_scatter_chart:Suitable for exploring relationships between variables, detecting outliers, etc.\nresponse_bubble_chart:Suitable for relationships between multiple variables, highlighting outliers or special situations, etc.\nresponse_donut_chart:Suitable for hierarchical structure representation, category proportion display and highlighting key categories, etc.\nresponse_area_chart:Suitable for visualization of time series data, comparison of multiple groups of data, analysis of data change trends, etc.\nresponse_heatmap:Suitable for visual analysis of time series data, large-scale data sets, distribution of classified data, etc.", + "placeholder": null, + "description": "数据的显示类型", + "value": null, + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "最大结果数量", + "name": "max_num_results", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": 50, + "placeholder": null, + "description": "返回的最大结果数量", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "响应格式", + "name": "response_format", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "{\n \"thoughts\": \"thoughts summary to say to user\",\n \"sql\": \"SQL Query to run\",\n \"display_type\": \"Data display method\"\n}", + "placeholder": null, + "description": "响应格式,默认为 JSON 格式", + "value": null, + "options": null, + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "text_area", + "size": "large", + "attr": { + "disabled": false, + "status": null, + "prefix": null, + "suffix": null, + "show_count": null, + "max_length": null, + "auto_size": { + "min_rows": 2, + "max_rows": 20 + } + }, + "editor": { + "width": 800, + "height": 400 + } + } + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "上下文键", + "name": "context_key", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "context", + "placeholder": null, + "description": "上下文的键,它将用于构建提示信息", + "value": null, + "options": null + } + ] + } + }, + { + "width": 320, + "height": 909, + "id": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "position": { + "x": -356.756339024138, + "y": -1039.8502354026027, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -356.756339024138, + "y": -1039.8502354026027, + "zoom": 0.0 + }, + "data": { + "label": "大语言模型算子", + "custom_label": null, + "name": "higher_order_llm_operator", + "description": "高级大语言模型算子,支持多轮对话(对话窗口、Token 长度和无多轮)。", + "category": "llm", + "category_label": "LLM", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_higher_order_llm_operator___$$___llm___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "CommonLLMHttpRequestBody", + "type_cls": "dbgpt.core.awel.trigger.http_trigger.CommonLLMHttpRequestBody", + "label": "Common LLM Request Body", + "custom_label": null, + "name": "common_llm_request_body", + "description": "The common LLM request body.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "HOContextBody", + "type_cls": "dbgpt_app.operators.llm.HOContextBody", + "label": "Extra Context", + "custom_label": null, + "name": "extra_context", + "description": "Extra context for building prompt(Knowledge context, database schema, etc), you can add multiple context.", + "dynamic": true, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "ModelOutput", + "type_cls": "dbgpt.core.interface.llm.ModelOutput", + "label": "Model Output", + "custom_label": null, + "name": "model_output", + "description": "The model output.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "version": "v1", + "type_name": "HOLLMOperator", + "type_cls": "dbgpt_app.operators.llm.HOLLMOperator", + "parameters": [ + { + "type_name": "ChatPromptTemplate", + "type_cls": "dbgpt.core.interface.prompt.ChatPromptTemplate", + "dynamic": false, + "dynamic_minimum": 0, + "label": "提示模板", + "name": "prompt_template", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "对话的提示模板。", + "value": "resource_dbgpt.core.interface.operators.prompt_operator.CommonChatPromptTemplate_0", + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "模型名称", + "name": "model", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "模型名称。", + "value": null, + "options": null + }, + { + "type_name": "LLMClient", + "type_cls": "dbgpt.core.interface.llm.LLMClient", + "dynamic": false, + "dynamic_minimum": 0, + "label": "LLM 客户端", + "name": "llm_client", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "大语言模型客户端,用于连接到大语言模型,若未提供,则使用 DB-GPT 部署的默认客户端。", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "历史消息合并模式", + "name": "history_merge_mode", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "none", + "placeholder": null, + "description": "历史合并模式,支持 'none'、'window' 和 'token'。'none':不合并历史,'window':按对话窗口合并,'token':按 Token 长度合并。", + "value": null, + "options": [ + { + "label": "No History", + "name": "none", + "value": "none", + "children": null + }, + { + "label": "Message Window", + "name": "window", + "value": "window", + "children": null + }, + { + "label": "Token Length", + "name": "token", + "value": "token", + "children": null + } + ], + "ui": { + "refresh": false, + "refresh_depends": null, + "ui_type": "select", + "size": null, + "attr": null + } + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "用户消息键", + "name": "user_message_key", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "user_input", + "placeholder": null, + "description": "提示词中用户消息的键,默认为 'user_input'。", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "历史键", + "name": "history_key", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "聊天历史键,用于将聊天历史消息传递给提示模板,若未提供,将解析提示模板以获取该键。", + "value": null, + "options": null + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "保留起始轮次", + "name": "keep_start_rounds", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "在聊天历史中保留的起始轮次。", + "value": null, + "options": null + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "保留结束轮次", + "name": "keep_end_rounds", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "在聊天历史中保留的结束轮次。", + "value": null, + "options": null + }, + { + "type_name": "int", + "type_cls": "builtins.int", + "dynamic": false, + "dynamic_minimum": 0, + "label": "最大 Token 限制", + "name": "max_token_limit", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": 2048, + "placeholder": null, + "description": "在聊天历史中保留的最大 Token 数量。", + "value": null, + "options": null + } + ] + } + }, + { + "width": 320, + "height": 235, + "id": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "position": { + "x": -451.3013131580019, + "y": 249.34490166592917, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -451.3013131580019, + "y": 249.34490166592917, + "zoom": 0.0 + }, + "data": { + "label": "SQL 输出解析器", + "custom_label": null, + "name": "default_sql_output_parser", + "description": "解析大语言模型调用的 SQL 输出。", + "category": "output_parser", + "category_label": "Output Parser", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_default_sql_output_parser___$$___output_parser___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "ModelOutput", + "type_cls": "dbgpt.core.interface.llm.ModelOutput", + "label": "Model Output", + "custom_label": null, + "name": "model_output", + "description": "The model output of upstream.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "dict", + "type_cls": "builtins.dict", + "label": "Dict SQL Output", + "custom_label": null, + "name": "dict", + "description": "The dict output after parsing.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "version": "v1", + "type_name": "SQLOutputParser", + "type_cls": "dbgpt.core.interface.output_parser.SQLOutputParser", + "parameters": [] + } + }, + { + "width": 320, + "height": 416, + "id": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "position": { + "x": -2378.805372792085, + "y": 839.3585168597831, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -2378.805372792085, + "y": 839.3585168597831, + "zoom": 0.0 + }, + "data": { + "type_name": "DatasourceResource", + "type_cls": "dbgpt_serve.agent.resource.datasource.DatasourceResource", + "label": "数据源资源", + "custom_label": null, + "name": "datasource", + "description": "连接到数据源(检索表结构并执行 SQL 以获取数据)。", + "category": "database", + "category_label": "Database", + "flow_type": "resource", + "icon": null, + "documentation_url": null, + "id": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "resource_type": "instance", + "parent_cls": [ + "dbgpt_serve.agent.resource.datasource.DatasourceResource", + "dbgpt.agent.resource.database.RDBMSConnectorResource", + "dbgpt.agent.resource.database.DBResource", + "dbgpt.agent.resource.base.Resource", + "typing.Generic" + ], + "parameters": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "数据源名称", + "name": "name", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "datasource", + "placeholder": null, + "description": "数据源的名称,默认为 'datasource'。", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "数据库名称", + "name": "db_name", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": false, + "default": null, + "placeholder": null, + "description": "数据库的名称。", + "value": "case_1_student_manager", + "options": [ + { + "label": "[mysql]test_case_info", + "name": "test_case_info", + "value": "test_case_info", + "children": null + }, + { + "label": "[mysql]case_2_ecom", + "name": "case_2_ecom", + "value": "case_2_ecom", + "children": null + }, + { + "label": "[sqlite]sqlite_dbgpt", + "name": "sqlite_dbgpt", + "value": "sqlite_dbgpt", + "children": null + }, + { + "label": "[mysql]case_5_order_management", + "name": "case_5_order_management", + "value": "case_5_order_management", + "children": null + }, + { + "label": "[mysql]case_1_student_manager", + "name": "case_1_student_manager", + "value": "case_1_student_manager", + "children": null + } + ] + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "提示模板", + "name": "prompt_template", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "数据库类型:{db_type},相关表结构定义:{schemas}", + "placeholder": null, + "description": "用于构建数据库提示的提示模板。", + "value": null, + "options": null + } + ] + } + }, + { + "width": 320, + "height": 353, + "id": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "position": { + "x": -52.331743847159714, + "y": 703.9883784083503, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": -52.331743847159714, + "y": 703.9883784083503, + "zoom": 0.0 + }, + "data": { + "label": "数据源执行算子", + "custom_label": null, + "name": "higher_order_datasource_executor_operator", + "description": "从数据源执行上下文。", + "category": "database", + "category_label": "Database", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_higher_order_datasource_executor_operator___$$___database___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "dict", + "type_cls": "builtins.dict", + "label": "SQL dict", + "custom_label": null, + "name": "sql_dict", + "description": "The SQL to be executed wrapped in a dictionary, generated by LLM", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "SQL result", + "custom_label": null, + "name": "sql_result", + "description": "The result of the SQL execution(GPT-Vis format)", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Markdown result", + "custom_label": null, + "name": "markdown_result", + "description": "The markdown result of the SQL execution", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": [ + "dbgpt_app.operators.datasource.HODatasourceExecutorOperator.MarkdownMapper" + ] + } + ], + "version": "v1", + "type_name": "HODatasourceExecutorOperator", + "type_cls": "dbgpt_app.operators.datasource.HODatasourceExecutorOperator", + "parameters": [ + { + "type_name": "DBResource", + "type_cls": "dbgpt.agent.resource.database.DBResource", + "dynamic": false, + "dynamic_minimum": 0, + "label": "数据源", + "name": "datasource", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": false, + "default": null, + "placeholder": null, + "description": "用于获取上下文的数据源", + "value": "resource_dbgpt_serve.agent.resource.datasource.DatasourceResource_0", + "options": null + } + ] + } + }, + { + "width": 320, + "height": 475, + "id": "operator_report_analyst___$$___database___$$___v1_0", + "position": { + "x": 535.8317267481011, + "y": 1282.938921503293, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": 535.8317267481011, + "y": 1282.938921503293, + "zoom": 0.0 + }, + "data": { + "label": "Report Analyst", + "custom_label": null, + "name": "report_analyst", + "description": "Report Analyst", + "category": "database", + "category_label": "Database", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_report_analyst___$$___database___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "User question", + "custom_label": null, + "name": "question", + "description": "The question of user", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "The data report", + "custom_label": null, + "name": "data_report", + "description": "The data report in markdown format.", + "dynamic": true, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Report Analyst Result", + "custom_label": null, + "name": "report_analyst_result", + "description": "The report analyst result.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "version": "v1", + "type_name": "ReportAnalystOperator", + "type_cls": "dbgpt_app.operators.report.ReportAnalystOperator", + "parameters": [ + { + "type_name": "ChatPromptTemplate", + "type_cls": "dbgpt.core.interface.prompt.ChatPromptTemplate", + "dynamic": false, + "dynamic_minimum": 0, + "label": "提示模板", + "name": "prompt_template", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "对话的提示模板。", + "value": null, + "options": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "模型名称", + "name": "model", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "模型名称。", + "value": null, + "options": null + }, + { + "type_name": "LLMClient", + "type_cls": "dbgpt.core.interface.llm.LLMClient", + "dynamic": false, + "dynamic_minimum": 0, + "label": "LLM 客户端", + "name": "llm_client", + "is_list": false, + "category": "resource", + "resource_type": "instance", + "optional": true, + "default": null, + "placeholder": null, + "description": "大语言模型客户端,用于连接到大语言模型,若未提供,则使用 DB-GPT 部署的默认客户端。", + "value": null, + "options": null + } + ] + } + }, + { + "width": 320, + "height": 398, + "id": "operator_string_join_operator___$$___common___$$___v1_0", + "position": { + "x": 881.1680168204623, + "y": 328.6839328760358, + "zoom": 0.0 + }, + "type": "customNode", + "position_absolute": { + "x": 881.1680168204623, + "y": 328.6839328760358, + "zoom": 0.0 + }, + "data": { + "label": "String Join Operator", + "custom_label": null, + "name": "string_join_operator", + "description": "Merge multiple inputs into a single string.", + "category": "common", + "category_label": "Common", + "flow_type": "operator", + "icon": null, + "documentation_url": null, + "id": "operator_string_join_operator___$$___common___$$___v1_0", + "tags": { + "order": "higher-order", + "ui_version": "flow2.0" + }, + "operator_type": "map", + "inputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Input Strings", + "custom_label": null, + "name": "input_strings", + "description": "The input strings to join.", + "dynamic": true, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + }, + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Input Strings", + "custom_label": null, + "name": "input_strings_1", + "description": "The input strings to join.", + "dynamic": true, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "outputs": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "label": "Joined String", + "custom_label": null, + "name": "joined_string", + "description": "The joined string.", + "dynamic": false, + "dynamic_minimum": 0, + "is_list": false, + "mappers": null + } + ], + "version": "v1", + "type_name": "StringJoinOperator", + "type_cls": "dbgpt_app.operators.report.StringJoinOperator", + "parameters": [ + { + "type_name": "str", + "type_cls": "builtins.str", + "dynamic": false, + "dynamic_minimum": 0, + "label": "Separator", + "name": "separator", + "is_list": false, + "category": "common", + "resource_type": "instance", + "optional": true, + "default": "\n\n", + "placeholder": null, + "description": "The separator to join the strings.", + "value": null, + "options": null + } + ] + } + } + ] + } + } +} \ No newline at end of file diff --git a/tests/intetration_tests/datasource/test_conn_oracle.py b/tests/intetration_tests/datasource/test_conn_oracle.py index 5cc734e09..39bc14adf 100644 --- a/tests/intetration_tests/datasource/test_conn_oracle.py +++ b/tests/intetration_tests/datasource/test_conn_oracle.py @@ -1,22 +1,23 @@ """ - Run unit test with command: pytest dbgpt/datasource/rdbms/tests/test_conn_mysql.py - docker run -itd --name mysql-test -p 3307:3306 -e MYSQL_ROOT_PASSWORD=12345678 mysql:5.7 - mysql -h 127.0.0.1 -uroot -p -P3307 - Enter password: - Welcome to the MySQL monitor. Commands end with ; or \g. - Your MySQL connection id is 2 - Server version: 5.7.41 MySQL Community Server (GPL) +Run unit test with command: pytest dbgpt/datasource/rdbms/tests/test_conn_mysql.py +docker run -itd --name mysql-test -p 3307:3306 -e MYSQL_ROOT_PASSWORD=12345678 mysql:5.7 +mysql -h 127.0.0.1 -uroot -p -P3307 +Enter password: +Welcome to the MySQL monitor. Commands end with ; or \g. +Your MySQL connection id is 2 +Server version: 5.7.41 MySQL Community Server (GPL) - Copyright (c) 2000, 2023, Oracle and/or its affiliates. +Copyright (c) 2000, 2023, Oracle and/or its affiliates. - Oracle is a registered trademark of Oracle Corporation and/or its - affiliates. Other names may be trademarks of their respective - owners. +Oracle is a registered trademark of Oracle Corporation and/or its +affiliates. Other names may be trademarks of their respective +owners. - Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. - - > create database test; +Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. + +> create database test; """ + import pytest from dbgpt_ext.datasource.rdbms.conn_oracle import OracleConnector @@ -27,6 +28,7 @@ CREATE TABLE test ( ) """ + @pytest.fixture def db(): # 注意:Oracle 默认端口是 1521,连接方式建议用 service_name @@ -45,32 +47,37 @@ def db(): except Exception: pass # 如果表不存在也忽略错误 + def test_get_usable_table_names(db): db.run(_create_table_sql) db.run("COMMIT") table_names = db.get_usable_table_names() assert "TEST" in map(str.upper, table_names) + def test_get_table_info(db): db.run(_create_table_sql) db.run("COMMIT") table_info = db.get_table_info() assert "CREATE TABLE TEST" in table_info.upper() + def test_run_no_throw(db): result = db.run_no_throw("this is a error sql") # run_no_throw 返回的是 list,错误时为空 assert result == [] or isinstance(result, list) + def test_get_index_empty(db): db.run(_create_table_sql) db.run("COMMIT") indexes = db.get_indexes("TEST") assert indexes == [] + def test_get_fields(db): - #db.run(_create_table_sql) - #db.run("COMMIT") + # db.run(_create_table_sql) + # db.run("COMMIT") print("进入方法...") fields = db.get_fields("PY_TEST") print("正在打印字段信息...") @@ -81,16 +88,21 @@ def test_get_fields(db): print(f"Is Nullable: {field[3]}") print(f"Column Comment: {field[4]}") print("-" * 30) # 可选的分隔符 - #assert fields[0][0].upper() == "ID" + # assert fields[0][0].upper() == "ID" + def test_get_charset(db): - result = db.run("SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER = 'NLS_CHARACTERSET'") + result = db.run( + "SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER = 'NLS_CHARACTERSET'" + ) assert result[1][0] in ("AL32UTF8", "UTF8") # result[0] 是字段名元组 + def test_get_users(db): users = db.get_users() assert any(user[0].upper() in ("SYS", "SYSTEM") for user in users) + def test_get_database_lists(db): cdb_result = db.run("SELECT CDB FROM V$DATABASE") if cdb_result[1][0] == "YES": @@ -98,4 +110,4 @@ def test_get_database_lists(db): pdb_names = [name[0] for name in databases[1:]] else: pdb_names = ["ORCL"] - assert any(name in ("ORCLPDB1", "ORCL") for name in pdb_names) \ No newline at end of file + assert any(name in ("ORCLPDB1", "ORCL") for name in pdb_names)