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("GeminiApiKey missing in secrets"); } public async Task ParseRecipeImageAsync(IFormFile image) { var googleAI = new GoogleAI(_apiKey); // Using the 2.5 Flash model specifically var model = googleAI.GenerativeModel(Model.Gemini25Flash); using var ms = new MemoryStream(); await image.CopyToAsync(ms); var base64Image = Convert.ToBase64String(ms.ToArray()); var prompt = "Extract this recipe. Provide a title and description."; // This structure ensures the 2.5 model receives both the text and the image correctly var request = new GenerateContentRequest { Contents = new List { new Content { Role = Role.User, Parts = new List { new TextPart { Text = prompt }, new InlineDataPart { MimeType = "image/png", Data = base64Image } } } } }; var response = await model.GenerateContent(request); return new RecipeResponseDto { Title = "Gemini 2.5 Analysis", Description = response.Text ?? "No text returned", Ingredients = new List(), Instructions = new List() }; } }