Organize workspace: Frontend, Backend, and Tests in one repo
This commit is contained in:
53
.vscode-server/data/User/History/b03096/ZxdS.cs
Normal file
53
.vscode-server/data/User/History/b03096/ZxdS.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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<RecipeResponseDto> 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.";
|
||||
|
||||
// 1. Create the parts using the IPart interface
|
||||
var parts = new List<IPart>
|
||||
{
|
||||
new TextPart { Text = prompt },
|
||||
new InlineDataPart { MimeType = "image/png", Data = base64Image }
|
||||
};
|
||||
|
||||
// 2. Create Content using the constructor (to fix CS1729)
|
||||
var content = new Content(parts, Role.User);
|
||||
|
||||
// 3. Create the Request
|
||||
var request = new GenerateContentRequest
|
||||
{
|
||||
Contents = new List<Content> { content }
|
||||
};
|
||||
|
||||
// 4. Call the model
|
||||
var response = await model.GenerateContent(request);
|
||||
|
||||
return new RecipeResponseDto
|
||||
{
|
||||
Title = "Gemini 2.5 Analysis",
|
||||
Description = response.Text ?? "No text returned",
|
||||
Ingredients = new List<string>(),
|
||||
Instructions = new List<string>()
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user