mirror of
https://github.com/marcominerva/SqlDatabaseVectorSearch.git
synced 2026-06-20 12:23:10 +00:00
Refactor and enhance config management
Refactored code to centralize configuration access through a single `AppSettings` instance in `ChatService` and `VectorSearchService`, improving maintainability and reducing verbosity. Introduced new configuration settings (`MaxTokensPerLine`, `MaxTokensPerParagraph`, `OverlapTokens`, `MaxChunksCount`) in `AppSettings.cs` and `appsettings.json` for enhanced flexibility in content processing. Adjusted existing settings usage (`MessageLimit`, `MessageExpiration`) to align with the new access method, and removed obsolete settings (`StoragePath`, `VectorDbPath`, `QueuePath`). These changes simplify the codebase, make the application more configurable and adaptable to different content characteristics, and allow for more controlled vector search operations.
This commit is contained in:
@@ -9,6 +9,8 @@ namespace SqlDatabaseVectorSearch.Services;
|
||||
|
||||
public class ChatService(IMemoryCache cache, IChatCompletionService chatCompletionService, IOptions<AppSettings> appSettingsOptions)
|
||||
{
|
||||
private readonly AppSettings appSettings = appSettingsOptions.Value;
|
||||
|
||||
public async Task<string> CreateQuestionAsync(Guid conversationId, string question)
|
||||
{
|
||||
var chat = new ChatHistory(cache.Get<ChatHistory?>(conversationId) ?? []);
|
||||
@@ -77,12 +79,12 @@ public class ChatService(IMemoryCache cache, IChatCompletionService chatCompleti
|
||||
|
||||
private Task UpdateCacheAsync(Guid conversationId, ChatHistory chat)
|
||||
{
|
||||
if (chat.Count > appSettingsOptions.Value.MessageLimit)
|
||||
if (chat.Count > appSettings.MessageLimit)
|
||||
{
|
||||
chat = new ChatHistory(chat.TakeLast(appSettingsOptions.Value.MessageLimit));
|
||||
chat = new ChatHistory(chat.TakeLast(appSettings.MessageLimit));
|
||||
}
|
||||
|
||||
cache.Set(conversationId, chat, appSettingsOptions.Value.MessageExpiration);
|
||||
cache.Set(conversationId, chat, appSettings.MessageExpiration);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user