@@ -82,23 +82,23 @@ public async Task<SearchResponse> SearchAsync(SearchRequest request)
8282 throw new InvalidOperationException ( "Azure OpenAI didn't return a meaningful response." ) ;
8383 }
8484
85- // if (answerMessage.AzureExtensionsContext != null)
86- // {
85+ if ( answerMessage . AzureExtensionsContext != null )
86+ {
8787 // Process citations within the answer, which take the form "[doc1][doc2]..." and refer to the (1-based) index of
8888 // the citations in the tool message.
89- // var citationIndex = 0;
90- // foreach (var citation in answerMessage.AzureExtensionsContext.Citations)
91- // {
92- // answerText = answerText.Replace($"[doc{++citationIndex}]", $"<cite>{citation.Title}{citation.Url}{citation.Filepath} </cite> XXX ", StringComparison.OrdinalIgnoreCase);
93- // searchResponse.SearchResults.Add(new SearchResult
94- // {
95- // DocumentId = citation.Filepath,
96- // DocumentTitle = citation.Title,
97- // DocumentSourceUrl = citation.Url,
98- // Captions = string.IsNullOrWhiteSpace(citation.Content) ? Array.Empty<string>() : new[] { citation.Content }
99- // });
100- // }
101- // }
89+ var citationIndex = 0 ;
90+ foreach ( var citation in answerMessage . AzureExtensionsContext . Citations )
91+ {
92+ answerText = answerText . Replace ( $ "[doc{ ++ citationIndex } ]", $ "<cite>{ citation . Title } </cite>", StringComparison . OrdinalIgnoreCase ) ;
93+ searchResponse . SearchResults . Add ( new SearchResult
94+ {
95+ DocumentId = citation . Filepath ,
96+ DocumentTitle = citation . Title ,
97+ DocumentSourceUrl = citation . Url ,
98+ Captions = string . IsNullOrWhiteSpace ( citation . Content ) ? Array . Empty < string > ( ) : new [ ] { citation . Content }
99+ } ) ;
100+ }
101+ }
102102
103103 searchResponse . Answers = new [ ] { new SearchAnswer { Text = answerText } } ;
104104 searchResponse . History . Add ( answerText ) ;
0 commit comments