@@ -86,26 +86,16 @@ public async Task<SearchResponse> SearchAsync(SearchRequest request)
8686 {
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- foreach ( var extensionMessage in answerMessage . AzureExtensionsContext . Messages . Where ( m => m . Role == ChatRole . Tool ) )
89+ var citationIndex = 0 ;
90+ foreach ( var citation in answerMessage . AzureExtensionsContext . Citations )
9091 {
91- Console . WriteLine ( extensionMessage . Content ) ;
92- var content = JsonSerializer . Deserialize < ChatResponseMessageContent > ( extensionMessage . Content ! ) ;
93- if ( content ? . Citations != null && content . Citations . Any ( ) )
92+ answerText = answerText . Replace ( $ "[doc{ ++ citationIndex } ]", $ "<cite>{ citation . Title } </cite>", StringComparison . OrdinalIgnoreCase ) ;
93+ searchResponse . SearchResults . Add ( new SearchResult
9494 {
95- var citationIndex = 0 ;
96- foreach ( var citation in content . Citations )
97- {
98- answerText = answerText . Replace ( $ "[doc{ ++ citationIndex } ]", $ "<cite>{ citation . Title } </cite>", StringComparison . OrdinalIgnoreCase ) ;
99- searchResponse . SearchResults . Add ( new SearchResult
100- {
101- DocumentId = citation . Id ,
102- DocumentTitle = citation . Title ,
103- Captions = string . IsNullOrWhiteSpace ( citation . Content ) ? Array . Empty < string > ( ) : new [ ] { citation . Content }
104- } ) ;
105- }
106- // Stop looping through the tool messages once we find the first one holding the citations.
107- break ;
108- }
95+ DocumentId = citation . Filepath ,
96+ DocumentTitle = citation . Title ,
97+ Captions = string . IsNullOrWhiteSpace ( citation . Content ) ? Array . Empty < string > ( ) : new [ ] { citation . Content }
98+ } ) ;
10999 }
110100 }
111101
@@ -114,19 +104,19 @@ public async Task<SearchResponse> SearchAsync(SearchRequest request)
114104 return searchResponse ;
115105 }
116106
117- private AzureCognitiveSearchChatExtensionConfiguration GetAzureCognitiveSearchDataSource ( SearchRequest request )
107+ private AzureSearchChatExtensionConfiguration GetAzureCognitiveSearchDataSource ( SearchRequest request )
118108 {
119109 ArgumentNullException . ThrowIfNull ( this . settings . SearchServiceUrl ) ;
120110 ArgumentNullException . ThrowIfNull ( this . settings . SearchServiceAdminKey ) ;
121111 ArgumentNullException . ThrowIfNull ( this . settings . OpenAIEndpoint ) ;
122112 ArgumentNullException . ThrowIfNull ( this . settings . OpenAIApiKey ) ;
123113 var useDocumentsIndex = request . SearchIndex == SearchIndexType . Documents ;
124- return new AzureCognitiveSearchChatExtensionConfiguration
114+ return new AzureSearchChatExtensionConfiguration
125115 {
126116 SearchEndpoint = new Uri ( this . settings . SearchServiceUrl ) ,
127- Key = this . settings . SearchServiceAdminKey ,
117+ Authentication = new OnYourDataApiKeyAuthenticationOptions ( this . settings . SearchServiceAdminKey ) ,
128118 IndexName = useDocumentsIndex ? this . settings . SearchIndexNameBlobDocuments : this . settings . SearchIndexNameBlobChunks ,
129- FieldMappingOptions = new AzureCognitiveSearchIndexFieldMappingOptions
119+ FieldMappingOptions = new AzureSearchIndexFieldMappingOptions
130120 {
131121 ContentFieldNames = { useDocumentsIndex ? nameof ( Document . Content ) : nameof ( DocumentChunk . Content ) } ,
132122 TitleFieldName = useDocumentsIndex ? nameof ( Document . Title ) : nameof ( DocumentChunk . SourceDocumentTitle ) ,
@@ -140,78 +130,35 @@ private AzureCognitiveSearchChatExtensionConfiguration GetAzureCognitiveSearchDa
140130 Strictness = request . Strictness ?? Constants . Defaults . Strictness ,
141131 DocumentCount = request . DocumentCount ?? Constants . Defaults . DocumentCount ,
142132 SemanticConfiguration = request . IsSemanticSearch ? Constants . ConfigurationNames . SemanticConfigurationNameDefault : null ,
143- EmbeddingEndpoint = request . IsVectorSearch ? new Uri ( new Uri ( this . settings . OpenAIEndpoint ) , $ "openai/deployments/{ this . settings . OpenAIEmbeddingDeployment } /embeddings?api-version={ this . settings . OpenAIApiVersion } ") : null ,
144- EmbeddingKey = request . IsVectorSearch ? this . settings . OpenAIApiKey : null
133+ VectorizationSource = request . IsVectorSearch ? new OnYourDataDeploymentNameVectorizationSource ( this . settings . OpenAIEmbeddingDeployment ) : null
145134 } ;
146135 }
147136
148- private AzureCognitiveSearchQueryType GetQueryType ( SearchRequest request )
137+ private AzureSearchQueryType GetQueryType ( SearchRequest request )
149138 {
150139 if ( request . QueryType == QueryType . TextStandard )
151140 {
152- return AzureCognitiveSearchQueryType . Simple ;
141+ return AzureSearchQueryType . Simple ;
153142 }
154143 else if ( request . QueryType == QueryType . TextSemantic )
155144 {
156- return AzureCognitiveSearchQueryType . Semantic ;
145+ return AzureSearchQueryType . Semantic ;
157146 }
158147 else if ( request . QueryType == QueryType . Vector )
159148 {
160- return AzureCognitiveSearchQueryType . Vector ;
149+ return AzureSearchQueryType . Vector ;
161150 }
162151 else if ( request . QueryType == QueryType . HybridStandard )
163152 {
164- return AzureCognitiveSearchQueryType . VectorSimpleHybrid ;
153+ return AzureSearchQueryType . VectorSimpleHybrid ;
165154 }
166155 else if ( request . QueryType == QueryType . HybridSemantic )
167156 {
168- return AzureCognitiveSearchQueryType . VectorSemanticHybrid ;
157+ return AzureSearchQueryType . VectorSemanticHybrid ;
169158 }
170159 else
171160 {
172161 throw new NotSupportedException ( $ "Unsupported query type \" { request . QueryType } \" .") ;
173162 }
174163 }
175-
176- // These model classes are based on the Azure OpenAI playground and samples
177- // to use while waiting for .NET SDK support.
178-
179- private class ChatResponseMessageContent
180- {
181- [ JsonPropertyName ( "citations" ) ]
182- public IList < Citation > Citations { get ; set ; } = new List < Citation > ( ) ;
183-
184- [ JsonPropertyName ( "intent" ) ]
185- public string ? Intent { get ; set ; } // This seems to be yet another nested JSON object, as an array of strings
186- }
187-
188- private class Citation
189- {
190- [ JsonPropertyName ( "content" ) ]
191- public string ? Content { get ; set ; }
192-
193- [ JsonPropertyName ( "id" ) ]
194- public string ? Id { get ; set ; }
195-
196- [ JsonPropertyName ( "title" ) ]
197- public string ? Title { get ; set ; }
198-
199- [ JsonPropertyName ( "filepath" ) ]
200- public string ? Filepath { get ; set ; }
201-
202- [ JsonPropertyName ( "url" ) ]
203- public string ? Url { get ; set ; }
204-
205- [ JsonPropertyName ( "metadata" ) ]
206- public CitationMetadata Metadata { get ; set ; } = new CitationMetadata ( ) ;
207-
208- [ JsonPropertyName ( "chunk_id" ) ]
209- public string ? ChunkId { get ; set ; }
210- }
211-
212- private class CitationMetadata
213- {
214- [ JsonPropertyName ( "chunking" ) ]
215- public string ? Chunking { get ; set ; }
216- }
217164}
0 commit comments