Skip to content

Commit

Permalink
Merge branch 'main' into feat/209-pagina-embeddings-chatbot
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanorosanelli committed Dec 13, 2024
2 parents 1b5ccd3 + 01afa7a commit 47d8490
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ node_modules
.DS_Store
.history
.vscode

feature_items.json
1 change: 1 addition & 0 deletions components/AppModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<LazyDialogShowFeedback v-if="$isOpenModal('ShowAnswerFeedback')" v-bind="modalStore.activeModalProps" />
<LazyDialogChatDocuments v-if="$isOpenModal('ChatDocuments')" v-bind="modalStore.activeModalProps" @enlarge-window="largerModal = true" />
<LazyDialogDocumentChunks v-if="$isOpenModal('SeeDocumentChunks')" v-bind="modalStore.activeModalProps" @enlarge-window="largerModal = true" />
<LazyDialogSystemInfo v-if="$isOpenModal('DialogSystemInfo')" v-bind="modalStore.activeModalProps" />
</div>
</div>
</div>
Expand Down
64 changes: 64 additions & 0 deletions components/Dialog/SystemInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<div class="space-y-8 leading-tight">
<div class="flex justify-between items-center pb-4 mb-4 s\m:mb-5">
<h3 class="text-xl font-semibold text-gray-900">{{ $t('SYSTEM_INFO') }}</h3>
<Icon class="text-2xl hover:cursor-pointer hover:bg-sky-100" name="ph:x-bold" @click="$closeModal()" />
</div>

<div class="gap-3 tracking-wider">
<span class="col-span-3 justify-self-end whitespace-nowrap">
Brevia App <strong>v{{ appVersion }}</strong>
</span>
</div>

<hr class="border-t border-gray-300" />

<div class="gap-3 tracking-wider">
<template v-if="versions?.brevia">
<span class="col-span-3 justify-self-end whitespace-nowrap">
Brevia API <strong>v{{ versions.brevia }}</strong>
</span>
<br />
</template>
<template v-if="versions?.apiName && versions?.apiVersion">
<span class="col-span-3 justify-self-end whitespace-nowrap">
{{ versions.apiName }} API <strong>v{{ versions.apiVersion }}</strong>
</span>
<br />
</template>
<span class="col-span-3 justify-self-end whitespace-nowrap">
API Base URL <strong>{{ versions.baseUrl }}</strong>
</span>
</div>

<hr v-if="integration !== 'brevia'" class="border-t border-gray-300" />

<div v-if="integration !== 'brevia'" class="gap-3 tracking-wider">
<template v-if="integrationVersions?.get(integration)">
<span class="col-span-3 justify-self-end whitespace-nowrap">
{{ integrationName }} API <strong>v{{ integrationVersions?.get(integration) }}</strong>
</span>
<br />
</template>
<template v-if="integrationVersions?.get('apiName') && integrationVersions?.get('apiVersion')">
<span class="col-span-3 justify-self-end whitespace-nowrap">
{{ integrationVersions?.get('apiName') }} API <strong>v{{ integrationVersions?.get('apiVersion') }}</strong>
</span>
<br />
</template>
<span class="col-span-3 justify-self-end whitespace-nowrap">
API Base URL <strong>{{ integrationVersions?.get('baseUrl') }}</strong>
</span>
</div>
</div>
</template>

<script lang="ts" setup>
const appVersion = useRuntimeConfig().public.version;
const response = await fetch('/api/brevia/versions');
const versions = await response.json();
const integration = useIntegration();
const integrationName = integration.charAt(0).toUpperCase() + integration.slice(1);
const integrationVersions = await useIntegrationVersion();
</script>
12 changes: 9 additions & 3 deletions components/Main/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@
</div>

<div class="flex gap-3 text-xs tracking-wider text-white">
<span class="col-span-3 justify-self-end whitespace-nowrap"> v{{ version }} </span>
<span v-if="statesStore.userHasRole('admin')" class="col-span-3 justify-self-end whitespace-nowrap">
<button @click="$openModal('DialogSystemInfo')">
{{ appVersion }}
<Icon name="ph:info-bold" />
</button>
</span>
<span v-else class="col-span-3 justify-self-end whitespace-nowrap"> v{{ appVersion }} </span>
</div>
</footer>
</template>
<script setup lang="ts">
const cookiesPrivacyTerms = useRuntimeConfig().public.cookiesPrivacyTerms !== '';
const version = useRuntimeConfig().public.version;
const appVersion = useRuntimeConfig().public.version;
const statesStore = useStatesStore();
</script>
9 changes: 9 additions & 0 deletions composables/integration-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const useIntegrationVersion = async (): Promise<Map<string, string>> => {
const integration = useIntegration();
if (integration === 'brevia') {
return new Map();
}
const response: any = await $fetch(`/api/${integration}/versions`);

return new Map(Object.entries(response));
};
40 changes: 40 additions & 0 deletions feature_items.json.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"feature_type": "summary",
"uname": "summary",
"title": "Document Summary",
"description": ""
},
{
"feature_type": "transcription",
"uname": "transcription",
"title": "Audio Transcription",
"description": ""
},
{
"feature_type": "analysis",
"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": "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-------------------"
}
}
}
]
1 change: 1 addition & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions modules/bedita/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export default defineNuxtModule<ModuleOptions>({
'./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) => {
Expand Down
15 changes: 15 additions & 0 deletions modules/bedita/runtime/server/api/bedita/versions.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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'),
baseUrl: useRuntimeConfig().bedita.apiBaseUrl,
};
} catch (error) {
return handleBeditaApiError(event, error);
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "brevia-app",
"private": true,
"version": "0.4.1",
"version": "0.5.0",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
Expand Down
16 changes: 8 additions & 8 deletions pages/analysis/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand All @@ -81,6 +80,7 @@ const store = useStatesStore();
const fileDrop = ref(null);
const { $createPdf } = useNuxtApp();
const { t } = useI18n();
onBeforeRouteLeave(() => {
stopPolling();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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);
}
};
</script>
1 change: 0 additions & 1 deletion pages/summary/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
:accept-types="acceptTypes"
@file-change="file = $event"
/>
/>
</div>

<div v-if="menuItem?.params?.payload?.prompts" class="flex flex-col justify-center gap-6">
Expand Down
17 changes: 17 additions & 0 deletions server/api/brevia/versions.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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'),
baseUrl: useRuntimeConfig().apiBaseUrl,
};
} catch (error) {
return handleApiError(event, error);
}
});
15 changes: 15 additions & 0 deletions server/utils/menu-items.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { authorizationHeaders, apiUrl } from '~/server/utils/api-client';
import fs from 'fs';
import path from 'path';

function chatbotItems(response): Array<any> {
return response.map((item) => {
Expand All @@ -15,6 +17,19 @@ function chatbotItems(response): Array<any> {
}

function featureItems() {
const jsonFeatureItemsPath = path.resolve(process.cwd(), 'feature_items.json');
if (fs.existsSync(jsonFeatureItemsPath)) {
const fileContents = fs.readFileSync(jsonFeatureItemsPath, 'utf8');
const featureItems = JSON.parse(fileContents);

return featureItems.map((item: any) => {
return {
type: 'features',
attributes: item,
};
});
}

return [
{
type: 'features',
Expand Down

0 comments on commit 47d8490

Please sign in to comment.