Skip to content

Commit 53a50d9

Browse files
committed
update text2graph and alarm2graph
1 parent 10c9baf commit 53a50d9

File tree

22 files changed

+1398
-269
lines changed

22 files changed

+1398
-269
lines changed

muagent/base_configs/prompts/simple_prompts.py

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,103 @@
203203
{conversation}
204204
205205
## 输出
206-
"""
206+
"""
207+
208+
209+
210+
text2EKG_prompt_en = '''你是一个结构化信息抽取的专家,你需要根据输入的文档,抽取其中的关键节点及节点间的连接顺序。请用json结构返回。
211+
212+
json结构定义如下:
213+
{
214+
"nodes": {
215+
"节点序号": {
216+
"type": "节点类型",
217+
"content": "节点内容"
218+
}
219+
},
220+
"edges": [
221+
{
222+
"start": "起始节点序号",
223+
"end": "终止节点序号"
224+
}
225+
]
226+
}
227+
其中 nodes 用来存放抽取的节点,每个 node 的 key 通过从0开始对递增序列表示,value 是一个字典,包含 type 和 content 两个属性, type 对应下面定义的三种节点类型,content 为抽取的节点内容。
228+
edges 用来存放节点间的连接顺序,它是一个列表,每个元素是一个字典,包含 start 和 end 两个属性, start 为起始 node 的 节点序号, end 为结束 node 的 节点序号。
229+
230+
节点类型定义如下:
231+
Schedule:
232+
表示整篇输入文档所做的事情,是对整篇输入文档的总结;
233+
第一个节点永远是Schedule节点。
234+
Task:
235+
表示需要执行的任务。
236+
Phenomenon:
237+
表示依据Task节点的执行结果,得到的事实结论。
238+
Phenomenon节点只能连接在Task节点之后。
239+
Analysis:
240+
表示依据Phenomenon节点的事实进行推断的过程;
241+
Analysis节点只能连接在Phenomenon节点之后。
242+
243+
以下是一个例子:
244+
input: 路径:排查网络问题
245+
1. 通过观察sofagw网关监控发现,BOLT失败数突增
246+
2. 且失败曲线与退保成功率曲线相关性较高,判定是网络问题。
247+
248+
output: {
249+
"nodes": {
250+
"0": {
251+
"type": "Schedule",
252+
"content": "排查网络问题"
253+
},
254+
"1": {
255+
"type": "Task",
256+
"content": "查询sofagw网关监控BOLT失败数"
257+
},
258+
"2": {
259+
"type": "Task",
260+
"content": "查询sofagw网关监控退保成功率"
261+
},
262+
"3": {
263+
"type": "Task",
264+
"content": "判断两条时序相关性"
265+
},
266+
"4": {
267+
"type": "Phenomenon",
268+
"content": "相关性较高"
269+
},
270+
"5": {
271+
"type": "Analysis",
272+
"content": "网络问题"
273+
}
274+
},
275+
"edges": [
276+
{
277+
"start": "0",
278+
"end": "1"
279+
},
280+
{
281+
"start": "1",
282+
"end": "2"
283+
},
284+
{
285+
"start": "2",
286+
"end": "3"
287+
},
288+
{
289+
"start": "3",
290+
"end": "4"
291+
},
292+
{
293+
"start": "4",
294+
"end": "5"
295+
}
296+
]
297+
}
298+
299+
请根据上述说明和例子来对以下的输入文档抽取结构化信息:
300+
301+
input: {text}
302+
303+
output:'''
304+
305+
text2EKG_prompt_zh = text2EKG_prompt_en

muagent/connector/configs/generate_prompt.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def replacePrompt(prompt: str, keys: list[str] = []):
55
prompt = prompt.replace("{", "{{").replace("}", "}}")
66
for key in keys:
7-
prompt = prompt.replace(f"{{{{key}}}}", f"{{key}}")
7+
prompt = prompt.replace(f"{{{{{key}}}}}", f"{{{key}}}")
88
return prompt
99

1010
def cleanPrompt(prompt):
@@ -54,4 +54,13 @@ def createMKGPrompt(conversation, schemas, language="en", **kwargs) -> str:
5454
# prompt = memory_extract_prompt_zh.format(**{"conversation": conversation, "schemas": schemas})
5555
# else:
5656
# prompt = memory_extract_prompt_en.format(**{"conversation": conversation, "schemas": schemas})
57+
return cleanPrompt(prompt)
58+
59+
60+
def createText2EKGPrompt(text, language="en", **kwargs) -> str:
61+
prompt = text2EKG_prompt_zh if language == "zh" else text2EKG_prompt_en
62+
prompt = replacePrompt(prompt, keys=["text"])
63+
from loguru import logger
64+
logger.debug(f"{prompt}")
65+
prompt = prompt.format(**{"text": text,})
5766
return cleanPrompt(prompt)

muagent/connector/memory/hierarchical_memory_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from muagent.connector.configs.generate_prompt import *
1111
from muagent.connector.schema import Memory, Message
1212
from muagent.schemas.db import DBConfig, GBConfig, VBConfig, TBConfig
13-
from muagent.schemas.memory import *
13+
from muagent.schemas.common import *
1414
from muagent.db_handler import *
1515
from muagent.connector.memory_manager import BaseMemoryManager
1616
from muagent.llm_models import *

muagent/db_handler/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
@desc:
77
'''
88

9-
from .graph_db_handler import NebulaHandler, NetworkxHandler, AliYunSLSHandler, GeaBaseHandler
9+
from .graph_db_handler import NebulaHandler, NetworkxHandler, AliYunSLSHandler, GeaBaseHandler, GBHandler
1010
from .vector_db_handler import LocalFaissHandler, TbaseHandler, ChromaHandler
1111

1212

1313
__all__ = [
14-
"NebulaHandler", "NetworkxHandler", "GeaBaseHandler",
14+
"GBHandler", "NebulaHandler", "NetworkxHandler", "GeaBaseHandler",
1515
"ChromaHandler", "TbaseHandler", "LocalFaissHandler",
1616
"AliYunSLSHandler"
1717
]

muagent/db_handler/graph_db_handler/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
@time: 2023/11/20 下午3:07
66
@desc:
77
'''
8+
from .base_gb_handler import GBHandler
89
from .nebula_handler import NebulaHandler
910
from .networkx_handler import NetworkxHandler
1011
from .aliyun_sls_hanlder import AliYunSLSHandler
1112
from .geabase_handler import GeaBaseHandler
1213

1314

1415
__all__ = [
15-
"NebulaHandler", "NetworkxHandler", "GeaBaseHandler",
16+
"GBHandler", "NebulaHandler", "NetworkxHandler", "GeaBaseHandler",
1617
"AliYunSLSHandler"
1718
]

muagent/db_handler/graph_db_handler/aliyun_sls_hanlder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import time
44

55
from aliyun.log import *
6-
from muagent.schemas.memory import *
6+
from muagent.schemas.common import *
77
from muagent.schemas.db import SLSConfig
88

99

@@ -141,6 +141,6 @@ def relation_process(self, relations: List[GRelation], crud_type) -> List[List[T
141141
relation_list = [
142142
[('start_id', relation.start_id), ('end_id', relation.start_id)] +\
143143
[(k, v) if k!="operation_type" else (k, crud_type) for k,v in relation.attributes.items()]
144-
for node in nodes
144+
for relation in relations
145145
]
146146
return relation_list

muagent/db_handler/graph_db_handler/base_gb_handler.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from loguru import logger
44
import json
55

6-
from muagent.schemas.memory import *
6+
from muagent.schemas.common import *
77

88

99

@@ -58,20 +58,20 @@ def search_nodes_by_attr(self, attributes: dict) -> List[GNode]:
5858
def search_edges_by_attr(self, attributes: dict, edge_type: str = None) -> List[GEdge]:
5959
pass
6060

61-
def get_current_node(self, attributes: dict, node_type: str = None, return_keys: list = []) -> Dict:
61+
def get_current_node(self, attributes: dict, node_type: str = None, return_keys: list = []) -> GNode:
6262
pass
6363

64-
def get_current_nodes(self, attributes: dict, node_type: str = None, return_keys: list = []) -> Dict:
64+
def get_current_nodes(self, attributes: dict, node_type: str = None, return_keys: list = []) -> List[GNode]:
6565
pass
6666

67-
def get_current_edge(self, src_id, dst_id, edge_type:str = None, return_keys: list = []) -> Dict:
67+
def get_current_edge(self, src_id, dst_id, edge_type:str = None, return_keys: list = []) -> GEdge:
6868
pass
6969

70-
def get_neighbor_nodes(self, attributes: dict, node_type: str = None, return_keys: list = []) -> List[Dict]:
70+
def get_neighbor_nodes(self, attributes: dict, node_type: str = None, return_keys: list = []) -> List[GNode]:
7171
pass
7272

73-
def get_neighbor_edges(self, attributes: dict, node_type: str = None, return_keys: list = []) -> List[Dict]:
73+
def get_neighbor_edges(self, attributes: dict, node_type: str = None, return_keys: list = []) -> List[GEdge]:
7474
pass
7575

76-
def get_hop_infos(self, attributes: dict, node_type: str = None, hop: int = 2, block_attributes: dict = []):
76+
def get_hop_infos(self, attributes: dict, node_type: str = None, hop: int = 2, block_attributes: dict = {}, select_attributes: dict = {}) -> Graph:
7777
pass

0 commit comments

Comments
 (0)