Add full application: receipt scanning, auth, billing, and account deletion
Brings the working codebase (Next.js app, auth system, Stripe billing, Docker/deploy config, tests, docs) into version control on top of the placeholder initial commit, and adds account self-deletion (Danger Zone in Settings, password + typed-email confirmation, cascading DB cleanup, Stripe cancellation) per GDPR right-to-erasure. Excludes local build caches, node_modules, and internal agent scratch files; .gitignore hardened to keep those out going forward. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
59
scripts/test_json_mode.mjs
Normal file
59
scripts/test_json_mode.mjs
Normal file
@@ -0,0 +1,59 @@
|
||||
import fs from "fs";
|
||||
import { generateObject } from "ai";
|
||||
import { createOpenAI } from "@ai-sdk/openai";
|
||||
import { ReceiptExtractionSchema } from "../src/lib/schema/receipt.ts";
|
||||
|
||||
const envContent = fs.readFileSync(".env.local", "utf-8");
|
||||
const apiKeyMatch = envContent.match(/OPENROUTER_API_KEY=([^\r\n]+)/);
|
||||
const apiKey = apiKeyMatch ? apiKeyMatch[1].trim() : "";
|
||||
|
||||
const demoImgPath = "public/demo/01_aral_tankbeleg_muenchen.jpg";
|
||||
const imgBase64 = fs.readFileSync(demoImgPath).toString("base64");
|
||||
const dataUrl = `data:image/jpeg;base64,${imgBase64}`;
|
||||
|
||||
async function testJsonMode() {
|
||||
console.log("Testing generateObject with mode: 'json' on OpenRouter...");
|
||||
|
||||
const openrouter = createOpenAI({
|
||||
apiKey,
|
||||
baseURL: "https://openrouter.ai/api/v1",
|
||||
headers: {
|
||||
"HTTP-Referer": "http://localhost:3000",
|
||||
"X-Title": "Receipt Scanner to Excel",
|
||||
},
|
||||
});
|
||||
|
||||
const { object } = await generateObject({
|
||||
model: openrouter("openai/gpt-4o-mini"),
|
||||
schema: ReceiptExtractionSchema,
|
||||
mode: "json",
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: `Du bist ein hochpräziser KI-Belegscanner. Extrahiere alle Belegdaten vollständig im vorgegebenen JSON-Format:
|
||||
- merchant (name, address, taxId, confidence 0-1)
|
||||
- date (isoDate YYYY-MM-DD, time, confidence 0-1)
|
||||
- documentType (KASSENBON, RECHNUNG, TANKBELEG, BEWIRTUNGSBELEG, PARKTICKET, SONSTIGES)
|
||||
- receiptNumber
|
||||
- currency (EUR)
|
||||
- totalAmount (value, confidence 0-1)
|
||||
- netAmount
|
||||
- taxBreakdown (array mit ratePercent, taxAmount, netAmount)
|
||||
- lineItems (array mit description, quantity, price, taxRate)
|
||||
- suggestedCategory (Bewirtung, Reisekosten & Hotel, Tanken & KFZ, Bürobedarf & IT, Verpflegungsmehraufwand, Material & Einkauf, Sonstiges)
|
||||
- validation (isMathValid, isDuplicateSuspected, needsUserReview, reviewField, reviewReason)`,
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "text", text: "Extrahiere diesen Beleg vollständig als JSON:" },
|
||||
{ type: "image", image: dataUrl },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.log("✓ SUCCESS! Extracted Object:\n", JSON.stringify(object, null, 2));
|
||||
}
|
||||
|
||||
testJsonMode().catch(console.error);
|
||||
Reference in New Issue
Block a user