Skip to content

Commit 21c5300

Browse files
authored
Merge pull request #21 from learntocloud/removeafterinset
Integrate Azure Blob Storage and clean up unused usings
2 parents e7f8eba + bfd0bac commit 21c5300

File tree

5 files changed

+50
-33
lines changed

5 files changed

+50
-33
lines changed

azure-project-generator/ProcessCertServiceFile.cs

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
using Azure;
2+
using Azure.Storage.Blobs;
13
using azure_project_generator.models;
24
using azure_project_generator.services;
35
using Microsoft.Azure.Functions.Worker;
46
using Microsoft.Extensions.Logging;
57
using Newtonsoft.Json;
68
using OpenAI.Embeddings;
79

10+
11+
812
namespace azure_project_generator
913
{
1014
public class ProcessCertServiceFile
@@ -13,16 +17,18 @@ public class ProcessCertServiceFile
1317
private readonly EmbeddingClient _embeddingClient;
1418
private readonly JsonValidationService _jsonValidationService;
1519
private readonly ContentGenerationService _contentGenerationService;
20+
private readonly BlobServiceClient _blobServiceClient;
1621

1722
public ProcessCertServiceFile(ILogger<ProcessCertServiceFile> logger,
1823
EmbeddingClient embeddingClient,
1924
JsonValidationService jsonValidationService,
20-
ContentGenerationService contentGenerationService)
25+
ContentGenerationService contentGenerationService, BlobServiceClient blobServiceClient)
2126
{
2227
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
2328
_embeddingClient = embeddingClient ?? throw new ArgumentNullException(nameof(embeddingClient));
2429
_jsonValidationService = jsonValidationService ?? throw new ArgumentNullException(nameof(jsonValidationService));
2530
_contentGenerationService = contentGenerationService ?? throw new ArgumentNullException(nameof(contentGenerationService));
31+
_blobServiceClient = blobServiceClient ?? throw new ArgumentNullException(nameof(blobServiceClient));
2632
}
2733

2834
[Function(nameof(ProcessCertServiceFile))]
@@ -35,39 +41,64 @@ public async Task<CertificationServiceOutput> Run(
3541
if (string.IsNullOrWhiteSpace(content))
3642
{
3743
_logger.LogError("Blob content is empty or whitespace.");
38-
return new CertificationServiceOutput { Document = null};
44+
return new CertificationServiceOutput { Document = null };
3945
}
4046

4147
if (!_jsonValidationService.ValidateJsonContent<CertificationService>(content))
4248
{
49+
_logger.LogError("Invalid JSON content.");
4350
return new CertificationServiceOutput { Document = null };
4451
}
4552

46-
var mappedServiceData = JsonConvert.DeserializeObject<CertificationService>(content);
47-
if (mappedServiceData == null)
53+
try
4854
{
49-
_logger.LogError("Failed to deserialize content to MappedService.");
50-
return new CertificationServiceOutput { Document = null };
51-
}
55+
var mappedServiceData = JsonConvert.DeserializeObject<CertificationService>(content);
56+
if (mappedServiceData == null)
57+
{
58+
_logger.LogError("Failed to deserialize content to CertificationService.");
59+
return new CertificationServiceOutput { Document = null };
60+
}
5261

53-
string contextSentence = _contentGenerationService.GenerateCertServiceContextSentence(mappedServiceData);
54-
float[] contentVector = await _contentGenerationService.GenerateEmbeddingsAsync(contextSentence);
62+
string contextSentence = _contentGenerationService.GenerateCertServiceContextSentence(mappedServiceData);
63+
float[] contentVector = await _contentGenerationService.GenerateEmbeddingsAsync(contextSentence);
5564

56-
var certServiceDocument = CreateCertServiceDocument(mappedServiceData, contextSentence, contentVector);
65+
var certServiceDocument = CreateCertServiceDocument(mappedServiceData, contextSentence, contentVector);
5766

58-
_logger.LogInformation("Document created successfully.");
59-
_logger.LogInformation($"Archiving blob: {name}");
67+
_logger.LogInformation("Document created successfully.");
68+
_logger.LogInformation($"Deleting blob: {name}");
6069

70+
// delete the blob
71+
BlobContainerClient blobContainerClient = _blobServiceClient.GetBlobContainerClient("certservice");
72+
BlobClient blobClient = blobContainerClient.GetBlobClient(name);
73+
await blobClient.DeleteAsync();
6174

62-
return new CertificationServiceOutput
75+
return new CertificationServiceOutput
76+
{
77+
Document = certServiceDocument,
78+
};
79+
}
80+
catch (JsonException jsonEx)
81+
{
82+
_logger.LogError($"JSON error occurred: {jsonEx.Message}");
83+
return new CertificationServiceOutput { Document = null };
84+
}
85+
catch (HttpRequestException httpEx)
6386
{
64-
Document = certServiceDocument,
65-
66-
};
87+
_logger.LogError($"HTTP request error occurred: {httpEx.Message}");
88+
return new CertificationServiceOutput { Document = null };
89+
}
90+
catch (RequestFailedException storageEx)
91+
{
92+
_logger.LogError($"Azure Storage error occurred: {storageEx.Message}");
93+
return new CertificationServiceOutput { Document = null };
94+
}
95+
catch (Exception ex)
96+
{
97+
_logger.LogError($"An unexpected error occurred: {ex.Message}");
98+
return new CertificationServiceOutput { Document = null };
99+
}
67100
}
68101

69-
// Other methods remain unchanged
70-
71102
private CertificationServiceDocument CreateCertServiceDocument(CertificationService data, string contextSentence, float[] contentVector) =>
72103
new CertificationServiceDocument
73104
{

azure-project-generator/azure-project-generator.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="Azure.AI.OpenAI" Version="2.0.0-beta.3" />
1616
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.2" />
17+
<PackageReference Include="Azure.Storage.Common" Version="12.20.1" />
1718
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.19.1" />
1819
<PackageReference Include="Azure.Storage.Queues" Version="12.19.1" />
1920
<PackageReference Include="JsonSchema.Net" Version="7.2.2" />

azure-project-generator/models/CertificationProjectPromptOutput.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using Microsoft.Azure.Functions.Worker;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72

83
namespace azure_project_generator.models
94
{

azure-project-generator/models/CertificationServiceOutput.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using Microsoft.Azure.Functions.Worker;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72

83
namespace azure_project_generator.models
94
{

azure-project-generator/models/CloudProjectIdea.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using Newtonsoft.Json;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
72

83
namespace azure_project_generator.models
94
{

0 commit comments

Comments
 (0)