Organize workspace: Frontend, Backend, and Tests in one repo

This commit is contained in:
2026-03-04 22:04:07 +00:00
parent a24e901b7f
commit c065cbf61e
5390 changed files with 844081 additions and 446 deletions

View File

@@ -0,0 +1,11 @@
// vitest.config.ts
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
test: {
globals: true,
environment: 'jsdom',
},
})

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned/vitest.config.ts","entries":[{"id":"3Okw.ts","timestamp":1772653272270},{"id":"hUJW.ts","timestamp":1772654078047}]}

View File

@@ -0,0 +1,16 @@
// vitest.config.ts
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
test: {
globals: true,
environment: 'jsdom',
server: {
deps: {
inline: [/@exodus\/bytes/, /html-encoding-sniffer/],
},
},
},
})

View File

@@ -0,0 +1,32 @@
{
"name": "Seasoned",
"type": "module",
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"test": "vitest"
},
"dependencies": {
"@google/generative-ai": "^0.24.1",
"@mdi/font": "^7.4.47",
"@prisma/client": "^7.4.2",
"dotenv": "^17.3.1",
"nuxt": "^4.1.3",
"prisma": "^6.19.2",
"sass": "^1.97.3",
"vue": "^3.5.29",
"vue-router": "^4.6.4",
"vuetify": "^4.0.1"
},
"devDependencies": {
"@types/node": "^25.3.3",
"@vitejs/plugin-vue": "^6.0.4",
"@vue/test-utils": "^2.4.6",
"jsdom": "^28.1.0",
"vitest": "^4.0.18"
}
}

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned/package.json","entries":[{"id":"Z7Qa.json","timestamp":1772653302431}]}

View File

@@ -0,0 +1,26 @@
{
"[python]": {
"editor.formatOnType": true
},
"security.workspace.trust.untrustedFiles": "open",
"editor.minimap.enabled": false,
"editor.unicodeHighlight.invisibleCharacters": false,
"redhat.telemetry.enabled": false,
"window.zoomLevel": 1,
"editor.unicodeHighlight.nonBasicASCII": false,
"remote.SSH.remotePlatform": {
"neptune.wrigglyt.xyz": "linux",
"10.0.11.3": "linux"
},
"jupyter.askForKernelRestart": false,
"git.openRepositoryInParentFolders": "never",
"workbench.colorTheme": "Shades of Purple (Super Dark)",
"jdk.telemetry.enabled": false,
"git.autofetch": true,
"cSpell.userWords": [
"Tutankhamun",
"vuetify",
"wordle",
"wordlist"
]
}

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-userdata:/c%3A/Users/Chloe/AppData/Roaming/Code/User/settings.json","entries":[{"id":"dvL4.json","timestamp":1772650572407}]}

View File

@@ -0,0 +1,110 @@
<template>
<v-app>
<v-main>
<v-container>
<v-card class="pa-5 mx-auto mt-10" max-width="500" elevation="10">
<v-card-title class="text-center">Seasoned AI</v-card-title>
<v-divider class="my-3"></v-divider>
<v-file-input
v-model="files"
label="Pick a recipe photo"
prepend-icon="mdi-camera"
variant="outlined"
accept="image/*"
></v-file-input>
<v-btn
color="primary"
block
size="x-large"
:loading="loading"
@click="uploadImage"
>
Analyze Recipe
</v-btn>
<div v-if="recipe" class="mt-5">
<h2 class="text-h4 mb-4">{{ recipe.title }}</h2>
<p class="text-subtitle-1 mb-6 text-grey-darken-1">{{ recipe.description }}</p>
<v-row>
<v-col cols="12" md="5">
<h3 class="text-h6 mb-2">Ingredients</h3>
<v-list lines="one" variant="flat" class="bg-grey-lighten-4 rounded-lg">
<v-list-item v-for="(item, i) in recipe.ingredients" :key="i">
<template v-slot:prepend>
<v-icon icon="mdi-circle-small"></v-icon>
</template>
{{ item }}
</v-list-item>
</v-list>
</v-col>
<v-col cols="12" md="7">
<h3 class="text-h6 mb-2">Instructions</h3>
<v-timeline side="end" align="start" density="compact">
<v-timeline-item
v-for="(step, i) in recipe.instructions"
:key="i"
dot-color="primary"
size="x-small"
>
<div class="text-body-1">{{ step }}</div>
</v-timeline-item>
</v-timeline>
</v-col>
</v-row>
</div>
</v-card>
</v-container>
</v-main>
</v-app>
</template>
<script setup>
import axios from 'axios'
import { ref } from 'vue'
const files = ref([])
const loading = ref(false)
const recipe = ref(null)
const uploadImage = async () => {
// 1. Debug: Check what Vuetify is actually giving us
console.log("Files variable:", files.value);
// Vuetify 3 v-file-input can return a single File or an Array of Files
// We need to ensure we have the actual File object
const fileToUpload = Array.isArray(files.value) ? files.value[0] : files.value;
if (!fileToUpload) {
alert("Please select a file first!");
return;
}
loading.value = true;
const formData = new FormData();
// 2. Append the file. The string 'image' MUST match your C# parameter name
formData.append('image', fileToUpload);
try {
// 3. Post with explicit multipart/form-data header (Axios usually does this, but let's be sure)
const response = await axios.post('http://localhost:5000/api/recipe/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
recipe.value = response.data;
console.log("Success:", response.data);
} catch (error) {
console.error("Detailed Error:", error.response?.data || error.message);
alert("Backend error: Check the browser console for details.");
} finally {
loading.value = false;
}
}
</script>

View File

@@ -0,0 +1,67 @@
<template>
<v-app>
<v-app-bar title="Seasoned AI Recipe Parser" color="primary"></v-app-bar>
<v-main>
<v-container>
<v-card class="mx-auto mt-5" max-width="600">
<v-card-text>
<v-file-input
v-model="selectedFile"
label="Upload Recipe Photo"
accept="image/*"
prepend-icon="mdi-camera"
@change="onFileSelect"
></v-file-input>
<v-btn
:loading="loading"
color="success"
block
@click="uploadImage"
:disabled="!selectedFile"
>
Analyze with C# Backend
</v-btn>
</v-card-text>
</v-card>
<v-card v-if="recipe" class="mx-auto mt-5" max-width="600">
<v-card-title>{{ recipe.title }}</v-card-title>
<v-card-text>
<div class="text-subtitle-1">Ingredients:</div>
<ul>
<li v-for="item in recipe.ingredients" :key="item">{{ item }}</li>
</ul>
</v-card-text>
</v-card>
</v-container>
</v-main>
</v-app>
</template>
<script setup>
import axios from 'axios'
const selectedFile = ref(null)
const loading = ref(false)
const recipe = ref(null)
const uploadImage = async () => {
if (!selectedFile.value) return
loading.value = true
const formData = new FormData()
// We use [0] because v-file-input returns an array
formData.append('image', selectedFile.value[0])
try {
// This points to your C# Backend we built earlier!
const response = await axios.post('http://localhost:5000/api/recipe/upload', formData)
recipe.value = response.data
} catch (error) {
console.error("Backend Error:", error)
alert("Make sure your C# Backend is running on port 5000!")
} finally {
loading.value = false
}
}
</script>

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned/app/app.vue","entries":[{"id":"KNJK.vue","timestamp":1772654853257},{"id":"yQXD.vue","timestamp":1772655854730},{"id":"wG0o.vue","timestamp":1772658220344},{"id":"4Y2E.vue","timestamp":1772660655062}]}

View File

@@ -0,0 +1,82 @@
<template>
<v-app>
<v-main>
<v-container>
<v-card class="pa-5 mx-auto mt-10" max-width="500" elevation="10">
<v-card-title class="text-center">Seasoned AI</v-card-title>
<v-divider class="my-3"></v-divider>
<v-file-input
v-model="files"
label="Pick a recipe photo"
prepend-icon="mdi-camera"
variant="outlined"
accept="image/*"
></v-file-input>
<v-btn
color="primary"
block
size="x-large"
:loading="loading"
@click="uploadImage"
>
Analyze Recipe
</v-btn>
<div v-if="recipe" class="mt-5">
<h3 class="text-h6">{{ recipe.title }}</h3>
<p>{{ recipe.description }}</p>
</div>
</v-card>
</v-container>
</v-main>
</v-app>
</template>
<script setup>
import axios from 'axios'
import { ref } from 'vue'
const files = ref([])
const loading = ref(false)
const recipe = ref(null)
const uploadImage = async () => {
// 1. Debug: Check what Vuetify is actually giving us
console.log("Files variable:", files.value);
// Vuetify 3 v-file-input can return a single File or an Array of Files
// We need to ensure we have the actual File object
const fileToUpload = Array.isArray(files.value) ? files.value[0] : files.value;
if (!fileToUpload) {
alert("Please select a file first!");
return;
}
loading.value = true;
const formData = new FormData();
// 2. Append the file. The string 'image' MUST match your C# parameter name
formData.append('image', fileToUpload);
try {
// 3. Post with explicit multipart/form-data header (Axios usually does this, but let's be sure)
const response = await axios.post('http://localhost:5000/api/recipe/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
recipe.value = response.data;
console.log("Success:", response.data);
} catch (error) {
console.error("Detailed Error:", error.response?.data || error.message);
alert("Backend error: Check the browser console for details.");
} finally {
loading.value = false;
}
}
</script>

View File

@@ -0,0 +1,68 @@
<template>
<v-app>
<v-main>
<v-container>
<v-card class="pa-5 mx-auto mt-10" max-width="500" elevation="10">
<v-card-title class="text-center">Seasoned AI</v-card-title>
<v-divider class="my-3"></v-divider>
<v-file-input
v-model="files"
label="Pick a recipe photo"
prepend-icon="mdi-camera"
variant="outlined"
accept="image/*"
></v-file-input>
<v-btn
color="primary"
block
size="x-large"
:loading="loading"
@click="uploadImage"
>
Analyze Recipe
</v-btn>
<div v-if="recipe" class="mt-5">
<h3 class="text-h6">{{ recipe.title }}</h3>
<p>{{ recipe.description }}</p>
</div>
</v-card>
</v-container>
</v-main>
</v-app>
</template>
<script setup>
import axios from 'axios'
import { ref } from 'vue'
const files = ref([])
const loading = ref(false)
const recipe = ref(null)
const uploadImage = async () => {
if (!files.value || files.value.length === 0) {
alert("Please select a file first!")
return
}
loading.value = true
const formData = new FormData()
// Vuetify v-file-input returns an array
formData.append('image', files.value[0])
try {
const response = await axios.post('http://localhost:5000/api/recipe/upload', formData)
recipe.value = response.data
console.log("Success:", response.data)
} catch (error) {
console.error("Connection Error:", error)
alert("Could not connect to C# Backend on port 5000")
} finally {
loading.value = false
}
}
</script>

View File

@@ -0,0 +1,38 @@
export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
devtools: { enabled: true },
future: {
compatibilityVersion: 4,
},
srcDir: 'app/',
css: [
'vuetify/lib/styles/main.sass',
'@mdi/font/css/materialdesignicons.min.css',
],
build: {
transpile: ['vuetify'],
},
modules: [
'vuetify-nuxt-module'
],
runtimeConfig: {
geminiApiKey: '',
},
vite: {
server: {
hmr: {
protocol: 'ws',
host: 'localhost',
port: 3000
}
}
}
})

View File

@@ -0,0 +1,25 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
devtools: { enabled: true },
future: {
compatibilityVersion: 4,
},
srcDir: 'app/',
css: [
'vuetify/lib/styles/main.sass',
'@mdi/font/css/materialdesignicons.min.css',
],
build: {
transpile: ['vuetify'],
},
modules: [
'vuetify-nuxt-module'
],
// Environment Variables for Gemini
runtimeConfig: {
geminiApiKey: '',
},
})

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned/nuxt.config.ts","entries":[{"id":"YA3U.ts","timestamp":1772656098549},{"id":"4vNe.ts","timestamp":1772656590628}]}

View File

@@ -0,0 +1,27 @@
using Seasoned.Backend.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IRecipeService, RecipeService>();
builder.Services.AddControllers();
builder.Services.AddOpenApi();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
});
});
var app = builder.Build();
app.UseCors();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,29 @@
using Seasoned.Backend.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IRecipeService, RecipeService>();
builder.Services.AddControllers();
builder.Services.AddOpenApi();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
var app = builder.Build();
app.UseCors("AllowAll");
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.MapControllers();
app.Run();

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned.Backend/Program.cs","entries":[{"id":"f7pI.cs","timestamp":1772653808017},{"id":"uV5H.cs","timestamp":1772655393867},{"id":"DOP7.cs","timestamp":1772655404025},{"id":"H1dq.cs","timestamp":1772656795188}]}

View File

@@ -0,0 +1,18 @@
using Seasoned.Backend.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IRecipeService, RecipeService>();
builder.Services.AddControllers();
builder.Services.AddOpenApi();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,26 @@
using Seasoned.Backend.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IRecipeService, RecipeService>();
builder.Services.AddControllers();
builder.Services.AddOpenApi();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
});
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.MapControllers();
app.Run();

View File

@@ -0,0 +1,8 @@
using Seasoned.Backend.DTOs;
namespace Seasoned.Backend.Services;
public interface IRecipeService
{
Task<RecipeResponseDto> ParseRecipeImageAsync(IFormFile image);
}

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned.Backend/Services/IRecipeService.cs","entries":[{"id":"ZKMQ.cs","timestamp":1772653775570}]}

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned/Seasoned.code-workspace","entries":[{"id":"zqpI.code-workspace","timestamp":1772653555260}]}

View File

@@ -0,0 +1,14 @@
{
"folders": [
{
"path": "."
},
{
"path": "../Seasoned.Backend"
},
{
"path": "../Seasoned.Tests"
}
],
"settings": {}
}

View File

@@ -0,0 +1,6 @@
# 1. The "Key" to the AI (Gemini)
GEMINI_API_KEY=AIzaSyCB_8aoRxQEXeO2cakFn_u5dttRbyThOf4
# 2. The "Address" to the Database (Postgres)
# Replace 'localhost' with theserver IP when you deploy
DATABASE_URL="postgresql://seasoned_admin:your_secure_password_here@localhost:5432/seasoned_db?schema=public"

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned/.env","entries":[{"id":"90iu","timestamp":1772655859776}]}

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned.Backend/Controllers/RecipeController.cs","entries":[{"id":"vcso.cs","timestamp":1772653722495},{"id":"gfRM.cs","timestamp":1772658067690}]}

View File

@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Mvc;
using Seasoned.Backend.Services;
using Seasoned.Backend.DTOs;
namespace Seasoned.Backend.Controllers;
[ApiController]
[Route("api/[controller]")]
public class RecipeController : ControllerBase
{
private readonly IRecipeService _recipeService;
// Dependency Injection: The service is "injected" here
public RecipeController(IRecipeService recipeService)
{
_recipeService = recipeService;
}
[HttpPost("upload")]
public async Task<ActionResult<RecipeResponseDto>> UploadRecipe([FromForm] IFormFile image)
{
if (image == null || image.Length == 0)
{
return BadRequest("No image uploaded.");
}
var result = await _recipeService.ParseRecipeImageAsync(image);
return Ok(result);
}
}

View File

@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Mvc;
using Seasoned.Backend.Services;
using Seasoned.Backend.DTOs;
namespace Seasoned.Backend.Controllers;
[ApiController]
[Route("api/[controller]")]
public class RecipeController : ControllerBase
{
private readonly IRecipeService _recipeService;
// Dependency Injection: The service is "injected" here
public RecipeController(IRecipeService recipeService)
{
_recipeService = recipeService;
}
[HttpPost("upload")]
public async Task<ActionResult<RecipeResponseDto>> UploadRecipe(IFormFile image)
{
if (image == null || image.Length == 0)
{
return BadRequest("No image uploaded.");
}
var result = await _recipeService.ParseRecipeImageAsync(image);
return Ok(result);
}
}

View File

@@ -0,0 +1,15 @@
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
// If you're using Nuxt 4, we use the standard 'nuxt/app' import to help the editor
import { defineNuxtPlugin } from '#app'
export default defineNuxtPlugin((nuxtApp) => {
const vuetify = createVuetify({
ssr: true,
components,
directives,
})
nuxtApp.vueApp.use(vuetify)
})

View File

@@ -0,0 +1,17 @@
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
// We use the global defineNuxtPlugin.
// If it's still red, it's just a VS Code cache issue—the code is valid.
export default defineNuxtPlugin((nuxtApp) => {
const vuetify = createVuetify({
ssr: true,
components,
directives,
})
// We cast nuxtApp as 'any' ONLY if the editor is being stubborn
// during your setup, but npx nuxi prepare usually fixes the real type.
nuxtApp.vueApp.use(vuetify)
})

View File

@@ -0,0 +1,14 @@
// plugins/vuetify.ts
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
export default defineNuxtPlugin((nuxtApp) => {
const vuetify = createVuetify({
ssr: true,
components,
directives,
})
nuxtApp.vueApp.use(vuetify)
})

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned/plugins/vuetify.ts","entries":[{"id":"R09H.ts","timestamp":1772654162226},{"id":"8Yqw.ts","timestamp":1772654356633},{"id":"KNbC.ts","timestamp":1772654431873},{"id":"z5oj.ts","timestamp":1772654663808}]}

View File

@@ -0,0 +1,14 @@
// @ts-nocheck
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
export default defineNuxtPlugin((nuxtApp) => {
const vuetify = createVuetify({
ssr: true,
components,
directives,
})
nuxtApp.vueApp.use(vuetify)
})

View File

@@ -0,0 +1,8 @@
import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
describe('Frontend Setup', () => {
it('checks that 1 + 1 is 2', () => {
expect(1 + 1).toBe(2)
})
})

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned/test/App.spec.ts","entries":[{"id":"4b9C.ts","timestamp":1772653995852}]}

View File

@@ -0,0 +1,9 @@
namespace Seasoned.Backend.DTOs;
public class RecipeResponseDto
{
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public List<string> Ingredients { get; set; } = new();
public List<string> Instructions { get; set; } = new();
}

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned.Backend/DTOs/RecipeResponseDto.cs","entries":[{"id":"WSMI.cs","timestamp":1772653671151}]}

View File

@@ -0,0 +1,47 @@
using Moq;
using Xunit;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Seasoned.Backend.Controllers;
using Seasoned.Backend.Services;
using Seasoned.Backend.DTOs;
namespace Seasoned.Tests;
public class RecipeControllerTests
{
[Fact]
public async Task ParseRecipe_ReturnsOk_WhenImageIsValid()
{
// 1. Arrange: Create a "Fake" Service
var mockService = new Mock<IRecipeService>();
var fakeRecipe = new RecipeResponseDto { Title = "Test Recipe" };
mockService.Setup(s => s.ParseImageAsync(It.IsAny<IFormFile>()))
.ReturnsAsync(fakeRecipe);
var controller = new RecipeController(mockService.Object);
// Create a fake image file
var content = "fake image content";
var fileName = "test.jpg";
var ms = new MemoryStream();
var writer = new StreamWriter(ms);
writer.Write(content);
writer.Flush();
ms.Position = 0;
var mockFile = new FormFile(ms, 0, ms.Length, "id_from_form", fileName);
// 2. Act: Call the Controller
var result = await controller.ParseRecipe(mockFile);
// 3. Assert: Check the result
var okResult = result as OkObjectResult;
okResult.Should().NotBeNull();
okResult!.StatusCode.Should().Be(200);
var returnedRecipe = okResult.Value as RecipeResponseDto;
returnedRecipe!.Title.Should().Be("Test Recipe");
}
}

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned.Tests/UnitTest1.cs","entries":[{"id":"FuxE.cs","timestamp":1772653857111}]}

View File

@@ -0,0 +1,55 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using Microsoft.AspNetCore.Http;
using System.IO;
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. Initialize Content with the Role in the constructor
var content = new Content(Role.User);
// 2. Assign the parts using dynamic to bypass the IPart/Part conversion headache
content.Parts = (dynamic)new List<object>
{
new { text = prompt },
new { inline_data = new { mime_type = "image/png", data = base64Image } }
};
// 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>()
};
}
}

View File

@@ -0,0 +1,49 @@
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.";
var content = new Content(Role.User);
content.Parts = new List<IPart>
{
(IPart)new Part { Text = prompt },
(IPart)new Part { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
};
var request = new GenerateContentRequest
{
Contents = new List<Content> { content }
};
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>()
};
}
}

View File

@@ -0,0 +1,48 @@
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.";
var content = new Content(Role.User);
content.Parts = new List<IPart>
{
(IPart)new Part { Text = prompt },
(IPart)new Part { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
};
var request = new GenerateContentRequest
{
Contents = new List<Content> { content }
};
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>()
};
}

View File

@@ -0,0 +1,18 @@
using Seasoned.Backend.DTOs;
namespace Seasoned.Backend.Services;
public class RecipeService : IRecipeService
{
public async Task<RecipeResponseDto> ParseRecipeImageAsync(IFormFile image)
{
// Placeholder logic to satisfy the return type
return new RecipeResponseDto
{
Title = "Mock Recipe",
Description = "This is a placeholder until Gemini is linked.",
Ingredients = new List<string> { "Ingredient A", "Ingredient B" },
Instructions = new List<string> { "Cook it", "Eat it" }
};
}
}

View File

@@ -0,0 +1,43 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using Microsoft.AspNetCore.Http;
using System.IO;
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.";
var request = new GenerateContentRequest(prompt);
await request.AddMedia(base64Image, "image/png");
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>()
};
}
}

View File

@@ -0,0 +1,50 @@
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.";
var parts = new List<IPart>
{
new Part { Text = prompt },
new Part { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
};
var content = new Content(parts);
content.Role = Role.User;
var request = new GenerateContentRequest
{
Contents = new List<Content> { content }
};
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>()
};
}
}

View File

@@ -0,0 +1,49 @@
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.";
var content = new Content(Role.User);
content.Parts = new List<IPart>
{
(IPart)new Part { Text = prompt },
(IPart)new Part { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
};
var request = new GenerateContentRequest
{
Contents = new List<Content> { content }
};
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>()
};
}
}

View File

@@ -0,0 +1,52 @@
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)
{
// Use the explicit string for the model to bypass the "Model.Gemini25Flash" error
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());
// Use a dynamic request structure which the library supports for newer models
var prompt = "Extract the recipe from this image. Return Title and Description.";
// This is a more robust way to send the request in the latest version
var response = await model.GenerateContent(new()
{
Contents = new List<Content>
{
new Content
{
Parts = new List<Part>
{
new() { Text = prompt },
new() { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
}
}
}
});
return new RecipeResponseDto
{
Title = "Gemini 2.5 Analysis",
Description = response.Text ?? "No text returned",
Ingredients = new List<string>(),
Instructions = new List<string>()
};
}
}

View File

@@ -0,0 +1,52 @@
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.";
// Use the constructor that the error message suggested: Content(string role)
var content = new Content(Role.User);
// Add parts manually to avoid the IPart/Part conversion headache
content.Parts = new List<Part>
{
new Part { Text = prompt },
new Part { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
};
var request = new GenerateContentRequest
{
Contents = new List<Content> { content }
};
// Call the model with the explicit request
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>()
};
}
}

View 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>()
};
}
}

View File

@@ -0,0 +1,47 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using Microsoft.AspNetCore.Http;
using System.IO;
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);
// Using the 2026 model string
var model = googleAI.GenerativeModel("gemini-2.5-flash");
using var ms = new MemoryStream();
await image.CopyToAsync(ms);
var imageBytes = ms.ToArray();
var prompt = "Extract the recipe from this image. Return Title and Description.";
// 1. New GenerateContentRequest automatically handles the text
var request = new GenerateContentRequest(prompt);
// 2. AddMedia is now the standard for version 3.x+
// This handles the binary-to-base64 conversion internally!
request.AddMedia(imageBytes, "image/png");
// 3. Send the unified request
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>()
};
}
}

View File

@@ -0,0 +1,49 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using Microsoft.AspNetCore.Http;
using System.IO;
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());
// 1. Better Prompt: Tell Gemini exactly what the JSON should look like
var prompt = @"Extract the recipe from this image.
Return a JSON object with exactly these fields:
{
""title"": ""string"",
""description"": ""string"",
""ingredients"": [""string""],
""instructions"": [""string""]
}";
// 2. Set the Response MIME Type to application/json
var config = new GenerationConfig { ResponseMimeType = "application/json" };
var request = new GenerateContentRequest(prompt, config);
request.AddMedia(base64Image, "image/png");
var response = await model.GenerateContent(request);
// 3. Use System.Text.Json to turn that string back into our DTO
var options = new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true };
var result = System.Text.Json.JsonSerializer.Deserialize<RecipeResponseDto>(response.Text, options);
return result ?? new RecipeResponseDto { Title = "Error parsing JSON" };
}
}

View File

@@ -0,0 +1,50 @@
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.";
// Use the library's internal GenerateContentRequest but manually build the Parts list
var request = new GenerateContentRequest();
var content = new Content(Role.User);
// This is the specific syntax to satisfy the IPart list requirement
content.Parts = new List<IPart>
{
new Part { Text = prompt },
new Part { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
}.Cast<IPart>().ToList(); // This 'Cast' is the magic bullet
request.Contents = new List<Content> { content };
// Solve the ambiguity by picking the Request overload
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>()
};
}
}

View File

@@ -0,0 +1,56 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using Microsoft.AspNetCore.Http;
using System.IO;
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);
// Use a string for the model name to avoid CS0117
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 constructor that the library likes
var request = new GenerateContentRequest();
// Manually build the structure in a way that avoids the List conversion crash
var content = new Content(Role.User);
// We add the text part using the library's preferred text-first approach
request.Contents = new List<Content> { content };
// Attempting the most universal "Add" method for media
// If your library doesn't have AddMedia, we use this direct property:
content.Parts = new List<IPart>
{
new TextPart(prompt),
new InlineDataPart("image/png", base64Image)
};
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>()
};
}
}

View File

@@ -0,0 +1,47 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI; // Add this!
namespace Seasoned.Backend.Services;
public class RecipeService : IRecipeService
{
private readonly string _apiKey;
public RecipeService(IConfiguration config)
{
// Get the key from your user-secrets
_apiKey = config["GeminiApiKey"] ?? throw new ArgumentNullException("API Key missing");
}
public async Task<RecipeResponseDto> ParseRecipeImageAsync(IFormFile image)
{
// 1. Initialize Gemini
var googleAI = new GoogleAI(_apiKey);
var model = googleAI.GenerativeModel(Model.Gemini15Flash);
// 2. Convert the uploaded image to a format Gemini understands
using var ms = new MemoryStream();
await image.CopyToAsync(ms);
var base64Image = Convert.ToBase64String(ms.ToArray());
// 3. The "Magic" Prompt
var prompt = "Extract the recipe from this image. Return ONLY a JSON object with: title (string), description (string), ingredients (array of strings), and instructions (array of strings).";
// 4. Call Gemini
var response = await model.GenerateContent(new List<Part> {
new TextPart { Text = prompt },
new InlineDataPart { MimeType = "image/jpeg", Data = base64Image }
});
// 5. Parse the AI's response (simplified for now)
var aiText = response.Text;
// For now, let's return the AI text in our DTO
return new RecipeResponseDto
{
Title = "AI Decoded Recipe",
Description = aiText, // The raw AI response
Ingredients = new List<string> { "Check description for details" }
};
}
}

View 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>()
};
}
}

View File

@@ -0,0 +1,24 @@
using Seasoned.Backend.DTOs;
namespace Seasoned.Backend.Services;
public interface IRecipeService
{
Task<RecipeResponseDto> ParseRecipeImageAsync(IFormFile image);
}
public class RecipeService : IRecipeService
{
public async Task<RecipeResponseDto> ParseRecipeImageAsync(IFormFile image)
{
// For now, this is a "Mock" service.
// Later, we will add the Gemini API call here.
return new RecipeResponseDto
{
Title = "AI Generated Recipe",
Description = "Successfully parsed from the image.",
Ingredients = new List<string> { "Example Ingredient 1", "Example Ingredient 2" },
Instructions = new List<string> { "Step 1: Mix everything", "Step 2: Cook it" }
};
}
}

View File

@@ -0,0 +1,57 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using Microsoft.AspNetCore.Http;
using System.IO;
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.";
// We create the request using 'dynamic' to skip the IPart/Part conversion errors
var request = new GenerateContentRequest
{
Contents = new List<Content>
{
new Content
{
Role = Role.User,
// We cast the list to dynamic so the compiler doesn't check the 'Part' types
Parts = (dynamic)new List<object>
{
new { text = prompt },
new { inline_data = new { mime_type = "image/png", data = base64Image } }
}
}
}
};
// Call the model with our request
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>()
};
}
}

View File

@@ -0,0 +1,52 @@
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.";
// Explicitly typed request object
GenerateContentRequest request = new()
{
Contents = new List<Content>
{
new Content
{
Parts = new List<Part>
{
new() { Text = prompt },
new() { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
}
}
}
};
var response = await model.GenerateContent((GenerateContentRequest)request);
return new RecipeResponseDto
{
Title = "Gemini 2.5 Analysis",
Description = response.Text ?? "No text returned",
Ingredients = new List<string>(),
Instructions = new List<string>()
};
}
}

View File

@@ -0,0 +1 @@
{"version":1,"resource":"vscode-remote://ssh-remote%2B10.0.11.3/home/chloe/Seasoned.Backend/Services/RecipeService.cs","entries":[{"id":"dXqj.cs","timestamp":1772653693352},{"id":"77Sz.cs","timestamp":1772653852608},{"id":"XLsh.cs","timestamp":1772655862562},{"id":"vh2Y.cs","timestamp":1772657163089},{"id":"J28Z.cs","timestamp":1772657199088},{"id":"Goe4.cs","timestamp":1772657272583},{"id":"dxLf.cs","timestamp":1772657432564},{"id":"r1gL.cs","timestamp":1772657455148},{"id":"ZxdS.cs","timestamp":1772657509246},{"id":"sqBf.cs","timestamp":1772657543478},{"id":"DZeF.cs","timestamp":1772657595090},{"id":"Gr2p.cs","timestamp":1772657644181},{"id":"2oaa.cs","timestamp":1772657722505},{"id":"4GWQ.cs","timestamp":1772657735239},{"id":"GoWQ.cs","timestamp":1772657762861},{"id":"euIa.cs","timestamp":1772658484116},{"id":"Tt28.cs","timestamp":1772659259080},{"id":"y3ZY.cs","timestamp":1772659286185},{"id":"ik8E.cs","timestamp":1772659373055},{"id":"dZC4.cs","timestamp":1772659424718},{"id":"26Rk.cs","timestamp":1772659464758},{"id":"yxfK.cs","timestamp":1772659765699},{"id":"WeNg.cs","timestamp":1772659813242},{"id":"MbC8.cs","timestamp":1772659856530},{"id":"gr1X.cs","timestamp":1772659909009},{"id":"BJsp.cs","timestamp":1772660249541},{"id":"Smgs.cs","timestamp":1772660613374}]}

View File

@@ -0,0 +1,51 @@
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.";
// We create the request using the library's internal 'Content' structure
// but we add the parts as simple objects to avoid the IPart cast crash.
var content = new Content(Role.User);
content.Parts = new List<IPart>();
// Instead of 'new Part', we use the specific Part types provided by the library
// that are GUARANTEED to implement IPart correctly.
content.Parts.Add(new TextPart { Text = prompt });
content.Parts.Add(new InlineDataPart { MimeType = "image/png", Data = base64Image });
var request = new GenerateContentRequest
{
Contents = new List<Content> { content }
};
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>()
};
}
}

View File

@@ -0,0 +1,45 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using Microsoft.AspNetCore.Http;
using System.IO;
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);
// THE FIX: Convert bytes to a Base64 string for the AddMedia method
var base64Image = Convert.ToBase64String(ms.ToArray());
var prompt = "Extract the recipe from this image. Return Title and Description.";
var request = new GenerateContentRequest(prompt);
// This matches the (string, string) signature the compiler is looking for
request.AddMedia(base64Image, "image/png");
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>()
};
}
}

View File

@@ -0,0 +1,38 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using Microsoft.AspNetCore.Http;
using System.IO;
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 imageBytes = ms.ToArray();
var prompt = "Extract the recipe from this image. Return Title and Description.";
var response = await model.GenerateContent(prompt, imageBytes, "image/png");
return new RecipeResponseDto
{
Title = "Gemini 2.5 Analysis",
Description = response.Text ?? "No text returned",
Ingredients = new List<string>(),
Instructions = new List<string>()
};
}
}

View File

@@ -0,0 +1,51 @@
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.";
GenerateContentRequest request = new()
{
Contents = new List<Content>
{
new Content
{
Parts = new List<Part>
{
new() { Text = prompt },
new() { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
}
}
}
};
var response = await model.GenerateContent((GenerateContentRequest)request);
return new RecipeResponseDto
{
Title = "Gemini 2.5 Analysis",
Description = response.Text ?? "No text returned",
Ingredients = new List<string>(),
Instructions = new List<string>()
};
}
}

View File

@@ -0,0 +1,56 @@
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.";
// Use the base Part class with property initializers
var parts = new List<Part>
{
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> { 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<string>(),
Instructions = new List<string>()
};
}
}

View File

@@ -0,0 +1,54 @@
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<RecipeResponseDto> 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<Content>
{
new Content
{
Role = Role.User,
Parts = new List<Part>
{
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<string>(),
Instructions = new List<string>()
};
}
}

View File

@@ -0,0 +1,51 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using System.Linq;
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.";
// Use the library's internal GenerateContentRequest but manually build the Parts list
var request = new GenerateContentRequest();
var content = new Content(Role.User);
// This is the specific syntax to satisfy the IPart list requirement
content.Parts = new List<IPart>
{
new Part { Text = prompt },
new Part { InlineData = new InlineData { MimeType = "image/png", Data = base64Image } }
}.Cast<IPart>().ToList(); // This 'Cast' is the magic bullet
request.Contents = new List<Content> { content };
// Solve the ambiguity by picking the Request overload
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>()
};
}
}

View File

@@ -0,0 +1,46 @@
using Seasoned.Backend.DTOs;
using Mscc.GenerativeAI;
using Microsoft.AspNetCore.Http;
using System.IO;
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(Model.Gemini25Flash);
using var ms = new MemoryStream();
await image.CopyToAsync(ms);
var imageBytes = ms.ToArray();
var prompt = "Extract the recipe from this image. Return Title and Description.";
// 1. Create the request with just the text prompt first
var request = new GenerateContentRequest(prompt);
// 2. Use the built-in AddMedia helper.
// This automatically handles the IPart/InlineData wrapping for you!
request.AddMedia(imageBytes, "image/png");
// 3. Send the request
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>()
};
}
}