Skip to content

Commit

Permalink
Clean up use of Python inference
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSandersonMS committed Jun 4, 2024
1 parent e383d82 commit 7159738
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
6 changes: 0 additions & 6 deletions src/AppHost/Python/PythonUvicornAppResource.cs

This file was deleted.

14 changes: 7 additions & 7 deletions src/AppHost/Python/PythonUvicornAppResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using AppHost;

namespace Aspire.Hosting;
namespace Aspire.Hosting;

public static class PythonUvicornAppResourceBuilderExtensions
{
public static IResourceBuilder<PythonUvicornAppResource> AddPythonUvicornApp(this IDistributedApplicationBuilder builder, string name, string workingDirectory, int? port = default, int? targetPort = default)
{
return builder.AddResource(new PythonUvicornAppResource(
name,
"python",
workingDirectory))
return builder.AddResource(new PythonUvicornAppResource(name, "python", workingDirectory))
.WithArgs("-m", "uvicorn", "main:app")
.WithHttpEndpoint(env: "UVICORN_PORT", port: port, targetPort: targetPort);
}
}

public class PythonUvicornAppResource(string name, string command, string workingDirectory)
: ExecutableResource(name, command, workingDirectory), IResourceWithServiceDiscovery
{
}
6 changes: 4 additions & 2 deletions src/Backend/Api/TicketApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ private static async Task<IResult> CloseTicketAsync(AppDbContext dbContext, int

private static async Task CreateTicketAsync(AppDbContext dbContext, TicketSummarizer summarizer, PythonInferenceClient pythonInference, CreateTicketRequest request)
{
// Classify the new ticket
// Classify the new ticket using the small zero-shot classifier model
var ticketTypes = Enum.GetValues<TicketType>();
var inferredTicketType = await pythonInference.ClassifyTextAsync(request.Message, ticketTypes.Select(type => type.ToString()));
var inferredTicketType = await pythonInference.ClassifyTextAsync(
request.Message,
candidateLabels: ticketTypes.Select(type => type.ToString()));

var ticket = new Ticket
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ namespace eShopSupport.ServiceDefaults.Clients.PythonInference;

public class PythonInferenceClient(HttpClient http)
{
public async Task<string> ClassifyTextAsync(string text, IEnumerable<string> candidateLabels)
public async Task<string?> ClassifyTextAsync(string text, IEnumerable<string> candidateLabels)
{
var response = await http.PostAsJsonAsync("/classify", new { text = text, candidate_labels = candidateLabels });
return (await response.Content.ReadFromJsonAsync<string>())!;
var response = await http.PostAsJsonAsync("/classify",
new { text, candidate_labels = candidateLabels });
var label = await response.Content.ReadFromJsonAsync<string>();
return label;
}
}

0 comments on commit 7159738

Please sign in to comment.