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

Extract report data from the PDF document using AI #45

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ yarn-error.log*
/frontend/.env
/dist/
/local/
/scripts/node_modules
/scripts/samplesAnalysisReport.jsonl
13 changes: 13 additions & 0 deletions database/migrations/017-analysis-ia-additionnal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Knex } from 'knex';

exports.up = async (knex: Knex) => {
await knex.schema.table('analysis_residues', (table) => {
table.string('original_name');
});
};

exports.down = async (knex: Knex) => {
await knex.schema.table('analysis_residues', (table) => {
table.dropColumn('original_name');
});
};
2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="apple-touch-icon" href="/dsfr/favicon/apple-touch-icon.png?v=1.12.1" />
<link rel="icon" href="/dsfr/favicon/favicon.svg?v=1.12.1" type="image/svg+xml" />
<link rel="shortcut icon" href="/dsfr/favicon/favicon.ico?v=1.12.1" type="image/x-icon" />
<link rel="stylesheet" href="/dsfr/utility/icons/icons.min.css?hash=b3cc982" />
<link rel="stylesheet" href="/dsfr/utility/icons/icons.min.css?hash=878660e6" />
<link rel="stylesheet" href="/dsfr/dsfr.min.css?v=1.12.1" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" />

Expand Down
12 changes: 12 additions & 0 deletions frontend/src/services/analysis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
PartialAnalysis,
} from 'shared/schema/Analysis/Analysis';
import { api } from 'src/services/api.service';
import { authParams } from 'src/services/auth-headers';
import config from 'src/utils/config';
import { getURLQuery } from 'src/utils/fetchUtils';

export const analysisApi = api.injectEndpoints({
endpoints: (builder) => ({
Expand Down Expand Up @@ -49,10 +52,19 @@ export const analysisApi = api.injectEndpoints({
}),
});

const analysisExtractURL = (analysis: PartialAnalysis) => {
const params = getURLQuery({
...authParams(),
});
return `${config.apiEndpoint}/api/analysis/${analysis.id}/extract${params}`;
};

export const {
useGetSampleAnalysisQuery,
useCreateAnalysisMutation,
useUpdateAnalysisMutation,
getAnalysisExtractURL,
} = {
...analysisApi,
getAnalysisExtractURL: analysisExtractURL,
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import Button from '@codegouvfr/react-dsfr/Button';
import { cx } from '@codegouvfr/react-dsfr/fr/cx';
import Stepper from '@codegouvfr/react-dsfr/Stepper';
import { useEffect, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { PartialAnalysis } from 'shared/schema/Analysis/Analysis';
import { AnalysisStatus } from 'shared/schema/Analysis/AnalysisStatus';
import { Sample } from 'shared/schema/Sample/Sample';
import { useGetSampleAnalysisQuery } from 'src/services/analysis.service';
import {
getAnalysisExtractURL,
useGetSampleAnalysisQuery,
} from 'src/services/analysis.service';
import AnalysisComplianceStep from 'src/views/SampleView/SampleAnalysis/SampleDraftAnalysis/AnalysisComplianceStep/AnalysisComplianceStep';
import AnalysisReportStep from 'src/views/SampleView/SampleAnalysis/SampleDraftAnalysis/AnalysisReportStep/AnalysisReportStep';
import AnalysisResiduesStep from 'src/views/SampleView/SampleAnalysis/SampleDraftAnalysis/AnalysisResiduesStep/AnalysisResiduesStep';
Expand Down Expand Up @@ -46,6 +50,17 @@ const SampleDraftAnalysis = ({ sample }: Props) => {

return (
<>
{partialAnalysis?.id && (
<Button
className={cx('fr-mr-2w')}
linkProps={{
to: getAnalysisExtractURL(partialAnalysis as PartialAnalysis),
target: '_blank',
}}
>
Test extraction
</Button>
)}
<h4 className={cx('fr-mb-0')}>
Saisie des résultats d’analyse
<div className={cx('fr-text--md', 'fr-text--regular')}>
Expand Down
154 changes: 151 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
"lodash": "^4.17.21",
"node-fetch": "^2.6.7",
"nodemailer": "^6.9.13",
"openai": "^4.61.1",
"pdf-parse": "^1.1.1",
"pg": "^8.7.3",
"puppeteer": "^22.11.2",
"randomstring": "^1.2.1",
Expand All @@ -82,6 +84,7 @@
"@types/node": "^20.11.30",
"@types/node-fetch": "^2.5.12",
"@types/nodemailer": "^6.4.15",
"@types/pdf-parse": "^1.1.4",
"@types/randomstring": "^1.1.8",
"@types/supertest": "^2.0.12",
"@types/uuid": "^8.3.4",
Expand Down
Loading
Loading