Spaces:
Build error
Build error
minor formatting
Browse files- planning_ai/main.py +51 -15
- planning_ai/nodes/map_node.py +15 -3
planning_ai/main.py
CHANGED
@@ -59,11 +59,11 @@ def build_quarto_doc(doc_title, out):
|
|
59 |
)
|
60 |
key_points = final["final_summary"].split("## Key points raised in support")[1]
|
61 |
|
62 |
-
aims = [
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
value_counts = Counter(aims)
|
68 |
total_values = sum(value_counts.values())
|
69 |
percentages = {
|
@@ -82,8 +82,8 @@ def build_quarto_doc(doc_title, out):
|
|
82 |
pl.DataFrame(
|
83 |
[
|
84 |
place.dict()
|
85 |
-
for summary in final["
|
86 |
-
for place in summary
|
87 |
]
|
88 |
)
|
89 |
.group_by("place")
|
@@ -108,7 +108,7 @@ def build_quarto_doc(doc_title, out):
|
|
108 |
# [f"| {item} | {d['percentage']:.2%} | {d['count']} |" for item, d in top_5]
|
109 |
# )
|
110 |
|
111 |
-
stances = [summary
|
112 |
value_counts = Counter(stances)
|
113 |
total_values = sum(value_counts.values())
|
114 |
percentages = {
|
@@ -127,11 +127,11 @@ def build_quarto_doc(doc_title, out):
|
|
127 |
|
128 |
short_summaries = "\n\n".join(
|
129 |
[
|
130 |
-
f"####
|
131 |
-
f"{summary.
|
132 |
-
f"**Stance**: {summary
|
133 |
-
f"**Constructiveness**: {summary
|
134 |
-
for summary in final["
|
135 |
]
|
136 |
)
|
137 |
|
@@ -141,6 +141,11 @@ def build_quarto_doc(doc_title, out):
|
|
141 |
"format:\n"
|
142 |
" PrettyPDF-pdf:\n"
|
143 |
" papersize: A4\n"
|
|
|
|
|
|
|
|
|
|
|
144 |
"execute:\n"
|
145 |
" freeze: auto\n"
|
146 |
" echo: false\n"
|
@@ -186,10 +191,10 @@ def main():
|
|
186 |
step = None
|
187 |
for step in app.stream(
|
188 |
{
|
189 |
-
"
|
190 |
"filenames": [Path(doc.metadata["source"]) for doc in split_docs],
|
191 |
},
|
192 |
-
{"recursion_limit": 10},
|
193 |
):
|
194 |
print(list(step.keys()))
|
195 |
|
@@ -203,3 +208,34 @@ if __name__ == "__main__":
|
|
203 |
doc_title = "Cambridge Response Summary"
|
204 |
out = main()
|
205 |
build_quarto_doc(doc_title, out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
)
|
60 |
key_points = final["final_summary"].split("## Key points raised in support")[1]
|
61 |
|
62 |
+
aims = []
|
63 |
+
for summary in final["summaries_fixed"]:
|
64 |
+
aim = summary["summary"].aims
|
65 |
+
aims.extend(aim)
|
66 |
+
|
67 |
value_counts = Counter(aims)
|
68 |
total_values = sum(value_counts.values())
|
69 |
percentages = {
|
|
|
82 |
pl.DataFrame(
|
83 |
[
|
84 |
place.dict()
|
85 |
+
for summary in final["summaries_fixed"]
|
86 |
+
for place in summary["summary"].places
|
87 |
]
|
88 |
)
|
89 |
.group_by("place")
|
|
|
108 |
# [f"| {item} | {d['percentage']:.2%} | {d['count']} |" for item, d in top_5]
|
109 |
# )
|
110 |
|
111 |
+
stances = [summary["summary"].stance for summary in final["summaries_fixed"]]
|
112 |
value_counts = Counter(stances)
|
113 |
total_values = sum(value_counts.values())
|
114 |
percentages = {
|
|
|
127 |
|
128 |
short_summaries = "\n\n".join(
|
129 |
[
|
130 |
+
f"#### **TODO**\n"
|
131 |
+
f"{summary['summary'].summary}\n\n"
|
132 |
+
f"**Stance**: {summary['summary'].stance}\n\n"
|
133 |
+
f"**Constructiveness**: {summary['summary'].rating}\n\n"
|
134 |
+
for summary in final["summaries_fixed"]
|
135 |
]
|
136 |
)
|
137 |
|
|
|
141 |
"format:\n"
|
142 |
" PrettyPDF-pdf:\n"
|
143 |
" papersize: A4\n"
|
144 |
+
" lumo-html:\n"
|
145 |
+
" logo: logo.png\n"
|
146 |
+
" github-repo: https://github.com/cjber/planning-ai\n"
|
147 |
+
" self-contained: true\n"
|
148 |
+
" is-particlejs-enabled: true\n"
|
149 |
"execute:\n"
|
150 |
" freeze: auto\n"
|
151 |
" echo: false\n"
|
|
|
191 |
step = None
|
192 |
for step in app.stream(
|
193 |
{
|
194 |
+
"documents": [doc.page_content for doc in split_docs],
|
195 |
"filenames": [Path(doc.metadata["source"]) for doc in split_docs],
|
196 |
},
|
197 |
+
# {"recursion_limit": 10},
|
198 |
):
|
199 |
print(list(step.keys()))
|
200 |
|
|
|
208 |
doc_title = "Cambridge Response Summary"
|
209 |
out = main()
|
210 |
build_quarto_doc(doc_title, out)
|
211 |
+
|
212 |
+
d = [
|
213 |
+
i
|
214 |
+
for i in out["generate_final_summary"]["summaries_fixed"]
|
215 |
+
if i["iteration"] == 4
|
216 |
+
][0]
|
217 |
+
d["document"]
|
218 |
+
|
219 |
+
h = [
|
220 |
+
i["summary"].summary
|
221 |
+
for i in out["generate_final_summary"]["hallucinations"]
|
222 |
+
if i["document"] == d["document"]
|
223 |
+
]
|
224 |
+
|
225 |
+
e = [
|
226 |
+
i["hallucination"].explanation
|
227 |
+
for i in out["generate_final_summary"]["hallucinations"]
|
228 |
+
if i["document"] == d["document"]
|
229 |
+
]
|
230 |
+
|
231 |
+
test = {
|
232 |
+
"document": d["document"],
|
233 |
+
"final_summary": d["summary"].summary,
|
234 |
+
"attempts": h,
|
235 |
+
"reasoning": e,
|
236 |
+
}
|
237 |
+
|
238 |
+
print(f"Document:\n\n{test['document']}\n\n")
|
239 |
+
print(f"Final:\n\n{test['final_summary']}\n\n")
|
240 |
+
print("Attempts: \n\n*", "\n\n* ".join(test["attempts"]), "\n\n")
|
241 |
+
print("Reasoning: \n\n*", "\n\n* ".join(test["reasoning"]), "\n\n")
|
planning_ai/nodes/map_node.py
CHANGED
@@ -11,13 +11,25 @@ from planning_ai.states import DocumentState, OverallState
|
|
11 |
|
12 |
def generate_summary(state: DocumentState):
|
13 |
response = map_chain.invoke({"context": state["document"]})
|
14 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
def map_summaries(state: OverallState):
|
18 |
return [
|
19 |
-
Send(
|
20 |
-
|
|
|
|
|
|
|
21 |
]
|
22 |
|
23 |
|
|
|
11 |
|
12 |
def generate_summary(state: DocumentState):
|
13 |
response = map_chain.invoke({"context": state["document"]})
|
14 |
+
return {
|
15 |
+
"summaries": [
|
16 |
+
{
|
17 |
+
"summary": response,
|
18 |
+
"document": state["document"],
|
19 |
+
"filename": state["filename"],
|
20 |
+
"iteration": 1,
|
21 |
+
}
|
22 |
+
]
|
23 |
+
}
|
24 |
|
25 |
|
26 |
def map_summaries(state: OverallState):
|
27 |
return [
|
28 |
+
Send(
|
29 |
+
"generate_summary",
|
30 |
+
{"document": document, "filename": filename},
|
31 |
+
)
|
32 |
+
for document, filename in zip(state["documents"], state["filenames"])
|
33 |
]
|
34 |
|
35 |
|