Skip to content

Commit a35c12b

Browse files
committed
renamed files
1 parent 21c5300 commit a35c12b

File tree

2 files changed

+89
-5
lines changed

2 files changed

+89
-5
lines changed

azure-project-generator/ProcessCertDataFile.cs renamed to azure-project-generator/CertificationDataFileProcessor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1+
using Azure.Storage.Blobs;
12
using azure_project_generator.models;
23
using azure_project_generator.services;
34
using Microsoft.Azure.Functions.Worker;
45
using Microsoft.Extensions.Logging;
56
using Newtonsoft.Json;
67
using OpenAI.Embeddings;
7-
using Azure.Storage.Blobs;
88
using System.Text;
99

1010
namespace azure_project_generator
1111
{
12-
public class ProcessCertDataFile
12+
public class CertificationDataFileProcessor
1313
{
14-
private readonly ILogger<ProcessCertServiceFile> _logger;
14+
private readonly ILogger<CertificationServiceFileProcessor> _logger;
1515
private readonly EmbeddingClient _embeddingClient;
1616
private readonly JsonValidationService _jsonValidationService;
1717
private readonly ContentGenerationService _contentGenerationService;
1818
private readonly BlobServiceClient _blobServiceClient;
1919

20-
public ProcessCertDataFile(ILogger<ProcessCertServiceFile> logger,
20+
public CertificationDataFileProcessor(ILogger<CertificationServiceFileProcessor> logger,
2121
EmbeddingClient embeddingClient,
2222
JsonValidationService jsonValidationService,
2323
ContentGenerationService contentGenerationService, BlobServiceClient blobServiceClient)
@@ -29,7 +29,7 @@ public ProcessCertDataFile(ILogger<ProcessCertServiceFile> logger,
2929
_blobServiceClient = blobServiceClient ?? throw new ArgumentNullException(nameof(blobServiceClient));
3030
}
3131

32-
[Function(nameof(ProcessCertDataFile))]
32+
[Function(nameof(CertificationDataFileProcessor))]
3333
public async Task<CertificationProjectPromptOutput> Run([BlobTrigger("certdata/{name}", Connection = "AzureWebJobsStorage")] string content, string name)
3434
{
3535

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 CertificationServiceFileProcessor
11+
{
12+
private readonly ILogger<CertificationServiceFileProcessor> _logger;
13+
private readonly EmbeddingClient _embeddingClient;
14+
private readonly JsonValidationService _jsonValidationService;
15+
private readonly ContentGenerationService _contentGenerationService;
16+
17+
public CertificationServiceFileProcessor(ILogger<CertificationServiceFileProcessor> 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(CertificationServiceFileProcessor))]
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};
39+
}
40+
41+
if (!_jsonValidationService.ValidateJsonContent<CertificationService>(content))
42+
{
43+
return new CertificationServiceOutput { Document = null };
44+
}
45+
46+
var mappedServiceData = JsonConvert.DeserializeObject<CertificationService>(content);
47+
if (mappedServiceData == null)
48+
{
49+
_logger.LogError("Failed to deserialize content to MappedService.");
50+
return new CertificationServiceOutput { Document = 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+
66+
};
67+
}
68+
69+
70+
private CertificationServiceDocument CreateCertServiceDocument(CertificationService data, string contextSentence, float[] contentVector) =>
71+
new CertificationServiceDocument
72+
{
73+
Id = Guid.NewGuid().ToString(),
74+
CertificationServiceKey = $"{data.CertificationCode}-{data.ServiceName}",
75+
CertificationCode = data.CertificationCode,
76+
CertificationName = data.CertificationName,
77+
SkillName = data.SkillName,
78+
TopicName = data.TopicName,
79+
ServiceName = data.ServiceName,
80+
ContextSentence = contextSentence,
81+
ContextVector = contentVector
82+
};
83+
}
84+
}

0 commit comments

Comments
 (0)