Organize workspace: Frontend, Backend, and Tests in one repo
This commit is contained in:
55
.vscode-server/data/User/History/b03096/J28Z.cs
Normal file
55
.vscode-server/data/User/History/b03096/J28Z.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
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 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<Mscc.GenerativeAI.Content>
|
||||
{
|
||||
new Mscc.GenerativeAI.Content
|
||||
{
|
||||
Role = Mscc.GenerativeAI.Role.User,
|
||||
Parts = new List<Mscc.GenerativeAI.Part>
|
||||
{
|
||||
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<string>(),
|
||||
Instructions = new List<string>()
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user