balibabu
commited on
Commit
·
565e3eb
1
Parent(s):
8a7a5d9
feat: build nodes and edges from chat bot dsl #918 (#1372)
Browse files### What problem does this PR solve?
feat: build nodes and edges from chat bot dsl #918
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- graph/test/dsl_examples/retrieval_relevant_rewrite_and_generate.json +72 -72
- web/src/pages/flow/list/create-flow-modal.tsx +1 -1
- web/src/pages/flow/list/hooks.ts +7 -1
- web/src/pages/flow/list/index.less +5 -0
- web/src/pages/flow/retrieval-form/index.tsx +10 -1
- web/src/pages/flow/retrieval_relevant_rewrite_and_generate.json +160 -0
- web/src/pages/flow/utils.test.ts +17 -0
graph/test/dsl_examples/retrieval_relevant_rewrite_and_generate.json
CHANGED
@@ -1,79 +1,79 @@
|
|
1 |
{
|
2 |
"components": {
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
},
|
74 |
"history": [],
|
75 |
"messages": [],
|
76 |
"path": [],
|
77 |
-
"reference":
|
78 |
"answer": []
|
79 |
-
}
|
|
|
1 |
{
|
2 |
"components": {
|
3 |
+
"begin": {
|
4 |
+
"obj": {
|
5 |
+
"component_name": "Begin",
|
6 |
+
"params": {
|
7 |
+
"prologue": "Hi there!"
|
8 |
+
}
|
9 |
+
},
|
10 |
+
"downstream": ["answer:0"],
|
11 |
+
"upstream": []
|
12 |
+
},
|
13 |
+
"answer:0": {
|
14 |
+
"obj": {
|
15 |
+
"component_name": "Answer",
|
16 |
+
"params": {}
|
17 |
+
},
|
18 |
+
"downstream": ["retrieval:0"],
|
19 |
+
"upstream": ["begin", "generate:0"]
|
20 |
+
},
|
21 |
+
"retrieval:0": {
|
22 |
+
"obj": {
|
23 |
+
"component_name": "Retrieval",
|
24 |
+
"params": {
|
25 |
+
"similarity_threshold": 0.2,
|
26 |
+
"keywords_similarity_weight": 0.3,
|
27 |
+
"top_n": 6,
|
28 |
+
"top_k": 1024,
|
29 |
+
"rerank_id": "BAAI/bge-reranker-v2-m3",
|
30 |
+
"kb_ids": ["869a236818b811ef91dffa163e197198"],
|
31 |
+
"empty_response": "Sorry, knowledge base has noting related information."
|
32 |
+
}
|
33 |
+
},
|
34 |
+
"downstream": ["relevant:0"],
|
35 |
+
"upstream": ["answer:0", "rewrite:0"]
|
36 |
+
},
|
37 |
+
"relevant:0": {
|
38 |
+
"obj": {
|
39 |
+
"component_name": "Relevant",
|
40 |
+
"params": {
|
41 |
+
"llm_id": "deepseek-chat",
|
42 |
+
"temperature": 0.02,
|
43 |
+
"yes": "generate:0",
|
44 |
+
"no": "rewrite:0"
|
45 |
+
}
|
46 |
+
},
|
47 |
+
"downstream": ["generate:0", "rewrite:0"],
|
48 |
+
"upstream": ["retrieval:0"]
|
49 |
+
},
|
50 |
+
"generate:0": {
|
51 |
+
"obj": {
|
52 |
+
"component_name": "Generate",
|
53 |
+
"params": {
|
54 |
+
"llm_id": "deepseek-chat",
|
55 |
+
"prompt": "You are an intelligent assistant. Please answer the question based on content of knowledge base. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\". Answers need to consider chat history.\n Knowledge base content is as following:\n {input}\n The above is the content of knowledge base.",
|
56 |
+
"temperature": 0.02
|
57 |
+
}
|
58 |
+
},
|
59 |
+
"downstream": ["answer:0"],
|
60 |
+
"upstream": ["relevant:0"]
|
61 |
+
},
|
62 |
+
"rewrite:0": {
|
63 |
+
"obj": {
|
64 |
+
"component_name": "RewriteQuestion",
|
65 |
+
"params": {
|
66 |
+
"llm_id": "deepseek-chat",
|
67 |
+
"temperature": 0.8
|
68 |
+
}
|
69 |
+
},
|
70 |
+
"downstream": ["retrieval:0"],
|
71 |
+
"upstream": ["relevant:0"]
|
72 |
+
}
|
73 |
},
|
74 |
"history": [],
|
75 |
"messages": [],
|
76 |
"path": [],
|
77 |
+
"reference": [],
|
78 |
"answer": []
|
79 |
+
}
|
web/src/pages/flow/list/create-flow-modal.tsx
CHANGED
@@ -80,7 +80,7 @@ const CreateFlowModal = ({
|
|
80 |
</Form.Item>
|
81 |
</Form>
|
82 |
<Title level={5}>Create from templates</Title>
|
83 |
-
<Flex vertical gap={16}>
|
84 |
{list?.map((x) => (
|
85 |
<Card
|
86 |
key={x.id}
|
|
|
80 |
</Form.Item>
|
81 |
</Form>
|
82 |
<Title level={5}>Create from templates</Title>
|
83 |
+
<Flex vertical gap={16} className={styles.templatesBox}>
|
84 |
{list?.map((x) => (
|
85 |
<Card
|
86 |
key={x.id}
|
web/src/pages/flow/list/hooks.ts
CHANGED
@@ -14,6 +14,9 @@ import { useNavigate } from 'umi';
|
|
14 |
// import interpreterBase from '../../../../../graph/test/dsl_examples/interpreter.json';
|
15 |
// import interpreter from '../interpreter.json';
|
16 |
|
|
|
|
|
|
|
17 |
export const useFetchDataOnMount = () => {
|
18 |
const { data, loading } = useFetchFlowList();
|
19 |
|
@@ -43,7 +46,10 @@ export const useSaveFlow = () => {
|
|
43 |
title,
|
44 |
dsl,
|
45 |
// dsl: dslJson,
|
46 |
-
// dsl: {
|
|
|
|
|
|
|
47 |
});
|
48 |
|
49 |
if (ret?.retcode === 0) {
|
|
|
14 |
// import interpreterBase from '../../../../../graph/test/dsl_examples/interpreter.json';
|
15 |
// import interpreter from '../interpreter.json';
|
16 |
|
17 |
+
// import retrievalRelevantRewriteAndGenerateBase from '../../../../../graph/test/dsl_examples/retrieval_relevant_rewrite_and_generate.json';
|
18 |
+
// import retrievalRelevantRewriteAndGenerate from '../retrieval_relevant_rewrite_and_generate.json';
|
19 |
+
|
20 |
export const useFetchDataOnMount = () => {
|
21 |
const { data, loading } = useFetchFlowList();
|
22 |
|
|
|
46 |
title,
|
47 |
dsl,
|
48 |
// dsl: dslJson,
|
49 |
+
// dsl: {
|
50 |
+
// ...retrievalRelevantRewriteAndGenerateBase,
|
51 |
+
// graph: retrievalRelevantRewriteAndGenerate,
|
52 |
+
// },
|
53 |
});
|
54 |
|
55 |
if (ret?.retcode === 0) {
|
web/src/pages/flow/list/index.less
CHANGED
@@ -54,3 +54,8 @@
|
|
54 |
.selectedFlowTemplateCard {
|
55 |
background-color: @selectedBackgroundColor;
|
56 |
}
|
|
|
|
|
|
|
|
|
|
|
|
54 |
.selectedFlowTemplateCard {
|
55 |
background-color: @selectedBackgroundColor;
|
56 |
}
|
57 |
+
|
58 |
+
.templatesBox {
|
59 |
+
max-height: 500px;
|
60 |
+
overflow: auto;
|
61 |
+
}
|
web/src/pages/flow/retrieval-form/index.tsx
CHANGED
@@ -2,8 +2,9 @@ import KnowledgeBaseItem from '@/components/knowledge-base-item';
|
|
2 |
import Rerank from '@/components/rerank';
|
3 |
import SimilaritySlider from '@/components/similarity-slider';
|
4 |
import TopNItem from '@/components/top-n-item';
|
|
|
5 |
import type { FormProps } from 'antd';
|
6 |
-
import { Form } from 'antd';
|
7 |
import { IOperatorForm } from '../interface';
|
8 |
|
9 |
type FieldType = {
|
@@ -19,6 +20,7 @@ const onFinishFailed: FormProps<FieldType>['onFinishFailed'] = (errorInfo) => {
|
|
19 |
};
|
20 |
|
21 |
const RetrievalForm = ({ onValuesChange, form }: IOperatorForm) => {
|
|
|
22 |
return (
|
23 |
<Form
|
24 |
name="basic"
|
@@ -37,6 +39,13 @@ const RetrievalForm = ({ onValuesChange, form }: IOperatorForm) => {
|
|
37 |
<TopNItem></TopNItem>
|
38 |
<Rerank></Rerank>
|
39 |
<KnowledgeBaseItem></KnowledgeBaseItem>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
</Form>
|
41 |
);
|
42 |
};
|
|
|
2 |
import Rerank from '@/components/rerank';
|
3 |
import SimilaritySlider from '@/components/similarity-slider';
|
4 |
import TopNItem from '@/components/top-n-item';
|
5 |
+
import { useTranslate } from '@/hooks/commonHooks';
|
6 |
import type { FormProps } from 'antd';
|
7 |
+
import { Form, Input } from 'antd';
|
8 |
import { IOperatorForm } from '../interface';
|
9 |
|
10 |
type FieldType = {
|
|
|
20 |
};
|
21 |
|
22 |
const RetrievalForm = ({ onValuesChange, form }: IOperatorForm) => {
|
23 |
+
const { t } = useTranslate('flow');
|
24 |
return (
|
25 |
<Form
|
26 |
name="basic"
|
|
|
39 |
<TopNItem></TopNItem>
|
40 |
<Rerank></Rerank>
|
41 |
<KnowledgeBaseItem></KnowledgeBaseItem>
|
42 |
+
<Form.Item
|
43 |
+
name={'empty_response'}
|
44 |
+
label={t('emptyResponse', { keyPrefix: 'chat' })}
|
45 |
+
tooltip={t('emptyResponseTip', { keyPrefix: 'chat' })}
|
46 |
+
>
|
47 |
+
<Input.TextArea placeholder="" rows={4} />
|
48 |
+
</Form.Item>
|
49 |
</Form>
|
50 |
);
|
51 |
};
|
web/src/pages/flow/retrieval_relevant_rewrite_and_generate.json
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"edges": [
|
3 |
+
{
|
4 |
+
"id": "81de838d-a541-4b3f-9d68-9172ffd7c6b4",
|
5 |
+
"label": "",
|
6 |
+
"source": "begin",
|
7 |
+
"target": "answer:0"
|
8 |
+
},
|
9 |
+
{
|
10 |
+
"id": "8fa8daaa-58e7-4494-84c9-d53f379d2550",
|
11 |
+
"label": "",
|
12 |
+
"source": "generate:0",
|
13 |
+
"target": "answer:0"
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"id": "6720a5b8-96bc-4535-8800-ad3f35431a16",
|
17 |
+
"label": "",
|
18 |
+
"source": "answer:0",
|
19 |
+
"target": "retrieval:0"
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"id": "81476d89-707f-4d87-8aa3-fecb9d8499b3",
|
23 |
+
"label": "",
|
24 |
+
"source": "rewrite:0",
|
25 |
+
"target": "retrieval:0"
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"id": "2bba4a81-44e7-4796-b25f-e68c3fc7e54a",
|
29 |
+
"label": "",
|
30 |
+
"source": "retrieval:0",
|
31 |
+
"target": "relevant:0"
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"id": "eb205b7a-a87e-4bcc-94c5-bddff13f8ddd",
|
35 |
+
"label": "",
|
36 |
+
"source": "relevant:0",
|
37 |
+
"target": "generate:0"
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"id": "b8611b17-a01a-485c-ad40-377329eb8d96",
|
41 |
+
"label": "",
|
42 |
+
"source": "relevant:0",
|
43 |
+
"target": "rewrite:0"
|
44 |
+
}
|
45 |
+
],
|
46 |
+
"nodes": [
|
47 |
+
{
|
48 |
+
"id": "begin",
|
49 |
+
"type": "beginNode",
|
50 |
+
"position": {
|
51 |
+
"x": 0,
|
52 |
+
"y": 0
|
53 |
+
},
|
54 |
+
"data": {
|
55 |
+
"label": "Begin",
|
56 |
+
"name": "FiftyDeerDeny",
|
57 |
+
"form": {
|
58 |
+
"prologue": "Hi there!"
|
59 |
+
}
|
60 |
+
},
|
61 |
+
"sourcePosition": "left",
|
62 |
+
"targetPosition": "right"
|
63 |
+
},
|
64 |
+
{
|
65 |
+
"id": "answer:0",
|
66 |
+
"type": "ragNode",
|
67 |
+
"position": {
|
68 |
+
"x": 0,
|
69 |
+
"y": 0
|
70 |
+
},
|
71 |
+
"data": {
|
72 |
+
"label": "Answer",
|
73 |
+
"name": "NinePointsSmoke",
|
74 |
+
"form": {}
|
75 |
+
},
|
76 |
+
"sourcePosition": "left",
|
77 |
+
"targetPosition": "right"
|
78 |
+
},
|
79 |
+
{
|
80 |
+
"id": "retrieval:0",
|
81 |
+
"type": "ragNode",
|
82 |
+
"position": {
|
83 |
+
"x": 0,
|
84 |
+
"y": 0
|
85 |
+
},
|
86 |
+
"data": {
|
87 |
+
"label": "Retrieval",
|
88 |
+
"name": "ProudLiesPull",
|
89 |
+
"form": {
|
90 |
+
"similarity_threshold": 0.2,
|
91 |
+
"keywords_similarity_weight": 0.3,
|
92 |
+
"top_n": 6,
|
93 |
+
"top_k": 1024,
|
94 |
+
"rerank_id": "BAAI/bge-reranker-v2-m3",
|
95 |
+
"kb_ids": ["869a236818b811ef91dffa163e197198"],
|
96 |
+
"empty_response": "Sorry, knowledge base has noting related information."
|
97 |
+
}
|
98 |
+
},
|
99 |
+
"sourcePosition": "left",
|
100 |
+
"targetPosition": "right"
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"id": "relevant:0",
|
104 |
+
"type": "relevantNode",
|
105 |
+
"position": {
|
106 |
+
"x": 0,
|
107 |
+
"y": 0
|
108 |
+
},
|
109 |
+
"data": {
|
110 |
+
"label": "Relevant",
|
111 |
+
"name": "StrongBooksPay",
|
112 |
+
"form": {
|
113 |
+
"llm_id": "deepseek-chat",
|
114 |
+
"temperature": 0.02,
|
115 |
+
"yes": "generate:0",
|
116 |
+
"no": "rewrite:0"
|
117 |
+
}
|
118 |
+
},
|
119 |
+
"sourcePosition": "left",
|
120 |
+
"targetPosition": "right"
|
121 |
+
},
|
122 |
+
{
|
123 |
+
"id": "generate:0",
|
124 |
+
"type": "ragNode",
|
125 |
+
"position": {
|
126 |
+
"x": 0,
|
127 |
+
"y": 0
|
128 |
+
},
|
129 |
+
"data": {
|
130 |
+
"label": "Generate",
|
131 |
+
"name": "CyanBooksTell",
|
132 |
+
"form": {
|
133 |
+
"llm_id": "deepseek-chat",
|
134 |
+
"prompt": "You are an intelligent assistant. Please answer the question based on content of knowledge base. When all knowledge base content is irrelevant to the question, your answer must include the sentence \"The answer you are looking for is not found in the knowledge base!\". Answers need to consider chat history.\n Knowledge base content is as following:\n {input}\n The above is the content of knowledge base.",
|
135 |
+
"temperature": 0.02
|
136 |
+
}
|
137 |
+
},
|
138 |
+
"sourcePosition": "left",
|
139 |
+
"targetPosition": "right"
|
140 |
+
},
|
141 |
+
{
|
142 |
+
"id": "rewrite:0",
|
143 |
+
"type": "ragNode",
|
144 |
+
"position": {
|
145 |
+
"x": 0,
|
146 |
+
"y": 0
|
147 |
+
},
|
148 |
+
"data": {
|
149 |
+
"label": "RewriteQuestion",
|
150 |
+
"name": "SourPapersMake",
|
151 |
+
"form": {
|
152 |
+
"llm_id": "deepseek-chat",
|
153 |
+
"temperature": 0.8
|
154 |
+
}
|
155 |
+
},
|
156 |
+
"sourcePosition": "left",
|
157 |
+
"targetPosition": "right"
|
158 |
+
}
|
159 |
+
]
|
160 |
+
}
|
web/src/pages/flow/utils.test.ts
CHANGED
@@ -3,6 +3,7 @@ import path from 'path';
|
|
3 |
import customer_service from '../../../../graph/test/dsl_examples/customer_service.json';
|
4 |
import headhunter_zh from '../../../../graph/test/dsl_examples/headhunter_zh.json';
|
5 |
import interpreter from '../../../../graph/test/dsl_examples/interpreter.json';
|
|
|
6 |
import { dsl } from './mock';
|
7 |
import { buildNodesAndEdgesFromDSLComponents } from './utils';
|
8 |
|
@@ -87,3 +88,19 @@ test('build nodes and edges from interpreter dsl', () => {
|
|
87 |
}
|
88 |
expect(nodes.length).toEqual(12);
|
89 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import customer_service from '../../../../graph/test/dsl_examples/customer_service.json';
|
4 |
import headhunter_zh from '../../../../graph/test/dsl_examples/headhunter_zh.json';
|
5 |
import interpreter from '../../../../graph/test/dsl_examples/interpreter.json';
|
6 |
+
import retrievalRelevantRewriteAndGenerate from '../../../../graph/test/dsl_examples/retrieval_relevant_rewrite_and_generate.json';
|
7 |
import { dsl } from './mock';
|
8 |
import { buildNodesAndEdgesFromDSLComponents } from './utils';
|
9 |
|
|
|
88 |
}
|
89 |
expect(nodes.length).toEqual(12);
|
90 |
});
|
91 |
+
|
92 |
+
test('build nodes and edges from chat bot dsl', () => {
|
93 |
+
const { edges, nodes } = buildNodesAndEdgesFromDSLComponents(
|
94 |
+
retrievalRelevantRewriteAndGenerate.components,
|
95 |
+
);
|
96 |
+
try {
|
97 |
+
fs.writeFileSync(
|
98 |
+
path.join(__dirname, 'retrieval_relevant_rewrite_and_generate.json'),
|
99 |
+
JSON.stringify({ edges, nodes }, null, 4),
|
100 |
+
);
|
101 |
+
console.log('JSON data is saved.');
|
102 |
+
} catch (error) {
|
103 |
+
console.warn(error);
|
104 |
+
}
|
105 |
+
expect(nodes.length).toEqual(12);
|
106 |
+
});
|