|
4 | 4 | from dataclasses import dataclass
|
5 | 5 | from typing import Any, Callable, Optional, TypedDict, Union, cast
|
6 | 6 | from urllib.parse import urljoin
|
| 7 | +import json |
7 | 8 |
|
8 | 9 | import aiohttp
|
9 | 10 | from azure.search.documents.agent.aio import KnowledgeAgentRetrievalClient
|
@@ -297,19 +298,26 @@ async def run_agentic_retrieval(
|
297 | 298 | )
|
298 | 299 |
|
299 | 300 | results = []
|
300 |
| - if response and response.references: |
301 |
| - for reference in response.references: |
302 |
| - if isinstance(reference, KnowledgeAgentAzureSearchDocReference) and reference.source_data: |
303 |
| - results.append( |
304 |
| - Document( |
305 |
| - id=reference.doc_key, |
306 |
| - content=reference.source_data["content"], |
307 |
| - sourcepage=reference.source_data["sourcepage"], |
308 |
| - search_agent_query=activity_mapping[reference.activity_source], |
309 |
| - ) |
310 |
| - ) |
311 |
| - if top and len(results) == top: |
312 |
| - break |
| 301 | + grounding_text = response.response[0].content[0].text |
| 302 | + if response and grounding_text: |
| 303 | + grounding_response = json.loads(grounding_text) |
| 304 | + for grounding_reference in grounding_response: |
| 305 | + ref_id = grounding_reference.get("ref_id") |
| 306 | + if ref_id is not None: |
| 307 | + ref_id = str(ref_id) |
| 308 | + for reference in response.references: |
| 309 | + if isinstance(reference, KnowledgeAgentAzureSearchDocReference) and reference.id == ref_id and reference.source_data: |
| 310 | + results.append( |
| 311 | + Document( |
| 312 | + id=reference.doc_key, |
| 313 | + content=reference.source_data["content"], |
| 314 | + sourcepage=reference.source_data["sourcepage"], |
| 315 | + search_agent_query=activity_mapping[reference.activity_source], |
| 316 | + ) |
| 317 | + ) |
| 318 | + break |
| 319 | + if top and len(results) == top: |
| 320 | + break |
313 | 321 |
|
314 | 322 | return response, results
|
315 | 323 |
|
|
0 commit comments