diff --git a/SqlDatabaseVectorSearch/Services/ChatService.cs b/SqlDatabaseVectorSearch/Services/ChatService.cs index 00eafa7..d0c68b3 100644 --- a/SqlDatabaseVectorSearch/Services/ChatService.cs +++ b/SqlDatabaseVectorSearch/Services/ChatService.cs @@ -86,7 +86,7 @@ public class ChatService(IChatCompletionService chatCompletionService, Tokenizer Remember to ALWAYS end your answer with a period followed by a space before adding citations. """; - public async Task CreateQuestionAsync(Guid conversationId, string question, CancellationToken cancellationToken = default) + public async Task CreateReformulateQuestionAsync(Guid conversationId, string question, CancellationToken cancellationToken = default) { var chat = await GetChatHistoryAsync(conversationId, cancellationToken); @@ -170,11 +170,10 @@ public class ChatService(IChatCompletionService chatCompletionService, Tokenizer { var settings = new AzureOpenAIPromptExecutionSettings { - MaxTokens = appSettings.MaxOutputTokens + MaxTokens = appSettings.MaxOutputTokens, + ChatSystemPrompt = systemPromptForAnswering }; - var chat = new ChatHistory(systemPromptForAnswering); - var prompt = new StringBuilder($""" Answer the following question: --- @@ -210,6 +209,7 @@ public class ChatService(IChatCompletionService chatCompletionService, Tokenizer } } + var chat = new ChatHistory(); chat.AddUserMessage(prompt.ToString()); return (chat, settings); diff --git a/SqlDatabaseVectorSearch/Services/VectorSearchService.cs b/SqlDatabaseVectorSearch/Services/VectorSearchService.cs index cc49944..f18d39e 100644 --- a/SqlDatabaseVectorSearch/Services/VectorSearchService.cs +++ b/SqlDatabaseVectorSearch/Services/VectorSearchService.cs @@ -143,7 +143,7 @@ public partial class VectorSearchService(IServiceProvider serviceProvider, Appli private async Task<(ChatResponse ReformulatedQuestion, int EmbeddingTokenCount, IEnumerable Chunks)> CreateContextAsync(Question question, bool reformulate, CancellationToken cancellationToken) { // Reformulate the question taking into account the context of the chat to perform keyword search and embeddings. - var reformulatedQuestion = reformulate ? await chatService.CreateQuestionAsync(question.ConversationId, question.Text, cancellationToken) : new(question.Text); + var reformulatedQuestion = reformulate ? await chatService.CreateReformulateQuestionAsync(question.ConversationId, question.Text, cancellationToken) : new(question.Text); var embeddingTokenCount = tokenizerService.CountEmbeddingTokens(reformulatedQuestion.Text!); logger.LogDebug("Embedding Token Count: {EmbeddingTokenCount}", embeddingTokenCount);