Skip to content

Commit

Permalink
Minor changes and dispatcher prompt improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandro-avila committed Feb 18, 2025
1 parent 4278055 commit 975d23d
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ private async Task<string> ExtractIntentAsync(string message)
var input = AppendChatHistory(message);
var choices = GetAndSerializeChoices();
var prompt = $"""
You are a dispatcher agent, working with the Support Center.
You are a dispatcher agent, working with the Support Center of the Contoso organization.
You can help customers with their issues, and you can also assign tickets to other AI agents.
Read the customer's message carefully, and then decide the appropriate intent.
Read the customer's message carefully, and then decide the appropriate intent from the following list.
A history of the conversation is available to help you make a decision.
If you don't know the intent, don't guess; instead respond with "Unknown".
If you don't know the intent, please don't guess; instead respond with "Unknown".
There may be multiple intents, but you should choose the most appropriate one.
If you think that the message is not clear, you can ask the customer for more information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.AI.Agents.Abstractions;
using Microsoft.AspNetCore.Mvc;
using Orleans;
using Orleans.Runtime;
using SupportCenter.ApiService.Events;

namespace SupportCenter.ApiService.Controllers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public class CustomerRepository([FromKeyedServices("redis")] IConnectionMultiple
{
// Method that gets a customer by ID from redis database
public async Task<Customer?> GetCustomerByIdAsync(string customerId)
{
{
var db = redisConnection.GetDatabase();
var key = $"customers:{customerId}";
var customer = await db.StringGetAsync(key);
if (customer.IsNullOrEmpty)
{
return null;
}
return JsonSerializer.Deserialize<Customer>(customer);
return JsonSerializer.Deserialize<Customer>(customer.ToString());
}

public async Task<IEnumerable<Customer>> GetCustomersAsync()
Expand All @@ -30,14 +30,13 @@ public async Task<IEnumerable<Customer>> GetCustomersAsync()
var data = await db.StringGetAsync(key);
if (!data.IsNullOrEmpty)
{
var customer = JsonSerializer.Deserialize<Customer>(data);
var customer = JsonSerializer.Deserialize<Customer>(data.ToString());
if (customer != null)
{
customers.Add(customer);
}
}
}

return customers;
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

17 changes: 7 additions & 10 deletions samples/support-center/SupportCenter.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Azure.Provisioning.AppContainers;
using Azure.Provisioning;
using Azure.Provisioning.AppContainers;

var builder = DistributedApplication.CreateBuilder(args);

Expand All @@ -12,14 +12,13 @@
var redis = builder.AddRedis("redis")
.WithImage("redis/redis-stack-server")
.WithRedisCommander();
//.WithDataVolume(isReadOnly: false);
//.WithPersistence(interval: TimeSpan.FromMinutes(1), keysChangedThreshold: 10);
//.WithDataVolume(isReadOnly: false);
//.WithPersistence(interval: TimeSpan.FromMinutes(1), keysChangedThreshold: 10);

var openai = builder.ExecutionContext.IsPublishMode
? builder.AddAzureOpenAI("openAiConnection").AddDeployment(new AzureOpenAIDeployment("gpt-4o-mini", "gpt-4o-mini", "2024-07-18"))
: builder.AddConnectionString("openAiConnection");


var apiService = builder.AddProject<Projects.SupportCenter_ApiService>("apiservice")
.WithReference(openai)
.WithReference(signalr)
Expand Down Expand Up @@ -52,7 +51,7 @@
.WaitFor(streamingQueue)
.WaitFor(insights)
.WithEnvironment("HTTP_PORTS", "8081")
.WithReplicas(3 )
.WithReplicas(3)
.PublishAsAzureContainerApp((infra, capp) =>
{
capp.Configuration.Ingress.CorsPolicy = new ContainerAppCorsPolicy
Expand All @@ -61,11 +60,11 @@
AllowedOrigins = new BicepList<string> { "https://*.azurecontainerapps.io" },
AllowedHeaders = new BicepList<string> { "*" },
AllowedMethods = new BicepList<string> { "*" },

};
capp.Configuration.Ingress.TargetPort = 8081;
capp.Configuration.Ingress.TargetPort = 8081;
capp.Configuration.Ingress.StickySessionsAffinity = StickySessionAffinity.Sticky;
});
});
}
else
{
Expand All @@ -77,8 +76,6 @@
apiService.WithReference(orleans);
}



builder.AddNpmApp("frontend", "../SupportCenter.Frontend", "dev")
.WithReference(apiService)
.WithEnvironment("VITE_OAGENT_BASE_URL", apiService.GetEndpoint("http"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
<UserSecretsId>ca23c54b-f27b-425c-950f-9b608972c600</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<Content Include="appsettings.local.template.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SupportCenter.ApiService\SupportCenter.ApiService.csproj" />
<ProjectReference Include="..\SupportCenter.Seed.Memory\SupportCenter.Seed.Memory.csproj" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
},
"ConnectionStrings": {
"signalR": "Endpoint=;AccessKey=;Version=;",
"openAiConnection": "Endpoint=;Key="
}
}
22 changes: 12 additions & 10 deletions samples/support-center/SupportCenter.Seed.Memory/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
using UglyToad.PdfPig;
using UglyToad.PdfPig.DocumentLayoutAnalysis.TextExtractor;

string[] files = ["Benefit_Options.pdf", "employee_handbook.pdf", "Northwind_Health_Plus_Benefits_Details.pdf", "Northwind_Standard_Benefits_Details.pdf", "role_library.pdf"];
string[] files = [
"Benefit_Options.pdf",
"employee_handbook.pdf",
"Northwind_Health_Plus_Benefits_Details.pdf",
"Northwind_Standard_Benefits_Details.pdf",
"role_library.pdf"
];

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

Expand All @@ -21,15 +27,12 @@
return new RedisVectorStore(db, new() { StorageType = RedisStorageType.HashSet });
});


builder.Services.AddEmbeddingGenerator(s => {
return s.GetRequiredService<OpenAIClient>().AsEmbeddingGenerator("text-embedding-3-large");
});

using IHost host = builder.Build();



foreach (var file in files)
{
await ImportDocumentAsync(host.Services, file);
Expand All @@ -38,15 +41,15 @@
await host.RunAsync();



async Task ImportDocumentAsync(IServiceProvider hostProvider, string filename)
static async Task ImportDocumentAsync(IServiceProvider hostProvider, string filename)
{
using IServiceScope serviceScope = hostProvider.CreateScope();
var provider = serviceScope.ServiceProvider;
var vectorStore = provider.GetRequiredService<IVectorStore>();
var embeddingGenerator = provider.GetRequiredService<IEmbeddingGenerator<string, Embedding<float>>>();

var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
?? throw new InvalidOperationException("Current directory cannot be determined.");
var filePath = Path.Combine(currentDirectory, filename);
using var pdfDocument = PdfDocument.Open(File.OpenRead(filePath));
var pages = pdfDocument.GetPages();
Expand All @@ -57,7 +60,7 @@ async Task ImportDocumentAsync(IServiceProvider hostProvider, string filename)
try
{
var text = ContentOrderTextExtractor.GetText(page);
var descr = new string(text.Take(100).ToArray());
var descr = new string([.. text.Take(100)]);
var vector = await embeddingGenerator.GenerateEmbeddingVectorAsync(text);
await collection.UpsertAsync(new Document { Key = $"{Guid.NewGuid()}", Description = $"Document: {descr}", Text = text, Vector = vector });
}
Expand All @@ -66,5 +69,4 @@ async Task ImportDocumentAsync(IServiceProvider hostProvider, string filename)
Console.WriteLine($"Error processing page: {ex.Message}");
}
}
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 975d23d

Please sign in to comment.