Spaces:
Build error
Build error
feat: add final reduce chain
Browse files
planning_ai/nodes/reduce_node.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
import json
|
2 |
-
import logging
|
3 |
from pathlib import Path
|
4 |
|
5 |
import polars as pl
|
6 |
|
7 |
from planning_ai.chains.policy_chain import policy_chain
|
8 |
-
from planning_ai.chains.reduce_chain import reduce_chain
|
9 |
from planning_ai.logging import logger
|
10 |
from planning_ai.states import OverallState
|
11 |
from planning_ai.themes import THEMES_AND_POLICIES
|
@@ -77,7 +76,7 @@ def batch_generate_executive_summaries(summaries):
|
|
77 |
list: A list of final responses.
|
78 |
"""
|
79 |
summaries_text = [
|
80 |
-
f"Document ID: {[s['doc_id']]}
|
81 |
]
|
82 |
final_responses = []
|
83 |
batch_size = 50
|
@@ -137,5 +136,5 @@ def final_output(final_docs):
|
|
137 |
policies = generate_policy_output(policy_groups)
|
138 |
|
139 |
batch_executive = batch_generate_executive_summaries(docs)
|
140 |
-
executive =
|
141 |
return {"executive": executive, "documents": docs, "policies": policies}
|
|
|
1 |
import json
|
|
|
2 |
from pathlib import Path
|
3 |
|
4 |
import polars as pl
|
5 |
|
6 |
from planning_ai.chains.policy_chain import policy_chain
|
7 |
+
from planning_ai.chains.reduce_chain import reduce_chain, reduce_chain_final
|
8 |
from planning_ai.logging import logger
|
9 |
from planning_ai.states import OverallState
|
10 |
from planning_ai.themes import THEMES_AND_POLICIES
|
|
|
76 |
list: A list of final responses.
|
77 |
"""
|
78 |
summaries_text = [
|
79 |
+
f"Document ID: {[s['doc_id']]}\n\n{s['summary'].summary}" for s in summaries
|
80 |
]
|
81 |
final_responses = []
|
82 |
batch_size = 50
|
|
|
136 |
policies = generate_policy_output(policy_groups)
|
137 |
|
138 |
batch_executive = batch_generate_executive_summaries(docs)
|
139 |
+
executive = reduce_chain_final.invoke({"context": "\n\n".join(batch_executive)})
|
140 |
return {"executive": executive, "documents": docs, "policies": policies}
|