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 GoogleAI(_apiKey); var model = googleAI.GenerativeModel("gemini-2.5-flash"); 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."; // Use the base Part class with property initializers var parts = new List { new Part { Text = prompt }, new Part { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } } }; // Use the default constructor and set properties var content = new Content { Role = Role.User, Parts = parts }; var request = new GenerateContentRequest { Contents = new List { content } }; // Casting to solve the ambiguity error we saw earlier var response = await model.GenerateContent((GenerateContentRequest)request); return new RecipeResponseDto { Title = "Gemini 2.5 Analysis", Description = response.Text ?? "No text returned", Ingredients = new List(), Instructions = new List() }; } }