Skip to content

Commit d98e8a3

Browse files
committed
Refactor project idea generation and clean up code
Cleaned up `using` directives and adjusted `namespace` declaration in `GenerateProject.cs` for better readability. Refactored CosmosDB query logic to use embeddings generated from `certificationCode` and `skillName`, and updated the loop to concatenate service names into `projectServices`. Modified `_contentGenerationService.GenerateProjectIdeaAsync` to use `projectServices` and `skillName`. Updated `GenerateProjectIdeaAsync` method in `ContentGenerationService.cs` to reflect new parameters and prompt structure. Ensured response format remains valid JSON.
1 parent 9bc7681 commit d98e8a3

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

azure-project-generator/GenerateProject.cs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
using Azure;
21
using azure_project_generator.models;
32
using azure_project_generator.services;
4-
using Microsoft.AspNetCore.Http;
5-
using Microsoft.AspNetCore.Mvc;
63
using Microsoft.Azure.Cosmos;
74
using Microsoft.Azure.Functions.Worker;
85
using Microsoft.Azure.Functions.Worker.Http;
96
using Microsoft.Extensions.Logging;
10-
using Newtonsoft.Json;
117
using System.Net;
128

139
namespace azure_project_generator
@@ -30,16 +26,10 @@ public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function
3026
var response = req.CreateResponse(HttpStatusCode.OK);
3127
_logger.LogInformation("C# HTTP trigger function processed a request.");
3228

33-
var query = new QueryDefinition("SELECT * FROM c WHERE c.certificationCode = @certificationCode")
34-
.WithParameter("@certificationCode", certificationCode);
35-
36-
var iterator = client.GetContainer("AzureCertDB", "projectpromptvectors")
37-
.GetItemQueryIterator<CertificationProjectPromptDocument>(query);
38-
39-
40-
CertificationProjectPromptDocument certificationProjectPromptDocument = iterator.ReadNextAsync().Result.FirstOrDefault();
41-
42-
float[] projectPromptVector = certificationProjectPromptDocument.ProjectPromptVector;
29+
30+
string projectPrompt = "I need a project idea for the certification exam " + certificationCode + " for the skill " + skillName;
31+
32+
float[] projectPromptVector = _contentGenerationService.GenerateEmbeddingsAsync(projectPrompt).Result;
4333

4434
var queryDef = new QueryDefinition
4535
(query: $"SELECT c.serviceName, c.skillName, c.topicName, VectorDistance(c.contextVector,@embedding) " +
@@ -49,21 +39,18 @@ public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function
4939
using FeedIterator<CertificationService> resultSetIterator =
5040
client.GetContainer("AzureCertDB", "certvectors").GetItemQueryIterator<CertificationService>(queryDef);
5141

52-
string projectService = "";
53-
string projectSkill = "";
54-
string topicName = "";
55-
56-
57-
CertificationService feedResponse = resultSetIterator.ReadNextAsync().Result.FirstOrDefault();
58-
59-
projectService += feedResponse.ServiceName + " ";
60-
projectSkill += feedResponse.SkillName + " ";
61-
topicName += feedResponse.TopicName + " ";
62-
63-
42+
string projectServices = "";
6443

44+
while (resultSetIterator.HasMoreResults)
45+
{
46+
FeedResponse<CertificationService> feedResponse = resultSetIterator.ReadNextAsync().Result;
47+
foreach (var item in feedResponse)
48+
{
49+
projectServices += item.ServiceName + " ";
50+
}
51+
}
6552

66-
string cloudProjectIdea = await _contentGenerationService.GenerateProjectIdeaAsync(projectSkill, projectService, topicName);
53+
string cloudProjectIdea = await _contentGenerationService.GenerateProjectIdeaAsync(projectServices, skillName);
6754

6855
response.Headers.Add("Content-Type", "application/json");
6956
await response.WriteStringAsync(cloudProjectIdea);

azure-project-generator/services/ContentGenerationService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public async Task<float[]> GenerateEmbeddingsAsync(string content)
4646
}
4747
}
4848

49-
public async Task<string> GenerateProjectIdeaAsync(string skill, string service, string topic)
49+
public async Task<string> GenerateProjectIdeaAsync(string services, string skill)
5050
{
5151
string userPrompt = $@"You are an expert cloud architect.
5252
Please generate a detailed project idea for a beginner-friendly weekend cloud solution
53-
based on the following Azure certification skill: {skill} and topic: {topic}.
54-
The project should utilize the ONLY following services: {service}.
53+
based on the following Azure certification skill: {skill}.
54+
The project should utilize the ONLY following services: {services}.
5555
The project should be small in scale, achievable over a weekend, and have a fun, creative name. Suitable for beginners. Cheap to run.
5656
The response must be formatted as valid JSON and include only the following fields:
5757
{{

0 commit comments

Comments
 (0)