Yash Worlikar commited on
Commit
920638b
·
1 Parent(s): 09ee77e

Updated Missing Keys Handling

Browse files
Components/Pages/Home.razor CHANGED
@@ -8,7 +8,11 @@
8
  <PageTitle> Food Health Checker</PageTitle>
9
 
10
  <div class="container mt-2">
11
- <h3 class="card-title mb-2 fw-bold">AI Food Health Checker</h3>
 
 
 
 
12
  <div class="row justify-content-center ">
13
  <div class="col-xl-12">
14
  @if (!string.IsNullOrEmpty(errorMessage))
@@ -95,6 +99,7 @@
95
 
96
  public string Ingredients { get; set; } = string.Empty;
97
  public string Result { get; set; } = string.Empty;
 
98
 
99
  [Inject]
100
  public MarkdownPipeline pipeline { get; set; } = default!;
@@ -102,6 +107,17 @@
102
  public FoodCheckerService _foodCheckerService { get; set; } = default!;
103
  [Inject]
104
  private NavigationManager Navigation { get; set; } = default!;
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  private bool isProcessingIngredients = false;
107
  private bool isProcessingResponse = false;
 
8
  <PageTitle> Food Health Checker</PageTitle>
9
 
10
  <div class="container mt-2">
11
+ <div style="display: flex; justify-content: space-between; ">
12
+ <h3 class="card-title mb-2 fw-bold">AI Food Health Checker</h3>
13
+ <a class="card-title mb-2 fw-bold btn btn-dark" href="@duplicateSpace" target="_blank">Duplicate this space</a>
14
+ </div>
15
+
16
  <div class="row justify-content-center ">
17
  <div class="col-xl-12">
18
  @if (!string.IsNullOrEmpty(errorMessage))
 
99
 
100
  public string Ingredients { get; set; } = string.Empty;
101
  public string Result { get; set; } = string.Empty;
102
+ public string duplicateSpace { get; set; } = string.Empty;
103
 
104
  [Inject]
105
  public MarkdownPipeline pipeline { get; set; } = default!;
 
107
  public FoodCheckerService _foodCheckerService { get; set; } = default!;
108
  [Inject]
109
  private NavigationManager Navigation { get; set; } = default!;
110
+ [Inject]
111
+ private IConfiguration Config { get; set; } = default;
112
+
113
+ protected override void OnInitialized()
114
+ {
115
+ duplicateSpace = Config.GetValue<string>("HFDuplicateSpace") ?? string.Empty;
116
+ if (!_foodCheckerService.IsValid())
117
+ {
118
+ errorMessage = "API keys missing. Duplicate this space to add missing keys";
119
+ }
120
+ }
121
 
122
  private bool isProcessingIngredients = false;
123
  private bool isProcessingResponse = false;
FoodCheckerService.cs CHANGED
@@ -8,6 +8,7 @@ namespace FoodHealthChecker
8
  public class FoodCheckerService
9
  {
10
  private readonly Kernel _kernel;
 
11
  private readonly FoodCheckerPlugin _foodCheckerPlugin;
12
  public FoodCheckerService(IConfiguration config, FoodCheckerPlugin foodCheckerPlugin)
13
  {
@@ -20,14 +21,12 @@ namespace FoodHealthChecker
20
  if (azureOptions != null && azureOptions.isValid())
21
  {
22
  kernelBuilder.AddAzureOpenAIChatCompletion(azureOptions.DeploymentName, azureOptions.Endpoint, azureOptions.ApiKey);
 
23
  }
24
  else if (oaiOptions != null && oaiOptions.isValid())
25
  {
26
  kernelBuilder.AddOpenAIChatCompletion(oaiOptions.ModelID, oaiOptions.ApiKey);
27
- }
28
- else
29
- {
30
- throw new ArgumentException("Missing AI service configuration");
31
  }
32
  var kernel = kernelBuilder.Build();
33
  //TODO - implement
@@ -37,6 +36,10 @@ namespace FoodHealthChecker
37
  _kernel = kernel;
38
  }
39
 
 
 
 
 
40
  /// <summary>
41
  ///
42
  /// </summary>
@@ -58,7 +61,7 @@ namespace FoodHealthChecker
58
  /// <returns></returns>
59
  /// Inconsistant behaviour https://github.com/microsoft/semantic-kernel/pull/6319
60
  /// Related to https://github.com/dotnet/runtime/issues/96544
61
- public IAsyncEnumerable<string> GetIngredirentsAsync(ReadOnlyMemory<byte> imageData,string fileName, CancellationToken cancellationToken = default)
62
  {
63
 
64
  var imageDataUrl = new ImageContent(imageData) { MimeType = GetMimeType(fileName) }.ToString();
@@ -72,7 +75,7 @@ namespace FoodHealthChecker
72
  /// <param name="imageUrl"></param>
73
  /// <param name="cancellationToken"></param>
74
  /// <returns></returns>
75
- public IAsyncEnumerable<string> GetIngredirentsAsync(string imageUrl,CancellationToken cancellationToken = default)
76
  {
77
  return _foodCheckerPlugin.GetIngredientsAsync(imageUrl, _kernel, cancellationToken);
78
  }
 
8
  public class FoodCheckerService
9
  {
10
  private readonly Kernel _kernel;
11
+ private bool isValid = false;
12
  private readonly FoodCheckerPlugin _foodCheckerPlugin;
13
  public FoodCheckerService(IConfiguration config, FoodCheckerPlugin foodCheckerPlugin)
14
  {
 
21
  if (azureOptions != null && azureOptions.isValid())
22
  {
23
  kernelBuilder.AddAzureOpenAIChatCompletion(azureOptions.DeploymentName, azureOptions.Endpoint, azureOptions.ApiKey);
24
+ isValid = true;
25
  }
26
  else if (oaiOptions != null && oaiOptions.isValid())
27
  {
28
  kernelBuilder.AddOpenAIChatCompletion(oaiOptions.ModelID, oaiOptions.ApiKey);
29
+ isValid = true;
 
 
 
30
  }
31
  var kernel = kernelBuilder.Build();
32
  //TODO - implement
 
36
  _kernel = kernel;
37
  }
38
 
39
+ public bool IsValid()
40
+ {
41
+ return isValid;
42
+ }
43
  /// <summary>
44
  ///
45
  /// </summary>
 
61
  /// <returns></returns>
62
  /// Inconsistant behaviour https://github.com/microsoft/semantic-kernel/pull/6319
63
  /// Related to https://github.com/dotnet/runtime/issues/96544
64
+ public IAsyncEnumerable<string> GetIngredirentsAsync(ReadOnlyMemory<byte> imageData, string fileName, CancellationToken cancellationToken = default)
65
  {
66
 
67
  var imageDataUrl = new ImageContent(imageData) { MimeType = GetMimeType(fileName) }.ToString();
 
75
  /// <param name="imageUrl"></param>
76
  /// <param name="cancellationToken"></param>
77
  /// <returns></returns>
78
+ public IAsyncEnumerable<string> GetIngredirentsAsync(string imageUrl, CancellationToken cancellationToken = default)
79
  {
80
  return _foodCheckerPlugin.GetIngredientsAsync(imageUrl, _kernel, cancellationToken);
81
  }
appsettings.json CHANGED
@@ -14,5 +14,6 @@
14
  "OpenAI": {
15
  "ModelId": "",
16
  "ApiKey": ""
17
- }
 
18
  }
 
14
  "OpenAI": {
15
  "ModelId": "",
16
  "ApiKey": ""
17
+ },
18
+ "HFDuplicateSpace":""
19
  }