Skip to content

Commit

Permalink
refactor: Format with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-guan committed Dec 30, 2024
1 parent 7d69954 commit f78c09c
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 150 deletions.
9 changes: 8 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## Description

<!-- Provide a brief description of the changes introduced by this PR -->

## Related Issue

<!-- Link to the related issue (if applicable) using #issue_number -->

## Type of Change

<!-- Put an `x` in the boxes that apply -->

- [ ] Bug fix (non-breaking change which fixes an issue)
Expand All @@ -15,12 +18,15 @@
- [ ] Performance improvement

## How Has This Been Tested?

<!-- Describe the tests you ran to verify your changes -->

## Screenshots (if applicable)

<!-- Add screenshots to help explain your changes -->

## Checklist

<!-- Put an `x` in the boxes that apply -->

- [ ] My code follows the project's style guidelines
Expand All @@ -32,4 +38,5 @@
- [ ] New and existing unit tests pass locally with my changes

## Additional Notes
<!-- Add any additional notes or context about the PR here -->

<!-- Add any additional notes or context about the PR here -->
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Cambio Website Source

For Dev setup, please refer to this [Notion Page](https://www.notion.so/goldpiggy/TS-JS-Dev-Setup-ada0f7cdf74c424c8767ed692150cc88?pvs=4). You may need to request access, and you will only receive access if appropriate.

## Quick setup

- checkout a dev branch
- copy .env from 1password
- `npm install` for dependency
- `npm run dev` for local development and testing
- open `http://localhost:3000` in your browser
-
-
2 changes: 1 addition & 1 deletion app/actions/runSyncExtractKeyValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const runSyncExtractKeyValue = async ({
file_type: 'pdf',
extract_args: {
extract_instruction: extractInstruction,
}
},
};

const config = {
Expand Down
56 changes: 26 additions & 30 deletions app/components/playground/ExtractKeyValuePairContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ExtractKeyValuePairTutorial from '../tutorials/ExtractKeyValuePairTutoria

const downloadExtractedData = (formattedData: string, file?: PlaygroundFile['file']) => {
if (!formattedData) return;

const fileName = file instanceof File ? file.name : 'extracted_data';
const blob = new Blob([formattedData], { type: 'application/json' });
const url = URL.createObjectURL(blob);
Expand All @@ -33,7 +33,8 @@ const downloadExtractedData = (formattedData: string, file?: PlaygroundFile['fil
const ExtractKeyValuePairContainer = () => {
const [hideResult, setHideResult] = useState(false);
const { apiURL, isProduction } = useProductionContext();
const { selectedFileIndex, files, updateFileAtIndex, token, userId, clientId, addFilesFormData } = usePlaygroundStore();
const { selectedFileIndex, files, updateFileAtIndex, token, userId, clientId, addFilesFormData } =
usePlaygroundStore();

const selectedFile = useMemo(() => {
if (selectedFileIndex !== null && files.length > 0) {
Expand All @@ -44,7 +45,10 @@ const ExtractKeyValuePairContainer = () => {
useEffect(() => {
if (!selectedFile) return;

if (selectedFile.extractKeyValueState === ExtractState.EXTRACTING || selectedFile.extractKeyValueState === ExtractState.UPLOADING) {
if (
selectedFile.extractKeyValueState === ExtractState.EXTRACTING ||
selectedFile.extractKeyValueState === ExtractState.UPLOADING
) {
toast.loading('Extracting data...', { id: 'key-value-extracting-toast' });
} else {
toast.dismiss('key-value-extracting-toast');
Expand All @@ -53,7 +57,9 @@ const ExtractKeyValuePairContainer = () => {

const handleSuccess = async (response: any) => {
if (!response.data) {
toast.error(`${selectedFile?.file instanceof File ? selectedFile.file.name : 'File'}: Received undefined result. Please try again.`);
toast.error(
`${selectedFile?.file instanceof File ? selectedFile.file.name : 'File'}: Received undefined result. Please try again.`
);
updateFileAtIndex(selectedFileIndex, 'extractKeyValueState', ExtractState.READY);
return;
}
Expand Down Expand Up @@ -104,8 +110,8 @@ const ExtractKeyValuePairContainer = () => {

const jobParams: JobParams = {
vqaProcessorArgs: {
vqaExtractInstruction: extractInstruction
}
vqaExtractInstruction: extractInstruction,
},
};

// Upload file and get presigned url and metadata
Expand All @@ -116,7 +122,7 @@ const ExtractKeyValuePairContainer = () => {
file: file as File,
process_type: ProcessType.EXTRACT_KEY_VALUE,
extractArgs: {
extractInstruction
extractInstruction,
},
addFilesFormData,
});
Expand Down Expand Up @@ -153,7 +159,6 @@ const ExtractKeyValuePairContainer = () => {
// Run the async job based on environment
const runJob = isProduction ? runAsyncRequestJob : runPreprodAsyncRequestJob;
await runJob(jobConfig);

} catch (error) {
toast.error('Extraction failed. Please try again.');
console.error(error);
Expand All @@ -173,38 +178,26 @@ const ExtractKeyValuePairContainer = () => {
<ExtractKeyValuePairTutorial />
{fileUrl && (hideResult || !selectedFile?.extractKeyValueResult) && (
<div>
<DocumentViewer
<DocumentViewer
fileType={selectedFile?.file instanceof File ? selectedFile.file.type : 'pdf'}
fileUrl={fileUrl}
/>
{selectedFile?.extractKeyValueResult && (
<div className="absolute bottom-4 left-4">
<Button
label="Back to Result"
labelIcon={ArrowLeft}
onClick={() => setHideResult(false)}
/>
<Button label="Back to Result" labelIcon={ArrowLeft} onClick={() => setHideResult(false)} />
</div>
)}
</div>
)}
{!hideResult && selectedFile?.extractKeyValueResult && (
<div className="pb-24">
<CodeBlock
language="json"
code={selectedFile?.extractKeyValueResult}
aria-label="Extraction Result"
/>
<CodeBlock language="json" code={selectedFile?.extractKeyValueResult} aria-label="Extraction Result" />
<div className="absolute bottom-4 left-4 flex gap-2 w-fit">
<Button
label="Back to File"
labelIcon={ArrowLeft}
onClick={() => setHideResult(true)}
/>
<Button
label="Download"
labelIcon={Download}
onClick={() => downloadExtractedData(selectedFile?.extractKeyValueResult, selectedFile?.file)}
<Button label="Back to File" labelIcon={ArrowLeft} onClick={() => setHideResult(true)} />
<Button
label="Download"
labelIcon={Download}
onClick={() => downloadExtractedData(selectedFile?.extractKeyValueResult, selectedFile?.file)}
/>
</div>
</div>
Expand All @@ -213,9 +206,12 @@ const ExtractKeyValuePairContainer = () => {
<div className="h-[calc(100%-1rem)] min-w-60 max-w-72 w-[18vw] p-4 rounded-2xl shadow-[0px_0px_4px_2px_rgba(0,_0,_0,_0.1)] absolute top-4 right-0">
<div className="w-full max-h-full overflow-hidden flex flex-col gap-4">
<div className="flex flex-col gap-2">
<KeyValueInputs
<KeyValueInputs
onSubmit={onSubmit}
isLoading={selectedFile?.extractKeyValueState === ExtractState.EXTRACTING || selectedFile?.extractKeyValueState === ExtractState.UPLOADING}
isLoading={
selectedFile?.extractKeyValueState === ExtractState.EXTRACTING ||
selectedFile?.extractKeyValueState === ExtractState.UPLOADING
}
/>
</div>
</div>
Expand Down
Loading

0 comments on commit f78c09c

Please sign in to comment.