Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formats to json schema validator #47

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions frontend/app/components/CreateExtractor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ import Form from "@rjsf/chakra-ui";
import validator from "@rjsf/validator-ajv8";
import CodeMirror from "@uiw/react-codemirror";
import Ajv from "ajv";
import addFormats from "ajv-formats";
import React from "react";
import { useRouter } from "next/navigation";

import { ChatBubbleBottomCenterTextIcon } from "@heroicons/react/24/outline";
import { useMutation } from "@tanstack/react-query";
import { suggestExtractor, useCreateExtractor } from "../utils/api";

const ajc = new Ajv();
const ajv = new Ajv();
// Adds support for parsing format types like "date-time"
// and "email" in JSON Schema.
// A lot of the JSON Schema generated by LLMS will
// be generated with these formats out of the box.
addFormats(ajv);

/**
* Component to create a new extractor with fields
Expand Down Expand Up @@ -70,7 +76,7 @@ const CreateExtractor = ({}) => {
React.useMemo(() => {
try {
const parsedSchema = JSON.parse(schema);
ajc.compile(parsedSchema);
ajv.compile(parsedSchema);
setCurrentSchemaValid(true);
setLastValidSchema(parsedSchema);
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@types/react-dom": "18.2.7",
"@uiw/react-codemirror": "^4.21.24",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"autoprefixer": "10.4.14",
"axios": "^1.6.8",
"chakra-react-select": "^4.7.6",
Expand Down
1 change: 1 addition & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5514,6 +5514,7 @@ __metadata:
"@typescript-eslint/parser": ^7.3.0
"@uiw/react-codemirror": ^4.21.24
ajv: ^8.12.0
ajv-formats: ^2.1.1
autoprefixer: 10.4.14
axios: ^1.6.8
chakra-react-select: ^4.7.6
Expand Down
Loading