Skip to content

Commit

Permalink
better response
Browse files Browse the repository at this point in the history
  • Loading branch information
MattJeanes committed Jul 18, 2024
1 parent 47db257 commit 23bb928
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 5 additions & 5 deletions HomeAutomation.Web/Controllers/PackageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public async Task<PackageResponse> GetPackage()
{
var openAI = new OpenAIAPI(new APIAuthentication(_options.OpenAIApiKey));

foreach (var url in _options.ImageUrls)
foreach (var location in _options.Locations)
{
var image = await _httpClient.GetAsync(url);
var imageBytes = await image.Content.ReadAsByteArrayAsync();
var imageResponse = await _httpClient.GetAsync(location.ImageUrl);
var imageBytes = await imageResponse.Content.ReadAsByteArrayAsync();

var chatRequest = new ChatRequest
{
Expand Down Expand Up @@ -64,10 +64,10 @@ public async Task<PackageResponse> GetPackage()
var responseText = response?.Choices?.FirstOrDefault()?.Message.TextContent;
if (bool.Parse(responseText))
{
return new PackageResponse(true);
return new PackageResponse(location.Id, true);
}
}

return new PackageResponse(false);
return new PackageResponse(null, false);
}
}
8 changes: 7 additions & 1 deletion HomeAutomation.Web/Data/PackageOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

public class PackageOptions
{
public class Location
{
public string Id { get; set; }
public string ImageUrl { get; set; }
}

public string OpenAIApiKey { get; set; }
public List<string> ImageUrls { get; set; }
public List<Location> Locations { get; set; }
}
8 changes: 5 additions & 3 deletions HomeAutomation.Web/Data/PackageResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

public class PackageResponse
{
public PackageResponse(bool package)
public PackageResponse(string locationId, bool detected)
{
Package = package;
LocationId = locationId;
Detected = detected;
}

public bool Package { get; set; }
public string LocationId { get; set; }
public bool Detected { get; set; }
}

0 comments on commit 23bb928

Please sign in to comment.