From fb49fb596a56955ca70eac9da47d2826299469e1 Mon Sep 17 00:00:00 2001 From: Mert Demir Date: Mon, 5 Feb 2024 02:23:11 +0900 Subject: Automatic category from expense title (#80) * environment variable * random category draft * get category from ai * input limit and documentation * use watch * use field.name * prettier * presigned upload, readme warning, category to string util * prettier * check whether feature is enabled * use process.env * improved prompt to return id only * remove console.debug * show loader * share class name * prettier * use template literals * rename format util * prettier --- src/lib/env.ts | 9 +++++++-- src/lib/utils.ts | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/env.ts b/src/lib/env.ts index f1d59db..927e756 100644 --- a/src/lib/env.ts +++ b/src/lib/env.ts @@ -19,6 +19,7 @@ const envSchema = z S3_UPLOAD_REGION: z.string().optional(), S3_UPLOAD_ENDPOINT: z.string().optional(), NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT: z.coerce.boolean().default(false), + NEXT_PUBLIC_ENABLE_CATEGORY_EXTRACT: z.coerce.boolean().default(false), OPENAI_API_KEY: z.string().optional(), }) .superRefine((env, ctx) => { @@ -36,11 +37,15 @@ const envSchema = z 'If NEXT_PUBLIC_ENABLE_EXPENSE_DOCUMENTS is specified, then S3_* must be specified too', }) } - if (env.NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT && !env.OPENAI_API_KEY) { + if ( + (env.NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT || + env.NEXT_PUBLIC_ENABLE_CATEGORY_EXTRACT) && + !env.OPENAI_API_KEY + ) { ctx.addIssue({ code: ZodIssueCode.custom, message: - 'If NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT is specified, then OPENAI_API_KEY must be specified too', + 'If NEXT_PUBLIC_ENABLE_RECEIPT_EXTRACT or NEXT_PUBLIC_ENABLE_CATEGORY_EXTRACT is specified, then OPENAI_API_KEY must be specified too', }) } }) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d0b32e2..39477d1 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,3 +1,4 @@ +import { Category } from '@prisma/client' import { clsx, type ClassValue } from 'clsx' import { twMerge } from 'tailwind-merge' @@ -15,3 +16,7 @@ export function formatExpenseDate(date: Date) { timeZone: 'UTC', }) } + +export function formatCategoryForAIPrompt(category: Category) { + return `"${category.grouping}/${category.name}" (ID: ${category.id})` +} -- cgit v1.3