Skip to content

Commit d6c0e66

Browse files
committed
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.
1 parent dba2fb1 commit d6c0e66

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

SqlDatabaseVectorSearch/Services/ChatService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ The capital of Italy is Rome.
8686
Remember to ALWAYS end your answer with a period followed by a space before adding citations.
8787
""";
8888

89-
public async Task<ChatResponse> CreateQuestionAsync(Guid conversationId, string question, CancellationToken cancellationToken = default)
89+
public async Task<ChatResponse> CreateReformulateQuestionAsync(Guid conversationId, string question, CancellationToken cancellationToken = default)
9090
{
9191
var chat = await GetChatHistoryAsync(conversationId, cancellationToken);
9292

@@ -170,11 +170,10 @@ message.InnerContent is StreamingChatCompletionUpdate content && content.Usage i
170170
{
171171
var settings = new AzureOpenAIPromptExecutionSettings
172172
{
173-
MaxTokens = appSettings.MaxOutputTokens
173+
MaxTokens = appSettings.MaxOutputTokens,
174+
ChatSystemPrompt = systemPromptForAnswering
174175
};
175176

176-
var chat = new ChatHistory(systemPromptForAnswering);
177-
178177
var prompt = new StringBuilder($"""
179178
Answer the following question:
180179
---
@@ -210,6 +209,7 @@ message.InnerContent is StreamingChatCompletionUpdate content && content.Usage i
210209
}
211210
}
212211

212+
var chat = new ChatHistory();
213213
chat.AddUserMessage(prompt.ToString());
214214

215215
return (chat, settings);

SqlDatabaseVectorSearch/Services/VectorSearchService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public async IAsyncEnumerable<Response> AskStreamingAsync(Question question, boo
143143
private async Task<(ChatResponse ReformulatedQuestion, int EmbeddingTokenCount, IEnumerable<Entities.DocumentChunk> Chunks)> CreateContextAsync(Question question, bool reformulate, CancellationToken cancellationToken)
144144
{
145145
// Reformulate the question taking into account the context of the chat to perform keyword search and embeddings.
146-
var reformulatedQuestion = reformulate ? await chatService.CreateQuestionAsync(question.ConversationId, question.Text, cancellationToken) : new(question.Text);
146+
var reformulatedQuestion = reformulate ? await chatService.CreateReformulateQuestionAsync(question.ConversationId, question.Text, cancellationToken) : new(question.Text);
147147

148148
var embeddingTokenCount = tokenizerService.CountEmbeddingTokens(reformulatedQuestion.Text!);
149149
logger.LogDebug("Embedding Token Count: {EmbeddingTokenCount}", embeddingTokenCount);

0 commit comments

Comments
 (0)