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

UI to use mimetype configuration #71

Merged
merged 4 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions backend/server/api/configurables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

from fastapi import APIRouter
from typing_extensions import Annotated, TypedDict
from typing_extensions import TypedDict

from extraction.parsing import MAX_FILE_SIZE_MB, SUPPORTED_MIMETYPES
from server.models import SUPPORTED_MODELS
Expand All @@ -18,7 +18,7 @@ class ConfigurationResponse(TypedDict):
"""Response for configuration."""

available_models: List[str]
supported_mimetypes: List[str]
accepted_mimetypes: List[str]
max_file_size_mb: int


Expand All @@ -27,6 +27,6 @@ def get() -> ConfigurationResponse:
"""Endpoint to show server configuration."""
return {
"available_models": sorted(SUPPORTED_MODELS),
"supported_mimetypes": SUPPORTED_MIMETYPES,
"accepted_mimetypes": SUPPORTED_MIMETYPES,
"max_file_size_mb": MAX_FILE_SIZE_MB,
}
2 changes: 1 addition & 1 deletion backend/tests/unit_tests/api/test_api_configurables.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def test_configuration_api() -> None:
assert sorted(result) == [
"available_models",
"max_file_size_mb",
"supported_mimetypes",
"accepted_mimetypes",
]
models = result["available_models"]
assert all(isinstance(model_name, str) for model_name in models)
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/unit_tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tests.unit_tests.fixtures import get_sample_paths


def test_list_of_supported_mimetypes() -> None:
def test_list_of_accepted_mimetypes() -> None:
"""This list should generally grow! Protecting against typos in mimetypes."""
assert SUPPORTED_MIMETYPES == [
# Two MS Word mimetypes are disabled for now
Expand Down
30 changes: 24 additions & 6 deletions frontend/app/components/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
"use client";

import {
Button,
Textarea,
Heading,
Tab,
Tabs,
Box,
Divider,
AbsoluteCenter,
TabList,
TabPanel,
TabPanels,
Tabs,
Text,
Textarea,
} from "@chakra-ui/react";
import { useMutation } from "@tanstack/react-query";
import React from "react";
import SyntaxHighlighter from "react-syntax-highlighter";
import { docco } from "react-syntax-highlighter/dist/esm/styles/hljs";
import { runExtraction } from "../utils/api";
import { runExtraction, useConfiguration } from "../utils/api";
import { Extractor } from "./Extractor";
import { ResultsTable } from "./ResultsTable";

Expand All @@ -36,7 +38,10 @@ export const Playground = (props: PlaygroundProps) => {
const { data, isPending, mutate } = useMutation({
mutationFn: runExtraction,
});

const requestServerConfig = useConfiguration();
const [isDisabled, setIsDisabled] = React.useState(false);

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

Expand Down Expand Up @@ -93,13 +98,26 @@ export const Playground = (props: PlaygroundProps) => {
<div>
<Extractor extractorId={extractorId} isShared={isShared} />
</div>
<Heading>Upload Content</Heading>
<form
className="m-auto flex flex-col content-between gap-5 mt-10 mb-10"
onSubmit={handleSubmit}
onChange={handleChange}
>
<input type="file" name="file" className="file-input " />
<div className="divider">OR</div>
{requestServerConfig.isFetched && (
<input
type="file"
name="file"
className="file-input"
accept={requestServerConfig.data?.accepted_mimetypes.join(", ")}
/>
)}
<Box position="relative" padding="10">
<Divider />
<AbsoluteCenter bg="white" px="4">
OR
</AbsoluteCenter>
</Box>
<Textarea
placeholder="Enter text to extract information from..."
name="text"
Expand Down
19 changes: 19 additions & 0 deletions frontend/app/utils/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ const createExtractor: MutationFunction<any, any> = async (extractor) => {
return response.data;
};

export type ServerConfiguration = {
available_models: string[];
max_file_size_mb: number;
accepted_mimetypes: string[];
};

const getConfiguration = async (): Promise<ServerConfiguration> => {
const baseUrl = getBaseApiUrl();
const response = await axios.get(`${baseUrl}/configuration`);
return response.data;
};

export const useConfiguration = () => {
return useQuery({
queryKey: ["getConfiguration"],
queryFn: getConfiguration,
});
};

export const suggestExtractor = async ({
description,
jsonSchema,
Expand Down
Loading