@@ -24,9 +24,17 @@ class ChatSession:
24
24
>>> chat_session.send_message("What is the capital of France?")
25
25
"""
26
26
27
- def __init__ (self , model_config : KnowledgeGraphModelConfig , ontology : Ontology , graph : Graph ,
28
- cypher_system_instruction : str , qa_system_instruction : str ,
29
- cypher_gen_prompt : str , qa_prompt : str , cypher_gen_prompt_history : str ):
27
+ def __init__ (
28
+ self ,
29
+ model_config : KnowledgeGraphModelConfig ,
30
+ ontology : Ontology ,
31
+ graph : Graph ,
32
+ cypher_system_instruction : str ,
33
+ qa_system_instruction : str ,
34
+ cypher_gen_prompt : str ,
35
+ qa_prompt : str ,
36
+ cypher_gen_prompt_history : str ,
37
+ ):
30
38
"""
31
39
Initializes a new ChatSession object.
32
40
@@ -45,21 +53,22 @@ def __init__(self, model_config: KnowledgeGraphModelConfig, ontology: Ontology,
45
53
self .model_config = model_config
46
54
self .graph = graph
47
55
self .ontology = ontology
48
- cypher_system_instruction = cypher_system_instruction .format (ontology = str (ontology .to_json ()))
56
+ cypher_system_instruction = cypher_system_instruction .format (
57
+ ontology = str (ontology .to_json ())
58
+ )
49
59
50
-
51
60
self .cypher_prompt = cypher_gen_prompt
52
61
self .qa_prompt = qa_prompt
53
62
self .cypher_prompt_with_history = cypher_gen_prompt_history
54
-
63
+
55
64
self .cypher_chat_session = (
56
65
model_config .cypher_generation .with_system_instruction (
57
66
cypher_system_instruction
58
67
).start_chat ()
59
68
)
60
69
self .qa_chat_session = model_config .qa .with_system_instruction (
61
- qa_system_instruction
62
- ).start_chat ()
70
+ qa_system_instruction
71
+ ).start_chat ()
63
72
self .last_answer = None
64
73
65
74
def send_message (self , message : str ):
@@ -71,9 +80,9 @@ def send_message(self, message: str):
71
80
72
81
Returns:
73
82
dict: The response to the message in the following format:
74
- {"question": message,
75
- "response": answer,
76
- "context": context,
83
+ {"question": message,
84
+ "response": answer,
85
+ "context": context,
77
86
"cypher": cypher}
78
87
"""
79
88
cypher_step = GraphQueryGenerationStep (
@@ -82,7 +91,7 @@ def send_message(self, message: str):
82
91
ontology = self .ontology ,
83
92
last_answer = self .last_answer ,
84
93
cypher_prompt = self .cypher_prompt ,
85
- cypher_prompt_with_history = self .cypher_prompt_with_history
94
+ cypher_prompt_with_history = self .cypher_prompt_with_history ,
86
95
)
87
96
88
97
(context , cypher ) = cypher_step .run (message )
@@ -92,8 +101,8 @@ def send_message(self, message: str):
92
101
"question" : message ,
93
102
"response" : "I am sorry, I could not find the answer to your question" ,
94
103
"context" : None ,
95
- "cypher" : None
96
- }
104
+ "cypher" : None ,
105
+ }
97
106
98
107
qa_step = QAStep (
99
108
chat_session = self .qa_chat_session ,
@@ -102,10 +111,10 @@ def send_message(self, message: str):
102
111
103
112
answer = qa_step .run (message , cypher , context )
104
113
self .last_answer = answer
105
-
114
+
106
115
return {
107
- "question" : message ,
108
- "response" : answer ,
109
- "context" : context ,
110
- "cypher" : cypher
111
- }
116
+ "question" : message ,
117
+ "response" : answer ,
118
+ "context" : context ,
119
+ "cypher" : cypher ,
120
+ }
0 commit comments