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 to singleton. - Reformatted ChatHistory initialization in ChatService.cs. - Modified prompt construction to avoid new lines after chunks. - Updated Microsoft.SemanticKernel package to version 1.27.0.
This commit is contained in:
@@ -32,7 +32,7 @@ builder.Services.AddKernel()
|
|||||||
.AddAzureOpenAITextEmbeddingGeneration(aiSettings.Embedding.Deployment, aiSettings.Embedding.Endpoint, aiSettings.Embedding.ApiKey, dimensions: aiSettings.Embedding.Dimensions)
|
.AddAzureOpenAITextEmbeddingGeneration(aiSettings.Embedding.Deployment, aiSettings.Embedding.Endpoint, aiSettings.Embedding.ApiKey, dimensions: aiSettings.Embedding.Dimensions)
|
||||||
.AddAzureOpenAIChatCompletion(aiSettings.ChatCompletion.Deployment, aiSettings.ChatCompletion.Endpoint, aiSettings.ChatCompletion.ApiKey);
|
.AddAzureOpenAIChatCompletion(aiSettings.ChatCompletion.Deployment, aiSettings.ChatCompletion.Endpoint, aiSettings.ChatCompletion.ApiKey);
|
||||||
|
|
||||||
builder.Services.AddScoped<ChatService>();
|
builder.Services.AddSingleton<ChatService>();
|
||||||
builder.Services.AddScoped<VectorSearchService>();
|
builder.Services.AddScoped<VectorSearchService>();
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
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)
|
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.
|
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".
|
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.
|
Never answer to questions that are not related to this chat.
|
||||||
You must answer in the same language of the user's question.
|
You must answer in the same language of the user's question.
|
||||||
"""");
|
""");
|
||||||
|
|
||||||
var prompt = new StringBuilder("""
|
var prompt = new StringBuilder("""
|
||||||
Using the following information:
|
Using the following information:
|
||||||
@@ -52,7 +51,7 @@ public class ChatService(IMemoryCache cache, IChatCompletionService chatCompleti
|
|||||||
// TODO: Ensure that chunks are not too long, according to the model max token.
|
// TODO: Ensure that chunks are not too long, according to the model max token.
|
||||||
foreach (var result in chunks)
|
foreach (var result in chunks)
|
||||||
{
|
{
|
||||||
prompt.AppendLine(result);
|
prompt.Append(result);
|
||||||
prompt.AppendLine("---");
|
prompt.AppendLine("---");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
|
||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
|
||||||
<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="MinimalHelpers.OpenApi" Version="2.0.17" />
|
||||||
<PackageReference Include="PdfPig" Version="0.1.9" />
|
<PackageReference Include="PdfPig" Version="0.1.9" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
|
||||||
|
|||||||
Reference in New Issue
Block a user