mirror of
https://github.com/marcominerva/SqlDatabaseVectorSearch.git
synced 2026-06-20 12:23:10 +00:00
Change ChatService to singleton, update package version
- Changed ChatService registration in Program.cs from scoped to singleton. - Modified ChatHistory initialization in ChatService.cs by removing unnecessary line breaks. - Renamed loop variable in ChatService.cs from 'result' to 'text' for better readability. - Updated Microsoft.SemanticKernel package version from 1.26.0 to 1.27.0 in SqlDatabaseVectorSearch.csproj.
This commit is contained in:
@@ -35,7 +35,7 @@ builder.Services.AddKernel()
|
||||
.AddAzureOpenAITextEmbeddingGeneration(aiSettings.Embedding.Deployment, aiSettings.Embedding.Endpoint, aiSettings.Embedding.ApiKey, dimensions: aiSettings.Embedding.Dimensions)
|
||||
.AddAzureOpenAIChatCompletion(aiSettings.ChatCompletion.Deployment, aiSettings.ChatCompletion.Endpoint, aiSettings.ChatCompletion.ApiKey);
|
||||
|
||||
builder.Services.AddScoped<ChatService>();
|
||||
builder.Services.AddSingleton<ChatService>();
|
||||
builder.Services.AddScoped<VectorSearchService>();
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
@@ -35,13 +35,12 @@ public class ChatService(IMemoryCache cache, IChatCompletionService chatCompleti
|
||||
|
||||
public async Task<string> AskQuestionAsync(Guid conversationId, IEnumerable<string> chunks, string question)
|
||||
{
|
||||
var chat = new ChatHistory(""""
|
||||
"""
|
||||
var chat = new ChatHistory("""
|
||||
You can use only the information provided in this chat to answer questions. If you don't know the answer, reply suggesting to refine the question.
|
||||
For example, if the user asks "What is the capital of France?" and in this chat there isn't information about France, you should reply something like "This information isn't available in the given context".
|
||||
Never answer to questions that are not related to this chat.
|
||||
You must answer in the same language of the user's question.
|
||||
"""");
|
||||
""");
|
||||
|
||||
var prompt = new StringBuilder("""
|
||||
Using the following information:
|
||||
@@ -50,9 +49,9 @@ public class ChatService(IMemoryCache cache, IChatCompletionService chatCompleti
|
||||
""");
|
||||
|
||||
// TODO: Ensure that chunks are not too long, according to the model max token.
|
||||
foreach (var result in chunks)
|
||||
foreach (var text in chunks)
|
||||
{
|
||||
prompt.AppendLine(result);
|
||||
prompt.Append(text);
|
||||
prompt.AppendLine("---");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<PackageReference Include="EntityFrameworkCore.Exceptions.SqlServer" Version="8.1.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.SemanticKernel" Version="1.26.0" />
|
||||
<PackageReference Include="Microsoft.SemanticKernel" Version="1.27.0" />
|
||||
<PackageReference Include="MinimalHelpers.OpenApi" Version="2.0.17" />
|
||||
<PackageReference Include="PdfPig" Version="0.1.9" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
|
||||
|
||||
Reference in New Issue
Block a user