Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@
/// <summary>
/// System prompt to send with user prompts to instruct the model for chat session
/// </summary>
private readonly string _systemPrompt = @"

Check warning on line 37 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Package Restore and Build

The field 'SemanticKernelService._systemPrompt' is assigned but its value is never used

Check warning on line 37 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Package Restore and Build

The field 'SemanticKernelService._systemPrompt' is assigned but its value is never used

Check failure on line 37 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The field 'SemanticKernelService._systemPrompt' is assigned but its value is never used

Check failure on line 37 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The field 'SemanticKernelService._systemPrompt' is assigned but its value is never used
You are an AI assistant that helps people find information.
Provide concise answers that are polite and professional.";

/// <summary>
/// System prompt to send with user prompts as a Retail AI Assistant for chat session
/// </summary>
private readonly string _systemPromptRetailAssistant = @"";

Check warning on line 44 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Package Restore and Build

The field 'SemanticKernelService._systemPromptRetailAssistant' is assigned but its value is never used

Check warning on line 44 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Package Restore and Build

The field 'SemanticKernelService._systemPromptRetailAssistant' is assigned but its value is never used

Check failure on line 44 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The field 'SemanticKernelService._systemPromptRetailAssistant' is assigned but its value is never used

Check failure on line 44 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The field 'SemanticKernelService._systemPromptRetailAssistant' is assigned but its value is never used

/// <summary>
/// System prompt to send with user prompts to instruct the model for summarization
/// </summary>
private readonly string _summarizePrompt = @"

Check warning on line 49 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Package Restore and Build

The field 'SemanticKernelService._summarizePrompt' is assigned but its value is never used

Check warning on line 49 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Package Restore and Build

The field 'SemanticKernelService._summarizePrompt' is assigned but its value is never used

Check failure on line 49 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The field 'SemanticKernelService._summarizePrompt' is assigned but its value is never used

Check failure on line 49 in src/cosmos-copilot.WebApp/Services/SemanticKernelService.cs

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The field 'SemanticKernelService._summarizePrompt' is assigned but its value is never used
Summarize this text. One to three words maximum length.
Plain text only. No punctuation, markup or tags.";

Expand Down Expand Up @@ -252,12 +252,49 @@
string json = "";
string jsonFilePath = _productDataSourceURI;
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(jsonFilePath);
if(response.IsSuccessStatusCode)

try
{
HttpResponseMessage response = await client.GetAsync(jsonFilePath);
if(response.IsSuccessStatusCode)
{
json = await response.Content.ReadAsStringAsync();
}
else
{
Console.WriteLine($"Failed to fetch product data from {jsonFilePath}. Status code: {response.StatusCode}");
return;
}
}
catch (Exception ex)
{
Console.WriteLine($"Error fetching product data from {jsonFilePath}: {ex.Message}");
return;
}

// Validate that we have JSON content before attempting to deserialize
if (string.IsNullOrWhiteSpace(json))
{
Console.WriteLine($"Product data source returned empty content from {jsonFilePath}");
return;
}

List<Product>? products = null;
try
{
products = JsonSerializer.Deserialize<List<Product>>(json);
}
catch (JsonException ex)
{
Console.WriteLine($"Error deserializing product data: {ex.Message}");
return;
}

if (products == null || products.Count == 0)
{
json = await response.Content.ReadAsStringAsync();
Console.WriteLine("No products found in the data source");
return;
}
List<Product> products = JsonSerializer.Deserialize<List<Product>>(json)!;

foreach (var product in products)
{
Expand Down