Nyha15 commited on
Commit
5d862db
·
1 Parent(s): f3ba91e

Refactored

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -189,7 +189,7 @@ class KnowledgeBase:
189
 
190
  # Split texts into chunks
191
  # Split texts into chunks
192
- splits = self.splitter.split_text("".join(texts))
193
  if not splits:
194
  log_workflow(f"No splits generated for domain '{self.domain}' and country '{country}'")
195
  with self.lock:
@@ -289,28 +289,29 @@ class CoordinatorAgent:
289
  advice = {d: self.specialists[d].run(query, country) for d in self.specialists}
290
  # 2. plan (omitted)
291
  # 3. synthesis
292
- output = ["## Your Personalized Financial Advice\n"]
293
-
294
- # If there’s truly unique content per domain:
295
- for domain, txt in specialist_advice.items():
296
- output.append(f"### {domain.capitalize()}\n{txt.strip()}\n")
297
-
298
- # If you want to dedupe truly identical advice, you could:
299
- # seen = set()
300
- # for domain, txt in specialist_advice.items():
301
- # if txt not in seen:
302
- # seen.add(txt)
303
- # output.append(f"### {domain.capitalize()}\n{txt.strip()}\n")
 
 
 
 
 
 
 
304
 
305
- # Append your plans in a code‐block
306
- output.append("## Multi-Path Plans\n```json\n")
307
- output.append(json.dumps(plans, indent=2))
308
- output.append("\n```")
309
 
310
- synthesis = "\n".join(output)
311
- log_workflow("Synthesis complete")
312
- # 4. return
313
- return synthesis
314
 
315
  # =======================================
316
  # Main Portal Interface
 
189
 
190
  # Split texts into chunks
191
  # Split texts into chunks
192
+ splits = self.splitter.split_text("\n\n".join(texts))
193
  if not splits:
194
  log_workflow(f"No splits generated for domain '{self.domain}' and country '{country}'")
195
  with self.lock:
 
289
  advice = {d: self.specialists[d].run(query, country) for d in self.specialists}
290
  # 2. plan (omitted)
291
  # 3. synthesis
292
+ # 4. Synthesize and pretty–print
293
+ lines = ["# Your Personalized Financial Advice\n"]
294
+
295
+ # Add each specialist’s section
296
+ for domain, text in specialist_advice.items():
297
+ lines.append(f"## {domain.capitalize()}\n")
298
+ # Indent each paragraph for readability
299
+ for para in text.strip().split("\n\n"):
300
+ lines.append(" " + para.strip().replace("\n", "\n "))
301
+ lines.append("") # blank line
302
+
303
+ # Append Multi-Path Plans as a JSON code block
304
+ lines.append("## Multi-Path Financial Plans\n")
305
+ lines.append("```json")
306
+ lines.append(json.dumps(plans, indent=2))
307
+ lines.append("```")
308
+
309
+ formatted = "\n".join(lines)
310
+ log_workflow("Synthesis complete")
311
 
312
+ # 5. Return formatted advice + workflow log
313
+ return formatted + "\n\n---\n" + get_workflow_log()
 
 
314
 
 
 
 
 
315
 
316
  # =======================================
317
  # Main Portal Interface