Skip to content

Commit

Permalink
Handle nullable types and improve null value handling and switched to…
Browse files Browse the repository at this point in the history
… 3.5turbo
  • Loading branch information
madebygps committed Sep 10, 2024
1 parent 331104d commit e7f8eba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
13 changes: 7 additions & 6 deletions azure-project-generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
var config = context.Configuration;
// Initialize Azure OpenAI client
string keyFromEnvironment = config["AZURE_OPENAI_API_KEY"];
string endpointFromEnvironment = config["AZURE_OPENAI_API_ENDPOINT"];
string embeddingsDeployment = config["EMBEDDINGS_DEPLOYMENT"];
string azureWebJobsStorage = config["AzureWebJobsStorage"];
string completionsDeployment = config["COMPLETIONS_DEPLOYMENT"];
string? keyFromEnvironment = config["AZURE_OPENAI_API_KEY"];
string? endpointFromEnvironment = config["AZURE_OPENAI_API_ENDPOINT"];
string? embeddingsDeployment = config["EMBEDDINGS_DEPLOYMENT"];
string? azureWebJobsStorage = config["AzureWebJobsStorage"];
string? completionsDeployment = config["COMPLETIONS_DEPLOYMENT"];
if (string.IsNullOrEmpty(keyFromEnvironment) || string.IsNullOrEmpty(endpointFromEnvironment) || string.IsNullOrEmpty(embeddingsDeployment))
{
throw new InvalidOperationException("Required Azure OpenAI configuration is missing.");
}
// Register BlobServiceClient as a singleton
services.AddSingleton(new BlobServiceClient(azureWebJobsStorage));
Expand Down
19 changes: 9 additions & 10 deletions azure-project-generator/models/CloudProjectIdea.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,15 +9,13 @@ namespace azure_project_generator.models
{
public class CloudProjectIdea
{
public string Title { get; set; }
public string Description { get; set; }
public List<string> Steps { get; set; }
public List<string> Resources { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public List<string>? Steps { get; set; }

// Constructor to initialize Resources
public CloudProjectIdea()
{
Resources = new List<string>();
}
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<string> Resources { get; set; } = new List<string>();


}
}
11 changes: 10 additions & 1 deletion azure-project-generator/services/ContentGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ The project should focus on key technical steps without any subjective descripti

// deserialize to CloudProjectIdea object

CloudProjectIdea cloudProjectIdea = JsonConvert.DeserializeObject<CloudProjectIdea>(cleanedJsonContent);
CloudProjectIdea? cloudProjectIdea = JsonConvert.DeserializeObject<CloudProjectIdea>(cleanedJsonContent);
if (cloudProjectIdea == null)
{
_logger.LogError("Deserialization returned null for project idea.");
throw new Exception("Failed to deserialize project idea.");
}
// Ensure Steps is initialized if it's null
cloudProjectIdea.Steps ??= new List<string>();

foreach (var service in services)
{
// Properly encode the skill, topic, and service
Expand All @@ -102,6 +110,7 @@ The project should focus on key technical steps without any subjective descripti
cloudProjectIdea.Resources.Add($"https://learn.microsoft.com/search/?terms={encodedTopic}%20{encodedService}&category=Training");
}


string jsonString = JsonConvert.SerializeObject(cloudProjectIdea);

return jsonString;
Expand Down

0 comments on commit e7f8eba

Please sign in to comment.