mirror of
https://github.com/marcominerva/SqlDatabaseVectorSearch.git
synced 2026-06-20 12:23:10 +00:00
Rename and enhance ChatService methods
Renamed `CreateQuestionAsync` to `CreateReformulateQuestionAsync` for clearer intent. Updated `CreateChatAsync` to include a new `ChatSystemPrompt` property in `AzureOpenAIPromptExecutionSettings` and modified `ChatHistory` initialization to simplify setup. Removed redundant `prompt` string construction and added user messages directly to `ChatHistory`. Updated `VectorSearchService` to use the renamed `CreateReformulateQuestionAsync` method for consistency. These changes improve code clarity, maintainability, and functionality.
This commit is contained in:
@@ -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<ChatResponse> CreateQuestionAsync(Guid conversationId, string question, CancellationToken cancellationToken = default)
|
||||
public async Task<ChatResponse> 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);
|
||||
|
||||
@@ -143,7 +143,7 @@ public partial class VectorSearchService(IServiceProvider serviceProvider, Appli
|
||||
private async Task<(ChatResponse ReformulatedQuestion, int EmbeddingTokenCount, IEnumerable<Entities.DocumentChunk> 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);
|
||||
|
||||
Reference in New Issue
Block a user