mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 13:25:18 +00:00
feat: split into multiple items
This commit is contained in:
28
ai/schema.ts
28
ai/schema.ts
@@ -2,16 +2,30 @@ import { Field } from "@/prisma/client"
|
||||
|
||||
export const fieldsToJsonSchema = (fields: Field[]) => {
|
||||
const fieldsWithPrompt = fields.filter((field) => field.llm_prompt)
|
||||
const schemaProperties = fieldsWithPrompt.reduce(
|
||||
(acc, field) => {
|
||||
acc[field.code] = { type: field.type, description: field.llm_prompt || "" }
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, { type: string; description: string }>
|
||||
)
|
||||
|
||||
const schema = {
|
||||
type: "object",
|
||||
properties: fieldsWithPrompt.reduce(
|
||||
(acc, field) => {
|
||||
acc[field.code] = { type: field.type, description: field.llm_prompt || "" }
|
||||
return acc
|
||||
properties: {
|
||||
...schemaProperties,
|
||||
items: {
|
||||
type: "array",
|
||||
description: "Included items or products in the transaction which have own name and price",
|
||||
items: {
|
||||
type: "object",
|
||||
properties: schemaProperties,
|
||||
required: [...Object.keys(schemaProperties)],
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
{} as Record<string, { type: string; description: string }>
|
||||
),
|
||||
required: fieldsWithPrompt.map((field) => field.code),
|
||||
},
|
||||
required: [...Object.keys(schemaProperties), "items"],
|
||||
additionalProperties: false,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user