Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,12 +9,12 @@ import os
|
|
9 |
from dotenv import load_dotenv
|
10 |
import threading
|
11 |
|
12 |
-
#load_dotenv()
|
13 |
|
14 |
class OutputParser:
|
15 |
def __init__(self):
|
16 |
self.buffer = ""
|
17 |
self.current_agent = None
|
|
|
18 |
|
19 |
def parse_output(self, text: str) -> List[ChatMessage]:
|
20 |
messages = []
|
@@ -31,7 +31,7 @@ class OutputParser:
|
|
31 |
metadata={"title": f"π€ {self.current_agent}"}
|
32 |
))
|
33 |
|
34 |
-
# Look for task information
|
35 |
task_match = re.search(r'\[INFO\]: == Starting Task: (.*?)(?=\n\n|\n> Entering|$)', cleaned_text, re.DOTALL)
|
36 |
if task_match and self.current_agent:
|
37 |
task_content = task_match.group(1).strip()
|
@@ -41,43 +41,31 @@ class OutputParser:
|
|
41 |
metadata={"title": f"π Task for {self.current_agent}"}
|
42 |
))
|
43 |
|
44 |
-
# Look for
|
45 |
-
|
46 |
-
if thought_match and self.current_agent:
|
47 |
-
thought_content = thought_match.group(1).strip()
|
48 |
-
messages.append(ChatMessage(
|
49 |
-
role="assistant",
|
50 |
-
content=thought_content,
|
51 |
-
metadata={"title": f"π {self.current_agent}'s Thoughts"}
|
52 |
-
))
|
53 |
-
|
54 |
-
# Look for final answers from non-Editor agents
|
55 |
-
if "Final Answer:" in cleaned_text and self.current_agent != "Editor":
|
56 |
answer_match = re.search(r'Final Answer:\s*(.*?)(?=\n> Finished chain|$)', cleaned_text, re.DOTALL)
|
57 |
if answer_match:
|
58 |
answer_content = answer_match.group(1).strip()
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
content=answer_content
|
80 |
-
))
|
81 |
|
82 |
return messages
|
83 |
|
|
|
9 |
from dotenv import load_dotenv
|
10 |
import threading
|
11 |
|
|
|
12 |
|
13 |
class OutputParser:
|
14 |
def __init__(self):
|
15 |
self.buffer = ""
|
16 |
self.current_agent = None
|
17 |
+
self.final_article_sent = False # Add this flag
|
18 |
|
19 |
def parse_output(self, text: str) -> List[ChatMessage]:
|
20 |
messages = []
|
|
|
31 |
metadata={"title": f"π€ {self.current_agent}"}
|
32 |
))
|
33 |
|
34 |
+
# Look for task information
|
35 |
task_match = re.search(r'\[INFO\]: == Starting Task: (.*?)(?=\n\n|\n> Entering|$)', cleaned_text, re.DOTALL)
|
36 |
if task_match and self.current_agent:
|
37 |
task_content = task_match.group(1).strip()
|
|
|
41 |
metadata={"title": f"π Task for {self.current_agent}"}
|
42 |
))
|
43 |
|
44 |
+
# Look for final answers from all agents
|
45 |
+
if "Final Answer:" in cleaned_text:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
answer_match = re.search(r'Final Answer:\s*(.*?)(?=\n> Finished chain|$)', cleaned_text, re.DOTALL)
|
47 |
if answer_match:
|
48 |
answer_content = answer_match.group(1).strip()
|
49 |
+
|
50 |
+
if self.current_agent == "Editor" and not self.final_article_sent:
|
51 |
+
# This is the final article - send only once
|
52 |
+
messages.append(ChatMessage(
|
53 |
+
role="assistant",
|
54 |
+
content="Final Article",
|
55 |
+
metadata={"title": "π Final Article"}
|
56 |
+
))
|
57 |
+
messages.append(ChatMessage(
|
58 |
+
role="assistant",
|
59 |
+
content=answer_content
|
60 |
+
))
|
61 |
+
self.final_article_sent = True
|
62 |
+
elif self.current_agent != "Editor":
|
63 |
+
# This is an intermediate output (Planner or Writer)
|
64 |
+
messages.append(ChatMessage(
|
65 |
+
role="assistant",
|
66 |
+
content=answer_content,
|
67 |
+
metadata={"title": f"π‘ Output from {self.current_agent}"}
|
68 |
+
))
|
|
|
|
|
69 |
|
70 |
return messages
|
71 |
|