forked from savini98/jac-chat-buddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_solution.jac
183 lines (157 loc) · 5.3 KB
/
1_solution.jac
1
2
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import:py random;
'''
User node has user_name attribute.
'''
node user{
has user_name:string="user";
}
'''
Chat session of a user. This node contains the session_id, user_data and todo_list.
This should also include the chat history. Can have multiple chat sessions.
'''
node session{
has session_id : string = 100;
has user_data : dict = {}; # User data such as habits, heart rate etc.
has todo_list : list = []; # List of things to do by the user.
}
'''
Consists of user data such as age, pressure, married status.
'''
node data{
has user_data:dict = {
"age" : 0,
"Pressure" : (0,0),
"Married" : False
};
}
'''
List of things to do by the user.
'''
node todo{
has todo_list:list = [];
}
'''
This is the chat walker which will be used to chat with the user.
The create_session ability:
- gather the user data and todo list from connected nodes using filters.
- Creates a new session with the user data and todo list.
- Spawns the chat session with the session id.
'''
walker chat{
can create_session with user entry;
can chat_session with session entry;
}
'''
This is where we create the graph.
'''
walker create_graph{
has user_data:dict = {};
has todo_list:list = [];
can generate_graph with `root entry;
}
'''
This is the query walker which will be used to query a user input and generate a response.
The init_query_engine ability:
- Gathers the user data and todo list from the user node.
- Asks the user for the routing method.
- Creates a router node and connects it to the RAG_chat, todo_chat and user_qa_chat nodes.
- Visits the router node.
'''
walker query{
has query:str = '';
has user_session_id:str='';
has session_chat_history:list=[];
has user_data:dict={};
has todo_list:list=[];
can init_query_engine with session entry;
}
'''
This is the router node which will be used to route the user query to the appropriate chat node.
TODO:Auto-routing feature not yet implemented
'''
node router {
can route with query entry;
}
'''
This is the RAG chat node which will be used to chat with the user using Retrival Augmented Generation.
TODO:Not yet implemented.
'''
node RAG_chat {
can run_RAG with query entry {
print('routed --> RAG');
}
}
'''
This is the TODO chat node which will be used to chat with the user using the todo list and user data.
'''
node todo_chat {
can run_todo with query entry {
print('routed --> TODO');
}
}
'''
This is the user QA chat node which will be used to chat with the user using the user data.
TODO:Not yet implemented.
'''
node user_qa_chat {
can run_user_qa with query entry {
print('routed --> USER_QA');
}
}
with entry {
create_graph( user_data={ "age": 20,
"Pressure": (120, 80),
"Married": False
},
todo_list=["Do heart surgery : 04/12/2020",
"Run Marathon : 14/12/2020",
"Doctor's appointment : 20/12/2020"]
) spawn root;
}
## Implementations ==================================================================================================================
:walker:chat:can:create_session {
# Telescope into the nodes connected to the user node without walking.
data_node = [-->](`?data)[0]; # Getting the data node filtered. can use [0] as having only one such node.
todo_node = [-->](`?todo)[0]; # Getting the todo node filtered. can use [0] as having only one such node.
new_session_id = str(random.randint(1,100));
# Creating a new session node with the user data and todo list and connect it to the user.
n = here ++> session( session_id = new_session_id,
user_data = data_node.user_data,
todo_list = todo_node.todo_list
);
visit n;
}
:walker:chat:can:chat_session {
# print(here.user_data);
# print(here.todo_list);
query() spawn here;
}
:walker:create_graph:can:generate_graph {
end = here; # Assign the current root node (here) to end
end ++> (end := user()); # Create a user node and connect it to the end node. Assign the new user node to the end.
end ++> data(user_data = self.user_data); # Create a data node with the user data and connect it to the end node.
end ++> todo(todo_list = self.todo_list); # Create a todo node with the todo list and connect it to the end node.
chat() spawn [-->](`?user)[0]; # Spawn the chat walker with the user node.
}
:walker:query:can:init_query_engine {
self.user_data:dict = here.user_data;
self.todo_list:list = here.todo_list;
self.task_type:str = input('What is the routing method : '); # Get the routing method from the user.
# Create a router node and connect it to the RAG_chat, todo_chat and user_qa_chat nodes.
end = here;
end ++> (end := router());
end ++> RAG_chat();
end ++> todo_chat();
end ++> user_qa_chat();
visit [-->];
}
:node:router:can:route {
task:str = here.task_type;
if task == 'RAG' {
visit [-->](`?RAG_chat);
} elif task == 'QA'{
visit [-->](`?user_qa_chat);
} elif task == 'TODO' {
visit [-->](`?todo_chat);
}
}