Skip to content

Commit e88df72

Browse files
authored
Merge pull request #8 from learntocloud/promptcatalog
Add new services and models, update project structure
2 parents a2ac9da + 88f73ea commit e88df72

14 files changed

+393
-181
lines changed

azure-project-generator.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.11.35219.272
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "azure-project-generator", "azure-project-generator\azure-project-generator.csproj", "{C773FBC4-275D-4DE4-86C9-D0FBB0F20F29}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "azure-project-generator", "azure-project-generator\azure-project-generator.csproj", "{C773FBC4-275D-4DE4-86C9-D0FBB0F20F29}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using azure_project_generator.models;
2+
using azure_project_generator.services;
3+
using Microsoft.Azure.Functions.Worker;
4+
using Microsoft.Extensions.Logging;
5+
using Newtonsoft.Json;
6+
using OpenAI.Embeddings;
7+
8+
namespace azure_project_generator
9+
{
10+
public class ProcessCertPromptFile
11+
{
12+
private readonly ILogger<ProcessCertServiceFile> _logger;
13+
private readonly EmbeddingClient _embeddingClient;
14+
private readonly JsonValidationService _jsonValidationService;
15+
private readonly ContentGenerationService _contentGenerationService;
16+
17+
public ProcessCertPromptFile(ILogger<ProcessCertServiceFile> logger,
18+
EmbeddingClient embeddingClient,
19+
JsonValidationService jsonValidationService,
20+
ContentGenerationService contentGenerationService)
21+
{
22+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
23+
_embeddingClient = embeddingClient ?? throw new ArgumentNullException(nameof(embeddingClient));
24+
_jsonValidationService = jsonValidationService ?? throw new ArgumentNullException(nameof(jsonValidationService));
25+
_contentGenerationService = contentGenerationService ?? throw new ArgumentNullException(nameof(contentGenerationService));
26+
}
27+
28+
[Function(nameof(ProcessCertPromptFile))]
29+
public async Task<CertificationProjectPromptOutput> Run([BlobTrigger("certdata/{name}", Connection = "AzureWebJobsStorage")] string content, string name)
30+
{
31+
32+
if (string.IsNullOrWhiteSpace(content))
33+
{
34+
_logger.LogError("Blob content is empty or whitespace.");
35+
return new CertificationProjectPromptOutput { Document = null, ArchivedContent = null };
36+
}
37+
38+
if (!_jsonValidationService.ValidateJsonContent<Certification>(content))
39+
{
40+
return new CertificationProjectPromptOutput { Document = null, ArchivedContent = null };
41+
}
42+
43+
var certification = JsonConvert.DeserializeObject<Certification>(content);
44+
if (certification == null)
45+
{
46+
_logger.LogError("Failed to deserialize content to MappedService.");
47+
return new CertificationProjectPromptOutput { Document = null, ArchivedContent = null };
48+
}
49+
50+
string contextSentence = _contentGenerationService.GenerateCertDataContextSentence(certification);
51+
float[] contentVector = await _contentGenerationService.GenerateEmbeddingsAsync(contextSentence);
52+
53+
var certificationDocument = CreateCertificationProjectPromptDocument(certification, contextSentence, contentVector);
54+
55+
_logger.LogInformation("Document created successfully.");
56+
_logger.LogInformation($"Archiving blob: {name}");
57+
58+
59+
return new CertificationProjectPromptOutput
60+
{
61+
Document = certificationDocument,
62+
ArchivedContent = content
63+
};
64+
}
65+
66+
private CertificationProjectPromptDocument CreateCertificationProjectPromptDocument(Certification data, string contextSentence, float[] contentVector) =>
67+
new CertificationProjectPromptDocument
68+
{
69+
Id = Guid.NewGuid().ToString(),
70+
CertificationCode = data.CertificationCode,
71+
CertificationName = data.CertificationName,
72+
ProjectPrompt = contextSentence,
73+
ProjectPromptVector = contentVector
74+
};
75+
}
76+
}
77+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using azure_project_generator.models;
2+
using azure_project_generator.services;
3+
using Microsoft.Azure.Functions.Worker;
4+
using Microsoft.Extensions.Logging;
5+
using Newtonsoft.Json;
6+
using OpenAI.Embeddings;
7+
8+
namespace azure_project_generator
9+
{
10+
public class ProcessCertServiceFile
11+
{
12+
private readonly ILogger<ProcessCertServiceFile> _logger;
13+
private readonly EmbeddingClient _embeddingClient;
14+
private readonly JsonValidationService _jsonValidationService;
15+
private readonly ContentGenerationService _contentGenerationService;
16+
17+
public ProcessCertServiceFile(ILogger<ProcessCertServiceFile> logger,
18+
EmbeddingClient embeddingClient,
19+
JsonValidationService jsonValidationService,
20+
ContentGenerationService contentGenerationService)
21+
{
22+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
23+
_embeddingClient = embeddingClient ?? throw new ArgumentNullException(nameof(embeddingClient));
24+
_jsonValidationService = jsonValidationService ?? throw new ArgumentNullException(nameof(jsonValidationService));
25+
_contentGenerationService = contentGenerationService ?? throw new ArgumentNullException(nameof(contentGenerationService));
26+
}
27+
28+
[Function(nameof(ProcessCertServiceFile))]
29+
public async Task<CertificationServiceOutput> Run(
30+
[BlobTrigger("certservice/{name}", Connection = "AzureWebJobsStorage")] string content,
31+
string name)
32+
{
33+
_logger.LogInformation($"Processing blob: {name}");
34+
35+
if (string.IsNullOrWhiteSpace(content))
36+
{
37+
_logger.LogError("Blob content is empty or whitespace.");
38+
return new CertificationServiceOutput { Document = null, ArchivedContent = null };
39+
}
40+
41+
if (!_jsonValidationService.ValidateJsonContent<MappedService>(content))
42+
{
43+
return new CertificationServiceOutput { Document = null, ArchivedContent = null };
44+
}
45+
46+
var mappedServiceData = JsonConvert.DeserializeObject<MappedService>(content);
47+
if (mappedServiceData == null)
48+
{
49+
_logger.LogError("Failed to deserialize content to MappedService.");
50+
return new CertificationServiceOutput { Document = null, ArchivedContent = null };
51+
}
52+
53+
string contextSentence = _contentGenerationService.GenerateCertServiceContextSentence(mappedServiceData);
54+
float[] contentVector = await _contentGenerationService.GenerateEmbeddingsAsync(contextSentence);
55+
56+
var certServiceDocument = CreateCertServiceDocument(mappedServiceData, contextSentence, contentVector);
57+
58+
_logger.LogInformation("Document created successfully.");
59+
_logger.LogInformation($"Archiving blob: {name}");
60+
61+
62+
return new CertificationServiceOutput
63+
{
64+
Document = certServiceDocument,
65+
ArchivedContent = content
66+
};
67+
}
68+
69+
// Other methods remain unchanged
70+
71+
private CertificationServiceDocument CreateCertServiceDocument(MappedService data, string contextSentence, float[] contentVector) =>
72+
new CertificationServiceDocument
73+
{
74+
Id = Guid.NewGuid().ToString(),
75+
CertificationServiceKey = $"{data.CertificationCode}-{data.ServiceName}",
76+
CertificationCode = data.CertificationCode,
77+
CertificationName = data.CertificationName,
78+
SkillName = data.SkillName,
79+
TopicName = data.TopicName,
80+
ServiceName = data.ServiceName,
81+
ContextSentence = contextSentence,
82+
ContextVector = contentVector
83+
};
84+
}
85+
}

azure-project-generator/ProcessFile.cs

Lines changed: 0 additions & 156 deletions
This file was deleted.

azure-project-generator/Program.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Azure;
22
using Azure.AI.OpenAI;
3+
using azure_project_generator.services;
34
using Microsoft.Azure.Functions.Worker;
4-
using Microsoft.Extensions.Configuration;
55
using Microsoft.Extensions.DependencyInjection;
66
using Microsoft.Extensions.Hosting;
77

@@ -31,7 +31,13 @@
3131

3232
// Register EmbeddingClient as a singleton
3333
services.AddSingleton(azureClient.GetEmbeddingClient(embeddingsDeployment));
34+
35+
// Register JsonValidationService
36+
services.AddSingleton<JsonValidationService>();
37+
38+
// Register ContentGenerationService
39+
services.AddSingleton<ContentGenerationService>();
3440
})
3541
.Build();
3642

37-
host.Run();
43+
host.Run();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Newtonsoft.Json;
2+
3+
namespace azure_project_generator.models
4+
{
5+
6+
public class Certification
7+
{
8+
[JsonProperty("certificationCode")]
9+
public string CertificationCode { get; set; }
10+
[JsonProperty("certificationName")]
11+
public string CertificationName { get; set; }
12+
[JsonProperty("skillsMeasured")]
13+
public List<Skill> SkillsMeasured { get; set; }
14+
}
15+
16+
public class Skill
17+
{
18+
[JsonProperty("name")]
19+
20+
public string Name { get; set; }
21+
[JsonProperty("percentage")]
22+
public string Percentage { get; set; }
23+
[JsonProperty("topics")]
24+
public List<Topic> Topics { get; set; }
25+
}
26+
27+
public class Topic
28+
{
29+
[JsonProperty("topicName")]
30+
public string TopicName { get; set; }
31+
[JsonProperty("services")]
32+
public List<string> Services { get; set; }
33+
}
34+
35+
36+
}

0 commit comments

Comments
 (0)