using Seasoned.Backend.DTOs; using Mscc.GenerativeAI; namespace Seasoned.Backend.Services; public class RecipeService : IRecipeService { private readonly string _apiKey; public RecipeService(IConfiguration config) { _apiKey = config["GeminiApiKey"] ?? throw new ArgumentNullException("API Key missing"); } public async Task ParseRecipeImageAsync(IFormFile image) { var googleAI = new Mscc.GenerativeAI.GoogleAI(_apiKey); // Explicitly calling Gemini 2.5 Flash var model = googleAI.GenerativeModel(Mscc.GenerativeAI.Model.Gemini25Flash); using var ms = new MemoryStream(); await image.CopyToAsync(ms); var base64Image = Convert.ToBase64String(ms.ToArray()); var prompt = "Extract the recipe from this image. Return Title and Description."; // Using full namespace paths for all request objects var request = new Mscc.GenerativeAI.GenerateContentRequest { Contents = new List { new Mscc.GenerativeAI.Content { Role = Mscc.GenerativeAI.Role.User, Parts = new List { new Mscc.GenerativeAI.TextPart { Text = prompt }, new Mscc.GenerativeAI.InlineDataPart { MimeType = "image/png", Data = base64Image } } } } }; var response = await model.GenerateContent(request); return new RecipeResponseDto { Title = "Gemini 2.5 Result", Description = response.Text ?? "No text returned", Ingredients = new List(), Instructions = new List() }; } }