@@ -76,9 +76,6 @@ public AIChatService(IOptions<AIOptions> options, AISearchService searchService)
7676 bool enableContextualSearch = false ,
7777 [ System . Runtime . CompilerServices . EnumeratorCancellation ] CancellationToken cancellationToken = default )
7878 {
79- // Add logging to help debug the conversation state issue
80- Debug . WriteLine ( $ "GetChatCompletionStream called with previousResponseId: { previousResponseId } ") ;
81-
8279 var responseOptions = await CreateResponseOptionsAsync ( previousResponseId , tools , reasoningEffortLevel , mcpClient : mcpClient , cancellationToken : cancellationToken ) ;
8380 var enrichedPrompt = await EnrichPromptWithContext ( prompt , enableContextualSearch , cancellationToken ) ;
8481
@@ -113,33 +110,24 @@ private async Task<string> EnrichPromptWithContext(string prompt, bool enableCon
113110 return prompt ;
114111 }
115112
116- try
117- {
118- var searchResults = await _SearchService . ExecuteVectorSearch ( prompt ) ;
119- var contextualInfo = new System . Text . StringBuilder ( ) ;
120-
121- contextualInfo . AppendLine ( "## Contextual Information" ) ;
122- contextualInfo . AppendLine ( "The following information might be relevant to your question:" ) ;
123- contextualInfo . AppendLine ( ) ;
124-
125- await foreach ( var result in searchResults )
126- {
127- contextualInfo . AppendLine ( System . Globalization . CultureInfo . InvariantCulture , $ "**From: { result . Record . Heading } **") ;
128- contextualInfo . AppendLine ( result . Record . ChunkText ) ;
129- contextualInfo . AppendLine ( ) ;
130- }
113+ var searchResults = await _SearchService . ExecuteVectorSearch ( prompt ) ;
114+ var contextualInfo = new System . Text . StringBuilder ( ) ;
131115
132- contextualInfo . AppendLine ( "## User Question" ) ;
133- contextualInfo . AppendLine ( prompt ) ;
116+ contextualInfo . AppendLine ( "## Contextual Information" ) ;
117+ contextualInfo . AppendLine ( "The following information might be relevant to your question:" ) ;
118+ contextualInfo . AppendLine ( ) ;
134119
135- return contextualInfo . ToString ( ) ;
136- }
137- catch ( Exception ex )
120+ await foreach ( var result in searchResults )
138121 {
139- // Log the error but don't fail the request
140- Debug . WriteLine ( $ "Error enriching prompt with context: { ex . Message } " ) ;
141- return prompt ;
122+ contextualInfo . AppendLine ( System . Globalization . CultureInfo . InvariantCulture , $ "**From: { result . Record . Heading } **" ) ;
123+ contextualInfo . AppendLine ( result . Record . ChunkText ) ;
124+ contextualInfo . AppendLine ( ) ;
142125 }
126+
127+ contextualInfo . AppendLine ( "## User Question" ) ;
128+ contextualInfo . AppendLine ( prompt ) ;
129+
130+ return contextualInfo . ToString ( ) ;
143131 }
144132
145133 /// <summary>
0 commit comments