Spaces:
Paused
Paused
angry-meow
commited on
Commit
•
a2d4d13
1
Parent(s):
a00c36c
upped recursion limit, added ts prints to log
Browse files
graph.py
CHANGED
@@ -45,56 +45,44 @@ research_supervisor_chain = (
|
|
45 |
# Reserach Node Defs
|
46 |
#
|
47 |
def query_qdrant(state: ResearchState) -> ResearchState:
|
48 |
-
#print("qdrant node")
|
49 |
topic = state["topic"]
|
50 |
result = qdrant_research_chain.invoke({"topic": topic})
|
51 |
-
|
52 |
state["research_data"]["qdrant_results"] = result["response"]
|
53 |
state['workflow'].append("query_qdrant")
|
54 |
-
|
55 |
|
56 |
return state
|
57 |
|
58 |
def web_search(state: ResearchState) -> ResearchState:
|
59 |
-
#print("tavily node")
|
60 |
-
# Extract the last message as the topic
|
61 |
topic = state["topic"]
|
62 |
-
#print(topic)
|
63 |
-
# Get the Qdrant results from the state
|
64 |
qdrant_results = state["research_data"].get("qdrant_results", "No previous results available.")
|
65 |
-
|
66 |
-
result
|
67 |
-
"topic": topic,
|
68 |
-
"qdrant_results": qdrant_results
|
69 |
-
})
|
70 |
-
#print(result)
|
71 |
-
# Update the state with the web search results
|
72 |
state["research_data"]["web_search_results"] = result
|
73 |
state['workflow'].append("web_search")
|
74 |
-
|
75 |
return state
|
76 |
|
77 |
def research_supervisor(state):
|
78 |
-
#print("research supervisor node")
|
79 |
message_from_manager = state["message_from_manager"]
|
80 |
collected_data = state["research_data"]
|
81 |
topic = state['topic']
|
82 |
supervisor_result = research_supervisor_chain.invoke({"message_from_manager": message_from_manager, "collected_data": collected_data, "topic": topic})
|
83 |
lines = supervisor_result.split('\n')
|
84 |
-
|
85 |
for line in lines:
|
86 |
if line.startswith('Next Action: '):
|
87 |
state['next'] = line[len('Next Action: '):].strip() # Extract the next action content
|
88 |
elif line.startswith('Message to project manager: '):
|
89 |
state['message_to_manager'] = line[len('Message to project manager: '):].strip()
|
90 |
state['workflow'].append("research_supervisor")
|
91 |
-
|
92 |
return state
|
93 |
|
94 |
def research_end(state):
|
95 |
-
#print("research_end node")
|
96 |
state['workflow'].append("research_end")
|
97 |
-
|
98 |
return state
|
99 |
|
100 |
#######################################
|
@@ -135,24 +123,26 @@ post_review_chain = (
|
|
135 |
# Writing Node Defs
|
136 |
#
|
137 |
def post_creation(state):
|
138 |
-
print("post_creation node")
|
139 |
topic = state['topic']
|
140 |
drafts = state['draft_posts']
|
141 |
collected_data = state["research_data"]
|
142 |
review_comments = state['review_comments']
|
143 |
results = post_creation_chain.invoke({"topic": topic, "collected_data": collected_data, "drafts": drafts, "review_comments": review_comments})
|
|
|
144 |
state['draft_posts'].append(results)
|
145 |
state['workflow'].append("post_creation")
|
|
|
146 |
return state
|
147 |
|
148 |
def post_editor(state):
|
149 |
-
print("post_editor node")
|
150 |
current_draft = state['draft_posts'][-1]
|
151 |
styleguide = prompts.style_guide_text
|
152 |
review_comments = state['review_comments']
|
153 |
results = post_editor_chain.invoke({"current_draft": current_draft, "styleguide": styleguide, "review_comments": review_comments})
|
|
|
154 |
state['draft_posts'].append(results)
|
155 |
state['workflow'].append("post_editor")
|
|
|
156 |
return state
|
157 |
|
158 |
def post_review(state):
|
@@ -160,11 +150,13 @@ def post_review(state):
|
|
160 |
current_draft = state['draft_posts'][-1]
|
161 |
styleguide = prompts.style_guide_text
|
162 |
results = post_review_chain.invoke({"current_draft": current_draft, "styleguide": styleguide})
|
|
|
163 |
data = json.loads(results.strip())
|
164 |
state['review_comments'] = data["Comments on current draft"]
|
165 |
if data["Draft Acceptable"] == 'Yes':
|
166 |
state['final_post'] = state['draft_posts'][-1]
|
167 |
state['workflow'].append("post_review")
|
|
|
168 |
return state
|
169 |
|
170 |
def writing_end(state):
|
@@ -181,14 +173,15 @@ def writing_supervisor(state):
|
|
181 |
final_draft = state['final_post']
|
182 |
review_comments = state['review_comments']
|
183 |
supervisor_result = writing_supervisor_chain.invoke({"review_comments": review_comments, "message_from_manager": message_from_manager, "topic": topic, "drafts": drafts, "final_draft": final_draft})
|
184 |
-
lines = supervisor_result.split('\n')
|
185 |
print(supervisor_result)
|
|
|
186 |
for line in lines:
|
187 |
if line.startswith('Next Action: '):
|
188 |
state['next'] = line[len('Next Action: '):].strip() # Extract the next action content
|
189 |
elif line.startswith('Message to project manager: '):
|
190 |
state['message_to_manager'] = line[len('Message to project manager: '):].strip()
|
191 |
state['workflow'].append("writing_supervisor")
|
|
|
192 |
return state
|
193 |
|
194 |
#######################################
|
@@ -219,14 +212,12 @@ overall_supervisor_chain = (
|
|
219 |
# Complete Graph Node defs
|
220 |
#
|
221 |
def overall_supervisor(state):
|
222 |
-
print("overall supervisor node")
|
223 |
-
# Implement overall supervision logic
|
224 |
init_user_query = state["user_input"]
|
225 |
message_to_manager = state['message_to_manager']
|
226 |
last_active_team = state['last_active_team']
|
227 |
supervisor_result = overall_supervisor_chain.invoke({"query": init_user_query, "message_to_manager": message_to_manager, "last_active_team": last_active_team})
|
228 |
-
lines = supervisor_result.split('\n')
|
229 |
print(supervisor_result)
|
|
|
230 |
for line in lines:
|
231 |
if line.startswith('Next Action: '):
|
232 |
state['next_team'] = line[len('Next Action: '):].strip() # Extract the next action content
|
@@ -235,7 +226,6 @@ def overall_supervisor(state):
|
|
235 |
elif line.startswith('Message to supervisor: '):
|
236 |
state['message_from_manager'] = line[len('Message to supervisor: '):].strip() # Extract the next action content
|
237 |
state['workflow'].append("overall_supervisor")
|
238 |
-
print(state['next_team'])
|
239 |
print(state['workflow'])
|
240 |
return state
|
241 |
|
@@ -333,7 +323,7 @@ def getSocialMediaPost(userInput: str) -> str:
|
|
333 |
)
|
334 |
results = app.invoke(initial_state)
|
335 |
try:
|
336 |
-
results = app.invoke(initial_state, {"recursion_limit":
|
337 |
except GraphRecursionError:
|
338 |
return "Recursion Error"
|
339 |
finalPost = results['final_post']
|
|
|
45 |
# Reserach Node Defs
|
46 |
#
|
47 |
def query_qdrant(state: ResearchState) -> ResearchState:
|
|
|
48 |
topic = state["topic"]
|
49 |
result = qdrant_research_chain.invoke({"topic": topic})
|
50 |
+
print(result)
|
51 |
state["research_data"]["qdrant_results"] = result["response"]
|
52 |
state['workflow'].append("query_qdrant")
|
53 |
+
print(state['workflow'])
|
54 |
|
55 |
return state
|
56 |
|
57 |
def web_search(state: ResearchState) -> ResearchState:
|
|
|
|
|
58 |
topic = state["topic"]
|
|
|
|
|
59 |
qdrant_results = state["research_data"].get("qdrant_results", "No previous results available.")
|
60 |
+
result = tavily_chain.invoke({"topic": topic,"qdrant_results": qdrant_results })
|
61 |
+
print(result)
|
|
|
|
|
|
|
|
|
|
|
62 |
state["research_data"]["web_search_results"] = result
|
63 |
state['workflow'].append("web_search")
|
64 |
+
print(state['workflow'])
|
65 |
return state
|
66 |
|
67 |
def research_supervisor(state):
|
|
|
68 |
message_from_manager = state["message_from_manager"]
|
69 |
collected_data = state["research_data"]
|
70 |
topic = state['topic']
|
71 |
supervisor_result = research_supervisor_chain.invoke({"message_from_manager": message_from_manager, "collected_data": collected_data, "topic": topic})
|
72 |
lines = supervisor_result.split('\n')
|
73 |
+
print(supervisor_result)
|
74 |
for line in lines:
|
75 |
if line.startswith('Next Action: '):
|
76 |
state['next'] = line[len('Next Action: '):].strip() # Extract the next action content
|
77 |
elif line.startswith('Message to project manager: '):
|
78 |
state['message_to_manager'] = line[len('Message to project manager: '):].strip()
|
79 |
state['workflow'].append("research_supervisor")
|
80 |
+
print(state['workflow'])
|
81 |
return state
|
82 |
|
83 |
def research_end(state):
|
|
|
84 |
state['workflow'].append("research_end")
|
85 |
+
print(state['workflow'])
|
86 |
return state
|
87 |
|
88 |
#######################################
|
|
|
123 |
# Writing Node Defs
|
124 |
#
|
125 |
def post_creation(state):
|
|
|
126 |
topic = state['topic']
|
127 |
drafts = state['draft_posts']
|
128 |
collected_data = state["research_data"]
|
129 |
review_comments = state['review_comments']
|
130 |
results = post_creation_chain.invoke({"topic": topic, "collected_data": collected_data, "drafts": drafts, "review_comments": review_comments})
|
131 |
+
print(results)
|
132 |
state['draft_posts'].append(results)
|
133 |
state['workflow'].append("post_creation")
|
134 |
+
print(state['workflow'])
|
135 |
return state
|
136 |
|
137 |
def post_editor(state):
|
|
|
138 |
current_draft = state['draft_posts'][-1]
|
139 |
styleguide = prompts.style_guide_text
|
140 |
review_comments = state['review_comments']
|
141 |
results = post_editor_chain.invoke({"current_draft": current_draft, "styleguide": styleguide, "review_comments": review_comments})
|
142 |
+
print(results)
|
143 |
state['draft_posts'].append(results)
|
144 |
state['workflow'].append("post_editor")
|
145 |
+
print(state['workflow'])
|
146 |
return state
|
147 |
|
148 |
def post_review(state):
|
|
|
150 |
current_draft = state['draft_posts'][-1]
|
151 |
styleguide = prompts.style_guide_text
|
152 |
results = post_review_chain.invoke({"current_draft": current_draft, "styleguide": styleguide})
|
153 |
+
print(results)
|
154 |
data = json.loads(results.strip())
|
155 |
state['review_comments'] = data["Comments on current draft"]
|
156 |
if data["Draft Acceptable"] == 'Yes':
|
157 |
state['final_post'] = state['draft_posts'][-1]
|
158 |
state['workflow'].append("post_review")
|
159 |
+
print(state['workflow'])
|
160 |
return state
|
161 |
|
162 |
def writing_end(state):
|
|
|
173 |
final_draft = state['final_post']
|
174 |
review_comments = state['review_comments']
|
175 |
supervisor_result = writing_supervisor_chain.invoke({"review_comments": review_comments, "message_from_manager": message_from_manager, "topic": topic, "drafts": drafts, "final_draft": final_draft})
|
|
|
176 |
print(supervisor_result)
|
177 |
+
lines = supervisor_result.split('\n')
|
178 |
for line in lines:
|
179 |
if line.startswith('Next Action: '):
|
180 |
state['next'] = line[len('Next Action: '):].strip() # Extract the next action content
|
181 |
elif line.startswith('Message to project manager: '):
|
182 |
state['message_to_manager'] = line[len('Message to project manager: '):].strip()
|
183 |
state['workflow'].append("writing_supervisor")
|
184 |
+
print(state['workflow'])
|
185 |
return state
|
186 |
|
187 |
#######################################
|
|
|
212 |
# Complete Graph Node defs
|
213 |
#
|
214 |
def overall_supervisor(state):
|
|
|
|
|
215 |
init_user_query = state["user_input"]
|
216 |
message_to_manager = state['message_to_manager']
|
217 |
last_active_team = state['last_active_team']
|
218 |
supervisor_result = overall_supervisor_chain.invoke({"query": init_user_query, "message_to_manager": message_to_manager, "last_active_team": last_active_team})
|
|
|
219 |
print(supervisor_result)
|
220 |
+
lines = supervisor_result.split('\n')
|
221 |
for line in lines:
|
222 |
if line.startswith('Next Action: '):
|
223 |
state['next_team'] = line[len('Next Action: '):].strip() # Extract the next action content
|
|
|
226 |
elif line.startswith('Message to supervisor: '):
|
227 |
state['message_from_manager'] = line[len('Message to supervisor: '):].strip() # Extract the next action content
|
228 |
state['workflow'].append("overall_supervisor")
|
|
|
229 |
print(state['workflow'])
|
230 |
return state
|
231 |
|
|
|
323 |
)
|
324 |
results = app.invoke(initial_state)
|
325 |
try:
|
326 |
+
results = app.invoke(initial_state, {"recursion_limit": 40})
|
327 |
except GraphRecursionError:
|
328 |
return "Recursion Error"
|
329 |
finalPost = results['final_post']
|