Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -100,30 +100,54 @@ class OpenFloorResearchAgent:
|
|
100 |
|
101 |
def handle_utterance_event(self, envelope: Envelope) -> Envelope:
|
102 |
"""Handle research requests from AI experts"""
|
|
|
|
|
|
|
103 |
# Extract the query from the utterance
|
104 |
-
for event in envelope.events:
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
print(f"π DEBUG: {self.tool.name} completed in {end_time - start_time:.2f}s")
|
121 |
-
print(f"π DEBUG: Result length: {len(research_result)} chars")
|
122 |
-
print(f"π DEBUG: Result preview: {research_result[:200]}...")
|
123 |
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
|
|
127 |
return self._create_error_response(envelope, "Could not extract query from request")
|
128 |
|
129 |
def _create_response_envelope(self, original_envelope: Envelope, research_result: str, query: str) -> Envelope:
|
|
|
100 |
|
101 |
def handle_utterance_event(self, envelope: Envelope) -> Envelope:
|
102 |
"""Handle research requests from AI experts"""
|
103 |
+
print(f"π DEBUG: {self.tool.name} - Starting handle_utterance_event")
|
104 |
+
print(f"π DEBUG: Envelope has {len(envelope.events)} events")
|
105 |
+
|
106 |
# Extract the query from the utterance
|
107 |
+
for i, event in enumerate(envelope.events):
|
108 |
+
print(f"π DEBUG: Event {i}: {type(event)} - hasattr eventType: {hasattr(event, 'eventType')}")
|
109 |
+
|
110 |
+
if hasattr(event, 'eventType'):
|
111 |
+
print(f"π DEBUG: Event {i} eventType: {event.eventType}")
|
112 |
+
|
113 |
+
if event.eventType == 'utterance':
|
114 |
+
print(f"π DEBUG: Found utterance event, getting parameters...")
|
115 |
+
dialog_event = event.parameters.get('dialogEvent')
|
116 |
+
print(f"π DEBUG: dialog_event: {type(dialog_event)}")
|
117 |
+
|
118 |
+
if dialog_event and hasattr(dialog_event, 'features'):
|
119 |
+
print(f"π DEBUG: dialog_event has features")
|
120 |
+
text_feature = dialog_event.features.get('text')
|
121 |
+
print(f"π DEBUG: text_feature: {type(text_feature)}")
|
|
|
|
|
|
|
|
|
122 |
|
123 |
+
if text_feature and hasattr(text_feature, 'tokens'):
|
124 |
+
print(f"π DEBUG: text_feature has {len(text_feature.tokens)} tokens")
|
125 |
+
query_text = ' '.join([token.get('value', '') for token in text_feature.tokens])
|
126 |
+
|
127 |
+
print(f"π DEBUG: {self.tool.name} received query: '{query_text}'")
|
128 |
+
|
129 |
+
# Perform the research
|
130 |
+
import time
|
131 |
+
start_time = time.time()
|
132 |
+
research_result = self.tool.search(query_text)
|
133 |
+
end_time = time.time()
|
134 |
+
|
135 |
+
print(f"π DEBUG: {self.tool.name} completed in {end_time - start_time:.2f}s")
|
136 |
+
print(f"π DEBUG: Result length: {len(research_result)} chars")
|
137 |
+
print(f"π DEBUG: Result preview: {research_result[:200]}...")
|
138 |
+
|
139 |
+
# Create response envelope
|
140 |
+
return self._create_response_envelope(envelope, research_result, query_text)
|
141 |
+
else:
|
142 |
+
print(f"π DEBUG: text_feature doesn't have tokens or is None")
|
143 |
+
else:
|
144 |
+
print(f"π DEBUG: dialog_event doesn't have features or is None")
|
145 |
+
else:
|
146 |
+
print(f"π DEBUG: Event {i} is not utterance, skipping")
|
147 |
+
else:
|
148 |
+
print(f"π DEBUG: Event {i} doesn't have eventType attribute")
|
149 |
|
150 |
+
print(f"π DEBUG: No valid utterance event found, returning error")
|
151 |
return self._create_error_response(envelope, "Could not extract query from request")
|
152 |
|
153 |
def _create_response_envelope(self, original_envelope: Envelope, research_result: str, query: str) -> Envelope:
|