mtyrrell commited on
Commit
6795b19
·
1 Parent(s): 4db8949

sources fix

Browse files
src/components/orchestration/ui_adapters.py CHANGED
@@ -3,6 +3,7 @@ ChatUI Adapters for LangGraph Workflow Streaming
3
  """
4
  import logging
5
  import asyncio
 
6
  from typing import AsyncGenerator, Dict, Any
7
 
8
  from components.utils import build_conversation_context
@@ -138,12 +139,10 @@ async def chatui_adapter(data, compiled_graph, max_turns: int = 3, max_chars: in
138
  sources_collected = content
139
  elif result_type == "end":
140
  if sources_collected:
141
- sources_text = "\n\n**Sources:**\n"
142
- for i, source in enumerate(sources_collected, 1):
143
- title = source.get('title', 'Unknown')
144
- uri = source.get('uri') or '#' # Handle empty string
145
- sources_text += f"{i}. [{title}]({uri})\n"
146
- yield sources_text
147
  elif result_type == "error":
148
  yield f"Error: {content}"
149
  else:
@@ -243,15 +242,10 @@ async def chatui_file_adapter(data, compiled_graph, max_turns: int = 3, max_char
243
  sources_collected = content
244
  elif result_type == "end":
245
  if sources_collected:
246
- sources_text = "\n\n**Sources:**\n"
247
- for i, source in enumerate(sources_collected, 1):
248
- if isinstance(source, dict):
249
- title = source.get('title', 'Unknown')
250
- uri = source.get('uri') or '#' # Handle empty string
251
- sources_text += f"{i}. [{title}]({uri})\n"
252
- else:
253
- sources_text += f"{i}. {str(source)}\n"
254
- yield sources_text
255
  elif result_type == "error":
256
  yield f"Error: {content}"
257
  else:
 
3
  """
4
  import logging
5
  import asyncio
6
+ import json
7
  from typing import AsyncGenerator, Dict, Any
8
 
9
  from components.utils import build_conversation_context
 
139
  sources_collected = content
140
  elif result_type == "end":
141
  if sources_collected:
142
+ # Send sources as structured JSON for ChatUI to parse
143
+ sources_json = json.dumps({"webSources": sources_collected})
144
+ logger.info(f"Sending structured sources: {sources_json}")
145
+ yield sources_json
 
 
146
  elif result_type == "error":
147
  yield f"Error: {content}"
148
  else:
 
242
  sources_collected = content
243
  elif result_type == "end":
244
  if sources_collected:
245
+ # Send sources as structured JSON for ChatUI to parse
246
+ sources_json = json.dumps({"webSources": sources_collected})
247
+ logger.info(f"Sending structured sources (file): {sources_json}")
248
+ yield sources_json
 
 
 
 
 
249
  elif result_type == "error":
250
  yield f"Error: {content}"
251
  else: