Skip to content

Commit f84b6fd

Browse files
authored
Merge pull request #12 from learntocloud/generatesmallerprojects
refactored to generate projects per skill
2 parents 5dea23d + d98e8a3 commit f84b6fd

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

azure-project-generator/GenerateProject.cs

Lines changed: 6 additions & 20 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
@@ -24,23 +20,16 @@ public GenerateProject(ILogger<GenerateProject> logger, ContentGenerationService
2420
}
2521

2622
[Function("GenerateProject")]
27-
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req, string certificationCode,
28-
23+
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req, string certificationCode, string skillName,
2924
[CosmosDBInput(Connection = "CosmosDBConnection")] CosmosClient client)
3025
{
3126
var response = req.CreateResponse(HttpStatusCode.OK);
3227
_logger.LogInformation("C# HTTP trigger function processed a request.");
3328

34-
var query = new QueryDefinition("SELECT * FROM c WHERE c.certificationCode = @certificationCode")
35-
.WithParameter("@certificationCode", certificationCode);
36-
37-
var iterator = client.GetContainer("AzureCertDB", "projectpromptvectors")
38-
.GetItemQueryIterator<CertificationProjectPromptDocument>(query);
39-
40-
41-
CertificationProjectPromptDocument certificationProjectPromptDocument = iterator.ReadNextAsync().Result.FirstOrDefault();
42-
43-
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;
4433

4534
var queryDef = new QueryDefinition
4635
(query: $"SELECT c.serviceName, c.skillName, c.topicName, VectorDistance(c.contextVector,@embedding) " +
@@ -51,20 +40,17 @@ public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function
5140
client.GetContainer("AzureCertDB", "certvectors").GetItemQueryIterator<CertificationService>(queryDef);
5241

5342
string projectServices = "";
54-
string projectSkills = "";
5543

5644
while (resultSetIterator.HasMoreResults)
5745
{
5846
FeedResponse<CertificationService> feedResponse = resultSetIterator.ReadNextAsync().Result;
5947
foreach (var item in feedResponse)
6048
{
6149
projectServices += item.ServiceName + " ";
62-
projectSkills += item.SkillName + " ";
63-
6450
}
6551
}
6652

67-
string cloudProjectIdea = await _contentGenerationService.GenerateProjectIdeaAsync(projectSkills, projectServices);
53+
string cloudProjectIdea = await _contentGenerationService.GenerateProjectIdeaAsync(projectServices, skillName);
6854

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

azure-project-generator/ProcessCertDataFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public async Task<CertificationProjectPromptOutput> Run([BlobTrigger("certdata/{
7676
}
7777
}
7878
}
79-
8079

80+
string contextSentence = _contentGenerationService.GenerateCertDataContextSentence(certification);
8181

82-
float[] cerificationCodeVector = await _contentGenerationService.GenerateEmbeddingsAsync(certification.CertificationCode);
82+
float[] cerificationCodeVector = await _contentGenerationService.GenerateEmbeddingsAsync(contextSentence);
8383

8484
var certificationDocument = CreateCertificationProjectPromptDocument(certification, cerificationCodeVector);
8585

azure-project-generator/services/ContentGenerationService.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
using Microsoft.Extensions.Logging;
44
using OpenAI.Embeddings;
55
using OpenAI.Chat;
6-
using System.Text.Json;
7-
using Microsoft.AspNetCore.Mvc;
8-
using Newtonsoft.Json;
96
using Newtonsoft.Json.Linq;
107

118
namespace azure_project_generator.services
@@ -26,7 +23,8 @@ public ContentGenerationService(ILogger<ContentGenerationService> logger, Embedd
2623
public string GenerateCertServiceContextSentence(CertificationService data) =>
2724
$"The {data.CertificationCode} {data.CertificationName} certification includes the skill of {data.SkillName}. Within this skill, there is a focus on the topic of {data.TopicName}, particularly through the use of the service {data.ServiceName}.";
2825

29-
26+
public string GenerateCertDataContextSentence(Certification data) =>
27+
$"The {data.CertificationCode} {data.CertificationName} certification includes the following skills: {string.Join(", ", data.SkillsMeasured.Select(s => s.Name))}.";
3028
public async Task<float[]> GenerateEmbeddingsAsync(string content)
3129
{
3230
try
@@ -48,12 +46,12 @@ public async Task<float[]> GenerateEmbeddingsAsync(string content)
4846
}
4947
}
5048

51-
public async Task<string> GenerateProjectIdeaAsync(string skills, string services)
49+
public async Task<string> GenerateProjectIdeaAsync(string services, string skill)
5250
{
5351
string userPrompt = $@"You are an expert cloud architect.
5452
Please generate a detailed project idea for a beginner-friendly weekend cloud solution
55-
based on the following Azure certification skills: {skills}.
56-
The project should utilize the following services: {services}.
53+
based on the following Azure certification skill: {skill}.
54+
The project should utilize the ONLY following services: {services}.
5755
The project should be small in scale, achievable over a weekend, and have a fun, creative name. Suitable for beginners. Cheap to run.
5856
The response must be formatted as valid JSON and include only the following fields:
5957
{{
@@ -68,7 +66,7 @@ public async Task<string> GenerateProjectIdeaAsync(string skills, string service
6866
""Step 5: Description of the fifth step""
6967
]
7068
}}
71-
Ensure that the project idea is practical, aligned with beginner-level skills, and leverages best practices in Azure architecture.";
69+
Ensure that the project idea is practical, aligned with beginner-level skills, and leverages best practices in Azure architecture. Small in scope";
7270

7371
try
7472
{

0 commit comments

Comments
 (0)