WHG2023 commited on
Commit
0f743a0
·
1 Parent(s): c73dc6a

fix: Improve backend parsing and frontend stability

Browse files
Files changed (2) hide show
  1. app.py +6 -15
  2. real_ai_agents_implementation.py +11 -3
app.py CHANGED
@@ -112,24 +112,15 @@ def create_negotiation_transcript_display(transcript: List[Dict]) -> str:
112
  if not transcript:
113
  return "### Agent Negotiation Log\n\n*Awaiting instructions...*"
114
 
115
- markdown = "### Agent Negotiation Log\n\n---\n\n"
116
  for entry in transcript:
117
  agent = entry.get('agent', 'System')
118
- message = entry.get('message', '')
119
 
120
- # Make the agent name bold and add color
121
- if agent == "Chief Strategist":
122
- color = "#ff8c00" # Orange
123
- elif agent == "Conceptual Artist":
124
- color = "#da70d6" # Orchid
125
- elif agent == "System":
126
- color = "#ff4d4d" # Red
127
- else:
128
- color = "#00ff41" # Green
129
-
130
- markdown += f"<p style='color: {color}; margin-bottom: 5px;'><strong>🤖 {agent}:</strong></p>\n"
131
- markdown += f"<p style='margin-left: 20px; margin-top: 0px;'>{message}</p>\n\n"
132
- markdown += "---\n\n"
133
 
134
  return markdown
135
 
 
112
  if not transcript:
113
  return "### Agent Negotiation Log\n\n*Awaiting instructions...*"
114
 
115
+ markdown = "### Agent Negotiation Log\n\n---\n"
116
  for entry in transcript:
117
  agent = entry.get('agent', 'System')
118
+ message = entry.get('message', '').replace('\n', '\n> ') # Indent multiline messages
119
 
120
+ # Using markdown emphasis and blockquotes instead of raw HTML
121
+ markdown += f"\n\n**🤖 {agent}:**\n"
122
+ markdown += f"> {message}\n\n"
123
+ markdown += "---"
 
 
 
 
 
 
 
 
 
124
 
125
  return markdown
126
 
real_ai_agents_implementation.py CHANGED
@@ -188,14 +188,22 @@ class PriorArtDetective(BaseAgent):
188
  summary_response_text = self._execute_prompt(summary_prompt)
189
 
190
  try:
191
- summary_data = json.loads(summary_response_text.strip())
 
 
 
 
 
 
 
192
  summary_data["key_concepts"] = key_concepts # Add concepts for context
193
  return summary_data
194
  except json.JSONDecodeError:
 
195
  return {
196
  "key_concepts": key_concepts,
197
- "real_prior_art": search_findings,
198
- "landscape_summary": "Error parsing summary from LLM, but search was performed.",
199
  }
200
 
201
  class ChiefStrategistAgent(BaseAgent):
 
188
  summary_response_text = self._execute_prompt(summary_prompt)
189
 
190
  try:
191
+ # Clean the response to handle markdown code blocks
192
+ match = re.search(r'```json\s*([\s\S]*?)\s*```', summary_response_text)
193
+ if match:
194
+ json_str = match.group(1)
195
+ else:
196
+ json_str = summary_response_text
197
+
198
+ summary_data = json.loads(json_str.strip())
199
  summary_data["key_concepts"] = key_concepts # Add concepts for context
200
  return summary_data
201
  except json.JSONDecodeError:
202
+ print(f"Failed to parse JSON from LLM summary response: {summary_response_text}")
203
  return {
204
  "key_concepts": key_concepts,
205
+ "real_prior_art": search_findings, # Return the raw findings
206
+ "landscape_summary": "Error: The AI's analysis of the search results could not be parsed.",
207
  }
208
 
209
  class ChiefStrategistAgent(BaseAgent):