Skip to content

Commit

Permalink
fix: sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
raffreitas committed Dec 30, 2024
1 parent b29aa0f commit 9bc3dd0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
9 changes: 0 additions & 9 deletions src/MyRecipes.API/BackgroudServices/DeleteUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,4 @@ private async Task ProcessMessageAsync(ProcessMessageEventArgs eventArgs)
}

private static Task ExceptionReceivedHandler(ProcessErrorEventArgs _) => Task.CompletedTask;

~DeleteUserService() => Dispose();

public override void Dispose()
{
base.Dispose();

GC.SuppressFinalize(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentValidation;

using MyRecipes.Communication.Requests;
using MyRecipes.Domain.ValueObjects;
using MyRecipes.Exceptions;
Expand Down Expand Up @@ -31,7 +32,6 @@ public GenerateRecipeValidator()
if (value.Count(c => c == ' ') > 3 || value.Count(c => c == '/') > 1)
{
context.AddFailure("Ingredient", ResourceMessagesExceptions.INGREDIENT_NOT_FOLLOWING_PATTERN);
return;
}
});
});
Expand Down
5 changes: 2 additions & 3 deletions src/MyRecipes.Infrastructure/DependencyInjectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ private static void AddPasswordEncripter(IServiceCollection services)

private static void AddOpenAI(IServiceCollection services, IConfiguration configuration)
{
const string CHAT_MODEL = "gpt-4o";
var apiKey = configuration.GetValue<string>("Settings:OpenAI:ApiKey");

services.AddScoped<IGenerateRecipeAI, ChatGPTService>();
services.AddScoped(_ => new ChatClient(model: CHAT_MODEL, apiKey: apiKey));
services.AddScoped<IGenerateRecipeAI, ChatGptService>();
services.AddScoped(_ => new ChatClient(model: "gpt-4o", apiKey: apiKey));
}

private static void AddStorage(IServiceCollection services, IConfiguration configuration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using MyRecipes.Domain.Dtos;
using MyRecipes.Domain.Enums;
using MyRecipes.Domain.Services.OpenAi;

using OpenAI.Chat;

namespace MyRecipes.Infrastructure.Services.OpenAI;
internal class ChatGPTService : IGenerateRecipeAI
internal class ChatGptService : IGenerateRecipeAI
{
private readonly ChatClient _chatClient;

public ChatGPTService(ChatClient chatClient) => _chatClient = chatClient;
public ChatGptService(ChatClient chatClient) => _chatClient = chatClient;

public async Task<GeneratedRecipeDto> Generate(IList<string> ingredients)
{
Expand All @@ -18,7 +19,7 @@ public async Task<GeneratedRecipeDto> Generate(IList<string> ingredients)
new UserChatMessage(string.Join(';', ingredients))
];

var completion = await _chatClient.CompleteChatAsync();
var completion = await _chatClient.CompleteChatAsync(messages);

var responseList = completion.Value.Content[0].Text
.Split("\n")
Expand Down

0 comments on commit 9bc3dd0

Please sign in to comment.