-
Notifications
You must be signed in to change notification settings - Fork 0
chore: tf-azure-ai-foundry #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0387bb7
chore: tf-azure-ai-foundry
eugbyte 8551736
fmt: tf
eugbyte ed6140c
fix: fmt
eugbyte 46ef102
chore: update
eugbyte 372b03d
chore: error handling safety
eugbyte c81ce2a
fix: tf
eugbyte acfc9a4
fix: ctor
eugbyte cb85e11
fix: fmt
eugbyte 3c666aa
fix: fmt
eugbyte 42ac7bf
fix: fmt
eugbyte c40377e
fix: fmt
eugbyte 51f860a
fix: fmt
eugbyte 5ac7fd4
fix: fmt
eugbyte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Azure AI Foundry Content Safety resource | ||
| resource "azurerm_cognitive_account" "content_safety" { | ||
| name = "cs-evently-dev-sea" | ||
| location = azurerm_resource_group.rg.location | ||
| resource_group_name = azurerm_resource_group.rg.name | ||
| kind = "ContentSafety" | ||
| sku_name = "F0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,12 +10,25 @@ | |||||
| namespace Evently.Server.Features.Files.Services; | ||||||
|
|
||||||
| // Based on https://tinyurl.com/5pam66xn | ||||||
| public sealed class ObjectStorageService(IOptions<Settings> settings, ILogger<ObjectStorageService> logger) : IObjectStorageService { | ||||||
| private readonly BlobServiceClient _blobServiceClient = | ||||||
| new(settings.Value.StorageAccount.AzureStorageConnectionString); | ||||||
| private readonly ContentSafetyClient _contentSafetyClient = new( | ||||||
| endpoint: new Uri(settings.Value.AzureAiFoundry.ContentSafetyEndpoint), | ||||||
| credential: new AzureKeyCredential(settings.Value.AzureAiFoundry.ContentSafetyKey)); | ||||||
| public sealed class ObjectStorageService : IObjectStorageService { | ||||||
| private readonly BlobServiceClient _blobServiceClient; | ||||||
| private readonly ContentSafetyClient? _contentSafetyClient; | ||||||
| private readonly ILogger<ObjectStorageService> _logger; | ||||||
|
|
||||||
| public ObjectStorageService(IOptions<Settings> settings, ILogger<ObjectStorageService> logger) { | ||||||
| _logger = logger; | ||||||
| _blobServiceClient = | ||||||
| new BlobServiceClient(settings.Value.StorageAccount.AzureStorageConnectionString); | ||||||
|
|
||||||
| try { | ||||||
| _contentSafetyClient = new ContentSafetyClient( | ||||||
| endpoint: new Uri(settings.Value.AzureAiFoundry.ContentSafetyEndpoint), | ||||||
| credential: new AzureKeyCredential(settings.Value.AzureAiFoundry.ContentSafetyKey)); | ||||||
| } catch (Exception ex) { | ||||||
| // silence the error | ||||||
| _logger.LogError("error creating content safety client: {}. Content moderation skipped.", ex.Message); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public async Task<Uri> UploadFile(string containerName, string fileName, BinaryData binaryData, | ||||||
| string mimeType = "application/octet-stream") { | ||||||
|
|
@@ -63,7 +76,7 @@ public async Task<BinaryData> GetFile(string containerName, string fileName) { | |||||
| try { | ||||||
| await blobClient.DownloadToAsync(ms); | ||||||
| } catch (Exception ex) { | ||||||
| logger.LogError("error getting file: {}", ex.Message); | ||||||
| _logger.LogError("error getting file: {}", ex.Message); | ||||||
| } | ||||||
|
|
||||||
| byte[] bytes = ms.ToArray(); | ||||||
|
|
@@ -72,21 +85,25 @@ public async Task<BinaryData> GetFile(string containerName, string fileName) { | |||||
| } | ||||||
|
|
||||||
| public async Task<bool> PassesContentModeration(BinaryData binaryData) { | ||||||
| if (_contentSafetyClient is null) { | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| ContentSafetyImageData image = new(binaryData); | ||||||
| AnalyzeImageOptions request = new(image); | ||||||
| Response<AnalyzeImageResult> response; | ||||||
| try { | ||||||
| response = await _contentSafetyClient.AnalyzeImageAsync(request); | ||||||
| } catch (RequestFailedException ex) { | ||||||
| logger.LogContentModerationError(ex.Status.ToString(), ex.ErrorCode ?? "", ex.Message); | ||||||
| _logger.LogContentModerationError(statusCode: ex.Status.ToString(), errorCode: ex.ErrorCode ?? "", ex.Message); | ||||||
|
||||||
| _logger.LogContentModerationError(statusCode: ex.Status.ToString(), errorCode: ex.ErrorCode ?? "", ex.Message); | |
| _logger.LogContentModerationError(ex.Status.ToString(), ex.ErrorCode ?? "", ex.Message); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message uses a placeholder '{}' which is not standard for .NET logging. Use '{Message}' or positional parameters like '{0}' for proper structured logging.