-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
230 additions
and
44 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
API/ASSISTENTE.Infrastructure.Image/ASSISTENTE.Infrastructure.Image.csproj
This file contains 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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<InternalsVisibleTo Include="ASSISTENTE.Infrastructure"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ASSISTENTE.Infrastructure.LLM.OpenAi\ASSISTENTE.Infrastructure.LLM.OpenAi.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
API/ASSISTENTE.Infrastructure.Image/Contracts/IImageClient.cs
This file contains 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 @@ | ||
using CSharpFunctionalExtensions; | ||
|
||
namespace ASSISTENTE.Infrastructure.Image.Contracts; | ||
|
||
public interface IImageClient | ||
{ | ||
Task<Result<ImageDetails>> GenerateImage(ImagePrompt imagePrompt); | ||
} |
27 changes: 27 additions & 0 deletions
27
API/ASSISTENTE.Infrastructure.Image/Contracts/ImageDetails.cs
This file contains 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,27 @@ | ||
using CSharpFunctionalExtensions; | ||
using SOFTURE.Results; | ||
|
||
namespace ASSISTENTE.Infrastructure.Image.Contracts; | ||
|
||
public sealed class ImageDetails : ValueObject | ||
{ | ||
private ImageDetails(string imageUrl) | ||
{ | ||
ImageUrl = imageUrl; | ||
} | ||
|
||
public string ImageUrl { get; } | ||
|
||
public static Result<ImageDetails> Create(string? imageUrl) | ||
{ | ||
if (string.IsNullOrEmpty(imageUrl)) | ||
return Result.Failure<ImageDetails>(CommonErrors.EmptyParameter.Build()); | ||
|
||
return new ImageDetails(imageUrl); | ||
} | ||
|
||
protected override IEnumerable<IComparable> GetEqualityComponents() | ||
{ | ||
yield return ImageUrl; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
API/ASSISTENTE.Infrastructure.Image/Contracts/ImagePrompt.cs
This file contains 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,27 @@ | ||
using CSharpFunctionalExtensions; | ||
using SOFTURE.Results; | ||
|
||
namespace ASSISTENTE.Infrastructure.Image.Contracts; | ||
|
||
public sealed class ImagePrompt : ValueObject | ||
{ | ||
private ImagePrompt(string prompt) | ||
{ | ||
Prompt = prompt; | ||
} | ||
|
||
public string Prompt { get; } | ||
|
||
public static Result<ImagePrompt> Create(string prompt) | ||
{ | ||
if (string.IsNullOrEmpty(prompt)) | ||
return Result.Failure<ImagePrompt>(CommonErrors.EmptyParameter.Build()); | ||
|
||
return new ImagePrompt(prompt); | ||
} | ||
|
||
protected override IEnumerable<IComparable> GetEqualityComponents() | ||
{ | ||
yield return Prompt; | ||
} | ||
} |
This file contains 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,6 @@ | ||
namespace ASSISTENTE.Infrastructure.Image.Contracts; | ||
|
||
public enum VisionType | ||
{ | ||
OpenAi | ||
} |
20 changes: 20 additions & 0 deletions
20
API/ASSISTENTE.Infrastructure.Image/DependencyInjection.cs
This file contains 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,20 @@ | ||
using ASSISTENTE.Infrastructure.Image.Contracts; | ||
using ASSISTENTE.Infrastructure.LLM.OpenAi; | ||
using ASSISTENTE.Infrastructure.LLM.OpenAi.Settings; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace ASSISTENTE.Infrastructure.Image | ||
{ | ||
internal static class DependencyInjection | ||
{ | ||
public static IServiceCollection AddOpenAiImage<TSettings>(this IServiceCollection services) | ||
where TSettings : IOpenAiSettings | ||
{ | ||
services.AddOpenAi<TSettings>(); | ||
|
||
services.AddScoped<IImageClient, OpenAiClient>(); | ||
|
||
return services; | ||
} | ||
} | ||
} |
This file contains 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,27 @@ | ||
using ASSISTENTE.Infrastructure.Image.Contracts; | ||
using ASSISTENTE.Infrastructure.LLM.OpenAi.Errors; | ||
using CSharpFunctionalExtensions; | ||
using OpenAI; | ||
using OpenAI.Images; | ||
|
||
namespace ASSISTENTE.Infrastructure.Image; | ||
|
||
internal sealed class OpenAiClient(OpenAIClient client) : IImageClient | ||
{ | ||
public async Task<Result<ImageDetails>> GenerateImage(ImagePrompt imagePrompt) | ||
{ | ||
var request = new ImageGenerationRequest( | ||
prompt: imagePrompt.Prompt, | ||
size: "1024x1024" | ||
); | ||
|
||
var response = await client.ImagesEndPoint.GenerateImageAsync(request); | ||
|
||
if (response is null) | ||
return Result.Failure<ImageDetails>(ClientErrors.EmptyAnswer.Build()); | ||
|
||
var imageDetails = response.FirstOrDefault(); | ||
|
||
return ImageDetails.Create(imageDetails?.Url); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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
Oops, something went wrong.