From 29d0d2157de1356559a7e439ba0fe2684aff9d33 Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Fri, 25 Oct 2024 12:20:37 +0200 Subject: [PATCH 01/14] feat: load features from JSON file --- server/utils/menu-items.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/utils/menu-items.ts b/server/utils/menu-items.ts index fe9580d..3fb6acc 100644 --- a/server/utils/menu-items.ts +++ b/server/utils/menu-items.ts @@ -1,4 +1,6 @@ import { authorizationHeaders, apiUrl } from '~/server/utils/api-client'; +import fs from 'fs'; +import path from 'path'; function chatbotItems(response): Array { return response.map((item) => { @@ -15,6 +17,12 @@ function chatbotItems(response): Array { } function featureItems() { + const jsonFeatureItemsPath = path.resolve(process.cwd(), 'feature_items.json'); + if (fs.existsSync(jsonFeatureItemsPath)) { + const fileContents = fs.readFileSync(jsonFeatureItemsPath, 'utf8'); + return JSON.parse(fileContents); + } + return [ { type: 'features', From 318a62a3498829dc1b1a5ae3d032045bbe251d47 Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Fri, 25 Oct 2024 12:20:54 +0200 Subject: [PATCH 02/14] chore: features JSON sample --- .gitignore | 2 ++ feature_items.json.sample | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 feature_items.json.sample diff --git a/.gitignore b/.gitignore index dca1251..1727e4d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ node_modules .DS_Store .history .vscode + +feature_items.json diff --git a/feature_items.json.sample b/feature_items.json.sample new file mode 100644 index 0000000..b071981 --- /dev/null +++ b/feature_items.json.sample @@ -0,0 +1,28 @@ +[ + { + "type" : "features", + "attributes" : { + "feature_type" : "analysis", + "uname" : "summary", + "title" : "Document Summary", + "description" : "Upload a PDF document, even one with many pages, to get a textual summary." + } + }, + { + "type" : "features", + "attributes" : { + "feature_type" : "analysis", + "uname" : "questionnaire", + "title" : "Questionnaire Generator", + "description" : "Upload a PDF or TXT file and get a questionnaire with multiple questions and answers on the text provided", + "feature_params": { + "service": "services.GenerateQuestionsService", + "accept": "application/pdf,text/plain", + "payload": { + "max_duration": 60, + "max_attempts": 3 + } + } + } + } +] From b95f6c60765dc2c7e8b052ee94d3e06792295555 Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Fri, 25 Oct 2024 12:21:29 +0200 Subject: [PATCH 03/14] fix: minor anlysis + summary adjustments --- pages/analysis/[id].vue | 16 ++++++++-------- pages/summary/[id].vue | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pages/analysis/[id].vue b/pages/analysis/[id].vue index b114601..a837a05 100644 --- a/pages/analysis/[id].vue +++ b/pages/analysis/[id].vue @@ -68,7 +68,6 @@ const INTERVAL = 15000; // 15 seconds in ms const result = ref(null); const file = ref(null); const isBusy = ref(false); -const summary = ref(null); const jobId = ref(null); const jobData = ref(null); const jobName = ref(''); @@ -81,6 +80,7 @@ const store = useStatesStore(); const fileDrop = ref(null); const { $createPdf } = useNuxtApp(); +const { t } = useI18n(); onBeforeRouteLeave(() => { stopPolling(); @@ -134,8 +134,8 @@ const elapsedTime = computed(() => { }); const reset = () => { + result.value = null; file.value = null; - summary.value = null; error.value = ''; isBusy.value = false; jobData.value = null; @@ -214,9 +214,9 @@ const submit = async () => { store.setJobInfo(jobName.value, { id: jobId.value, file: { name: file.value?.name } }); startPolling(); } - } catch (error) { - error.value = error; - console.log(error); + } catch (err) { + error.value = t('AN_ERROR_OCCURRED_PLEASE_RETRY'); + console.log(err); } }; @@ -248,9 +248,9 @@ const readJobData = async () => { updateJobsLeft(); } } - } catch (error) { - error.value = error; - console.log(error); + } catch (err) { + error.value = t('AN_ERROR_OCCURRED_PLEASE_RETRY'); + console.log(err); } }; diff --git a/pages/summary/[id].vue b/pages/summary/[id].vue index f574c79..49c6b18 100644 --- a/pages/summary/[id].vue +++ b/pages/summary/[id].vue @@ -13,7 +13,6 @@ :accept-types="acceptTypes" @file-change="file = $event" /> - />
From 7b339347d2132876d7bd1a9829e0dcd0c53b3263 Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Fri, 25 Oct 2024 15:52:40 +0200 Subject: [PATCH 04/14] chore: review feature format --- feature_items.json.sample | 34 ++++++++++++++-------------------- server/utils/menu-items.ts | 9 ++++++++- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/feature_items.json.sample b/feature_items.json.sample index b071981..bde23ec 100644 --- a/feature_items.json.sample +++ b/feature_items.json.sample @@ -1,27 +1,21 @@ [ { - "type" : "features", - "attributes" : { - "feature_type" : "analysis", - "uname" : "summary", - "title" : "Document Summary", - "description" : "Upload a PDF document, even one with many pages, to get a textual summary." - } + "feature_type": "analysis", + "uname": "summary", + "title": "Document Summary", + "description": "Upload a PDF document, even one with many pages, to get a textual summary." }, { - "type" : "features", - "attributes" : { - "feature_type" : "analysis", - "uname" : "questionnaire", - "title" : "Questionnaire Generator", - "description" : "Upload a PDF or TXT file and get a questionnaire with multiple questions and answers on the text provided", - "feature_params": { - "service": "services.GenerateQuestionsService", - "accept": "application/pdf,text/plain", - "payload": { - "max_duration": 60, - "max_attempts": 3 - } + "feature_type": "analysis", + "uname": "questionnaire", + "title": "Questionnaire Generator", + "description": "Upload a PDF or TXT file and get a questionnaire with multiple questions and answers on the text provided", + "feature_params": { + "service": "services.GenerateQuestionsService", + "accept": "application/pdf,text/plain", + "payload": { + "max_duration": 60, + "max_attempts": 3 } } } diff --git a/server/utils/menu-items.ts b/server/utils/menu-items.ts index 3fb6acc..defc16b 100644 --- a/server/utils/menu-items.ts +++ b/server/utils/menu-items.ts @@ -20,7 +20,14 @@ function featureItems() { const jsonFeatureItemsPath = path.resolve(process.cwd(), 'feature_items.json'); if (fs.existsSync(jsonFeatureItemsPath)) { const fileContents = fs.readFileSync(jsonFeatureItemsPath, 'utf8'); - return JSON.parse(fileContents); + const featureItems = JSON.parse(fileContents); + + return featureItems.map((item: any) => { + return { + type: 'features', + attributes: item, + }; + }); } return [ From 8226e05408d695779c134e7fdd6584b385b8142c Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Wed, 13 Nov 2024 14:53:23 +0100 Subject: [PATCH 05/14] feat: display API versions in footer --- components/Main/Footer.vue | 9 +++++++-- server/api/brevia/versions.get.ts | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 server/api/brevia/versions.get.ts diff --git a/components/Main/Footer.vue b/components/Main/Footer.vue index 601c141..96251ea 100644 --- a/components/Main/Footer.vue +++ b/components/Main/Footer.vue @@ -32,12 +32,17 @@
- v{{ version }} + Brevia App: {{ appVersion }} + Brevia API: {{ data.brevia }} + {{ data?.apiName }} API: {{ data?.apiVersion }}
diff --git a/server/api/brevia/versions.get.ts b/server/api/brevia/versions.get.ts new file mode 100644 index 0000000..0bc47f5 --- /dev/null +++ b/server/api/brevia/versions.get.ts @@ -0,0 +1,16 @@ +export default defineEventHandler(async (event) => { + try { + const response: Response = await fetch(apiUrl('/status'), { + method: 'HEAD', + headers: authorizationHeaders(), + }); + + return { + 'brevia': response.headers.get('X-Brevia-Version'), + 'apiName': response.headers.get('X-API-Name'), + 'apiVersion': response.headers.get('X-API-Version'), + } + } catch (error) { + return handleApiError(event, error); + } +}); From 6d7d739aacee6192c88a14f98bef315f82180f7c Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Wed, 13 Nov 2024 15:03:24 +0100 Subject: [PATCH 06/14] chore: prettier --- components/Main/Footer.vue | 4 +++- server/api/brevia/versions.get.ts | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/Main/Footer.vue b/components/Main/Footer.vue index 96251ea..6154c49 100644 --- a/components/Main/Footer.vue +++ b/components/Main/Footer.vue @@ -34,7 +34,9 @@
Brevia App: {{ appVersion }} Brevia API: {{ data.brevia }} - {{ data?.apiName }} API: {{ data?.apiVersion }} + + {{ data?.apiName }} API: {{ data?.apiVersion }} +
diff --git a/server/api/brevia/versions.get.ts b/server/api/brevia/versions.get.ts index 0bc47f5..80bdba6 100644 --- a/server/api/brevia/versions.get.ts +++ b/server/api/brevia/versions.get.ts @@ -6,10 +6,10 @@ export default defineEventHandler(async (event) => { }); return { - 'brevia': response.headers.get('X-Brevia-Version'), - 'apiName': response.headers.get('X-API-Name'), - 'apiVersion': response.headers.get('X-API-Version'), - } + brevia: response.headers.get('X-Brevia-Version'), + apiName: response.headers.get('X-API-Name'), + apiVersion: response.headers.get('X-API-Version'), + }; } catch (error) { return handleApiError(event, error); } From ae6a9304be534179a3aeb159b45db64dacf6a362 Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Wed, 13 Nov 2024 15:31:04 +0100 Subject: [PATCH 07/14] chore: rename to `versions` --- components/Main/Footer.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/Main/Footer.vue b/components/Main/Footer.vue index 6154c49..90e6c48 100644 --- a/components/Main/Footer.vue +++ b/components/Main/Footer.vue @@ -33,9 +33,9 @@
Brevia App: {{ appVersion }} - Brevia API: {{ data.brevia }} - - {{ data?.apiName }} API: {{ data?.apiVersion }} + Brevia API: {{ versions.brevia }} + + {{ versions?.apiName }} API: {{ versions?.apiVersion }}
@@ -46,5 +46,5 @@ const cookiesPrivacyTerms = useRuntimeConfig().public.cookiesPrivacyTerms !== '' const appVersion = useRuntimeConfig().public.version; const response = await fetch('/api/brevia/versions'); -const data = await response.json(); +const versions = await response.json(); From 314a10f49d6bae03d687b30906b68e7cb0496770 Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Wed, 13 Nov 2024 18:58:56 +0100 Subject: [PATCH 08/14] feat: add integration versions --- components/Main/Footer.vue | 10 ++++++++++ composables/integration-version.ts | 9 +++++++++ modules/bedita/index.ts | 4 ++++ .../runtime/server/api/bedita/versions.get.ts | 14 ++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 composables/integration-version.ts create mode 100644 modules/bedita/runtime/server/api/bedita/versions.get.ts diff --git a/components/Main/Footer.vue b/components/Main/Footer.vue index 90e6c48..9e00db6 100644 --- a/components/Main/Footer.vue +++ b/components/Main/Footer.vue @@ -38,6 +38,13 @@ {{ versions?.apiName }} API: {{ versions?.apiVersion }} + +
+ {{ integration }} API: {{ integrationVersions?.get(integration) }} + + {{ integrationVersions?.get('apiName') }} API: {{ integrationVersions?.get('apiVersion') }} + +
diff --git a/composables/integration-version.ts b/composables/integration-version.ts new file mode 100644 index 0000000..1b7ed1a --- /dev/null +++ b/composables/integration-version.ts @@ -0,0 +1,9 @@ +export const useIntegrationVersion = async (): Promise> => { + const integration = useIntegration(); + if (integration === 'brevia') { + return new Map(); + } + const response: any = await $fetch(`/api/${integration}/versions`); + + return new Map(Object.entries(response)); +}; diff --git a/modules/bedita/index.ts b/modules/bedita/index.ts index 63d8719..8f120fb 100644 --- a/modules/bedita/index.ts +++ b/modules/bedita/index.ts @@ -106,6 +106,10 @@ export default defineNuxtModule({ './runtime/server/api/bedita/index/[collection_id]/[document_id].delete', ), }, + { + route: '/api/bedita/versions', + handler: resolver.resolve('./runtime/server/api/bedita/versions.get'), + }, ]; endpointsEnabled.forEach((endpoint) => { diff --git a/modules/bedita/runtime/server/api/bedita/versions.get.ts b/modules/bedita/runtime/server/api/bedita/versions.get.ts new file mode 100644 index 0000000..ac0cf92 --- /dev/null +++ b/modules/bedita/runtime/server/api/bedita/versions.get.ts @@ -0,0 +1,14 @@ +export default defineEventHandler(async (event) => { + try { + const client = await beditaApiClient(event); + const response = await client.get('/home'); + + return { + bedita: response.headers.get('X-BEdita-Version'), + apiName: response.headers.get('X-API-Name'), + apiVersion: response.headers.get('X-API-Version'), + }; + } catch (error) { + return handleBeditaApiError(event, error); + } +}); From b758ca0addcb99a84229a14119d282ebf4308a23 Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Thu, 12 Dec 2024 16:46:49 +0100 Subject: [PATCH 09/14] feat: system info modal for admin users --- components/AppModal.vue | 1 + components/Dialog/SystemInfo.vue | 54 +++++++++++++++++++ components/Main/Footer.vue | 25 +++------ locales/en/messages.json | 1 + locales/it/messages.json | 1 + .../runtime/server/api/bedita/versions.get.ts | 1 + server/api/brevia/versions.get.ts | 1 + 7 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 components/Dialog/SystemInfo.vue diff --git a/components/AppModal.vue b/components/AppModal.vue index 41b9a13..30c8ca0 100644 --- a/components/AppModal.vue +++ b/components/AppModal.vue @@ -15,6 +15,7 @@ + diff --git a/components/Dialog/SystemInfo.vue b/components/Dialog/SystemInfo.vue new file mode 100644 index 0000000..ba8cd50 --- /dev/null +++ b/components/Dialog/SystemInfo.vue @@ -0,0 +1,54 @@ + + + diff --git a/components/Main/Footer.vue b/components/Main/Footer.vue index 9e00db6..0a8bd19 100644 --- a/components/Main/Footer.vue +++ b/components/Main/Footer.vue @@ -32,29 +32,18 @@
- Brevia App: {{ appVersion }} - Brevia API: {{ versions.brevia }} - - {{ versions?.apiName }} API: {{ versions?.apiVersion }} - -
- -
- {{ integration }} API: {{ integrationVersions?.get(integration) }} - - {{ integrationVersions?.get('apiName') }} API: {{ integrationVersions?.get('apiVersion') }} + + + {{ appVersion }} + + + v{{ appVersion }}
diff --git a/locales/en/messages.json b/locales/en/messages.json index dc51f9a..114ffa7 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -152,6 +152,7 @@ "START_DATE": "Start date", "SUCCESS": "Success", "SUMMARIZATION": "summarization", + "SYSTEM_INFO": "System info", "TERMS_AND_CONDITIONS": "Terms & Conditions", "TERMS_OF_SERVICE": "Terms of Service", "TEXT_SUMMARY": "Text summary", diff --git a/locales/it/messages.json b/locales/it/messages.json index d868f9e..fe5dc25 100644 --- a/locales/it/messages.json +++ b/locales/it/messages.json @@ -152,6 +152,7 @@ "START_DATE": "Data iniziale", "SUCCESS": "Ok", "SUMMARIZATION": "Creazione sommario", + "SYSTEM_INFO": "Informazioni di sistema", "TERMS_AND_CONDITIONS": "Termini e Condizioni", "TERMS_OF_SERVICE": "Termini di servizio", "TEXT_SUMMARY": "Riassunto", diff --git a/modules/bedita/runtime/server/api/bedita/versions.get.ts b/modules/bedita/runtime/server/api/bedita/versions.get.ts index ac0cf92..4e96146 100644 --- a/modules/bedita/runtime/server/api/bedita/versions.get.ts +++ b/modules/bedita/runtime/server/api/bedita/versions.get.ts @@ -7,6 +7,7 @@ export default defineEventHandler(async (event) => { bedita: response.headers.get('X-BEdita-Version'), apiName: response.headers.get('X-API-Name'), apiVersion: response.headers.get('X-API-Version'), + baseUrl: useRuntimeConfig().bedita.apiBaseUrl, }; } catch (error) { return handleBeditaApiError(event, error); diff --git a/server/api/brevia/versions.get.ts b/server/api/brevia/versions.get.ts index 80bdba6..1df14a8 100644 --- a/server/api/brevia/versions.get.ts +++ b/server/api/brevia/versions.get.ts @@ -9,6 +9,7 @@ export default defineEventHandler(async (event) => { brevia: response.headers.get('X-Brevia-Version'), apiName: response.headers.get('X-API-Name'), apiVersion: response.headers.get('X-API-Version'), + baseUrl: useRuntimeConfig().apiBaseUrl, }; } catch (error) { return handleApiError(event, error); From 035e930d4c3a3f3a1637a507020109cf75b95c18 Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Thu, 12 Dec 2024 16:48:41 +0100 Subject: [PATCH 10/14] chore: prettier + eslint --- components/Dialog/SystemInfo.vue | 20 +++++++++++++++----- components/Main/Footer.vue | 2 +- composables/integration-version.ts | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/components/Dialog/SystemInfo.vue b/components/Dialog/SystemInfo.vue index ba8cd50..f5245af 100644 --- a/components/Dialog/SystemInfo.vue +++ b/components/Dialog/SystemInfo.vue @@ -6,18 +6,24 @@
- Brevia App v{{ appVersion }} + + Brevia App v{{ appVersion }} +

@@ -29,11 +35,15 @@
diff --git a/components/Main/Footer.vue b/components/Main/Footer.vue index 0a8bd19..47d10cf 100644 --- a/components/Main/Footer.vue +++ b/components/Main/Footer.vue @@ -33,7 +33,7 @@
- + {{ appVersion }} diff --git a/composables/integration-version.ts b/composables/integration-version.ts index 1b7ed1a..d177f3f 100644 --- a/composables/integration-version.ts +++ b/composables/integration-version.ts @@ -1,4 +1,4 @@ -export const useIntegrationVersion = async (): Promise> => { +export const useIntegrationVersion = async (): Promise> => { const integration = useIntegration(); if (integration === 'brevia') { return new Map(); From 4241548b86dbfa058472e8b1883010a8cc0d2893 Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Thu, 12 Dec 2024 18:13:26 +0100 Subject: [PATCH 11/14] chore: use v{{ appVersion }}
From 364f58cb10bda2e4d61274a1ee21140da27fd9c5 Mon Sep 17 00:00:00 2001 From: BuonDavide Date: Thu, 12 Dec 2024 17:26:33 +0000 Subject: [PATCH 12/14] chore: update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a463da9..dd962a6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "brevia-app", "private": true, - "version": "0.4.1", + "version": "0.4.2", "scripts": { "build": "nuxt build", "dev": "nuxt dev", From 4d19cd7c7642cceb3f4316940a0aea559a71056a Mon Sep 17 00:00:00 2001 From: stefanorosanelli Date: Thu, 12 Dec 2024 18:59:19 +0100 Subject: [PATCH 13/14] chore: improve feature JSON sample --- feature_items.json.sample | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/feature_items.json.sample b/feature_items.json.sample index bde23ec..bb54239 100644 --- a/feature_items.json.sample +++ b/feature_items.json.sample @@ -1,22 +1,40 @@ [ { - "feature_type": "analysis", + "feature_type": "summary", "uname": "summary", "title": "Document Summary", - "description": "Upload a PDF document, even one with many pages, to get a textual summary." + "description": "" + }, + { + "feature_type": "transcription", + "uname": "transcription", + "title": "Audio Transcription", + "description": "" }, { "feature_type": "analysis", - "uname": "questionnaire", - "title": "Questionnaire Generator", + "uname": "questions_generator", + "title": "Questions Generator", "description": "Upload a PDF or TXT file and get a questionnaire with multiple questions and answers on the text provided", "feature_params": { - "service": "services.GenerateQuestionsService", + "service": "brevia.services.RefineTextAnalysisService", "accept": "application/pdf,text/plain", "payload": { "max_duration": 60, "max_attempts": 3 } + }, + "prompts": { + "initial_prompt": { + "_type": "prompt", + "input_variables": ["text"], + "template": "Analyze the following text and generate 1-2 multiple choice questions, each with four options\n(A, B, C, D), of which only one is correct.\nHighlight the correct answer and make sure that the questions are relevant and understandable.\n\nReference text:\n-------------------\n{text}\n" + }, + "refine_prompt": { + "_type": "prompt", + "input_variables": ["existing_answer", "text"], + "template": "You are given the following partial document containing a list of multiple choice questions:\nPartial Document:\n-------------------\n{existing_answer}\n-------------------\nRewrite the list of questions by adding 1-2 more questions at the bottom from the context provided below:\n\n-------------\n{text}\n-------------------" + } } } ] From 01afa7a1b3dbcc6f87d60a3e8eb8147adfcf73d0 Mon Sep 17 00:00:00 2001 From: nikazzio Date: Fri, 13 Dec 2024 14:24:01 +0000 Subject: [PATCH 14/14] chore: update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dd962a6..921a1db 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "brevia-app", "private": true, - "version": "0.4.2", + "version": "0.5.0", "scripts": { "build": "nuxt build", "dev": "nuxt dev",