Skip to content

Commit

Permalink
feat(kb): Main page with creation and persistence on Aleph
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Jul 31, 2024
1 parent 0f9ed31 commit d7a2f27
Show file tree
Hide file tree
Showing 15 changed files with 3,687 additions and 4,989 deletions.
8,346 changes: 3,443 additions & 4,903 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,47 @@
"@aleph-sdk/message": "^1.0.7",
"@libertai/libertai-js": "0.0.9",
"@quasar/extras": "^1.16.12",
"@tanstack/vue-query": "^5.51.9",
"@wagmi/vue": "^0.0.31",
"@tanstack/vue-query": "^5.51.15",
"@wagmi/vue": "^0.0.34",
"axios": "^1.7.2",
"dayjs": "^1.11.12",
"dompurify": "^3.1.6",
"highlight.js": "^11.10.0",
"localforage": "^1.10.0",
"marked": "^12.0.2",
"marked-highlight": "^2.1.3",
"mime": "^4.0.4",
"pdfjs-dist": "^4.4.168",
"pinia": "^2.1.7",
"pdfjs-dist": "^4.5.136",
"pinia": "^2.2.0",
"pinia-plugin-persistedstate": "^3.2.1",
"quasar": "^2.16.6",
"stream": "^0.0.3",
"uuid": "^10.0.0",
"viem": "^2.17.10",
"vue": "^3.4.33",
"viem": "^2.18.5",
"vue": "^3.4.34",
"vue-router": "^4.4.0",
"web3": "^4.11.0",
"web3": "^4.11.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@quasar/app-vite": "^1.9.3",
"@types/dompurify": "^3.0.5",
"@types/node": "^20.14.11",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@types/node": "^20.14.13",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vue/eslint-config-typescript": "^13.0.0",
"autoprefixer": "^10.4.19",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-vue": "^9.27.0",
"postcss": "^8.4.39",
"postcss": "^8.4.40",
"prettier": "^3.3.3",
"tailwindcss": "^3.4.6",
"tailwindcss": "^3.4.7",
"typescript": "^5.5.4",
"vite-plugin-checker": "^0.7.2",
"vite-plugin-node-polyfills": "^0.22.0",
"vue-eslint-parser": "^9.4.3",
"vue-tsc": "^2.0.28"
"vue-tsc": "^2.0.29"
},
"overrides": {
"vite": "^4.0.0",
Expand Down
7 changes: 7 additions & 0 deletions public/icons/svg/chevron-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions public/icons/svg/folder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion quasar.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = configure(function (/* ctx */) {
// app boot file (/src/boot)
// --> boot files are part of "main.js"
// https://v2.quasar.dev/quasar-cli-vite/boot-files
boot: ['wagmi'],
boot: ['utils', 'wagmi'],

// https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#css
css: ['app.scss', 'tailwind.css'],
Expand Down
18 changes: 10 additions & 8 deletions src/boot/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// import { boot } from 'quasar/wrappers';
// import KnowledgeStoreUploader from 'components/KnowledgeStoreUploader.ts';
// "async" is optional;
// more info on params: https://v2.quasar.dev/quasar-cli/boot-files
// export default boot(async ({ _app }) => {
// // something to do
// // app.component('KnowledgeStoreUploader', KnowledgeStoreUploader);
// });
import { boot } from 'quasar/wrappers';

import dayjs from 'dayjs';
import localizedFormat from 'dayjs/plugin/localizedFormat';
import relativeTime from 'dayjs/plugin/relativeTime';

export default boot(() => {
dayjs.extend(localizedFormat);
dayjs.extend(relativeTime);
});
53 changes: 53 additions & 0 deletions src/components/dialog/KnowledgeBaseCreationDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<q-dialog class="q-pa-lg text-light" style="flex-grow: 1">
<q-card class="q-pa-md">
<q-card-actions :class="`flex flex-left text-semibold ${$q.dark.mode ? '' : 'text-purple700'}`">
Create knowledge base
<q-space />
<q-btn
v-close-popup
:icon="`img:icons/svg/close${$q.dark.mode ? '_lighten' : ''}.svg`"
flat
size="sm"
unelevated
/>
</q-card-actions>

<q-card-section horizontal>
<q-card-section>
<span>Name</span>
<q-input v-model="name" bg-color="secondary" input-class="text-light q-px-sm" outlined></q-input>
</q-card-section>
</q-card-section>

<q-card-section class="text-primary tw-mt-4" horizontal>
<q-btn v-close-popup class="q-px-xl tw-py-1" label="Close" rounded />
<q-space />
<q-btn
v-close-popup
class="bg-primary q-px-xl tw-py-1"
label="Confirm"
rounded
text-color="white"
@click="createKnowledgeBase"
/>
</q-card-section>
</q-card>
</q-dialog>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { useQuasar } from 'quasar';
const $q = useQuasar();
const emit = defineEmits<{ create: [name: string] }>();
// Form values
const name = ref('');
const createKnowledgeBase = () => {
emit('create', name.value);
};
</script>
52 changes: 3 additions & 49 deletions src/pages/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<span v-if="message.author === 'user'">{{ chatRef.username }}</span>
<span v-else>{{ chatRef.persona.name }}</span>

<span class="bull-date">{{ formatDate(message.timestamp) }}</span>
<span class="bull-date">{{ dayjs().to(message.timestamp) }}</span>
</q-item-label>
<!-- Display any attachments -->
<q-item-label v-if="message.attachments && message.attachments.length > 0">
Expand Down Expand Up @@ -105,24 +105,12 @@
<div class="tw-mx-4">
<message-input :is-loading="isLoadingRef" class="col" @send-message="sendMessage" />
</div>

<!-- This should really not pass the ref, but it's a quick fix for now -->
<!-- <q-dialog v-model="showKnowledgeUploaderRef" position="bottom">-->
<!-- <KnowledgeStoreUploader-->
<!-- :chat-ref="chatRef"-->
<!-- auto-upload-->
<!-- label="Auto KnowledgeStoreUploader"-->
<!-- multiple-->
<!-- url="http://localhost:4444/upload"-->
<!-- @attachment-added="addAttachment"-->
<!-- />-->
<!-- </q-dialog>-->
</q-page>
</template>

<script lang="ts" setup>
import 'highlight.js/styles/devibeans.css';
import { copyToClipboard, date, DateUnitOptions, useQuasar } from 'quasar';
import { copyToClipboard, useQuasar } from 'quasar';
import { nextTick, onMounted, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
Expand All @@ -139,6 +127,7 @@ import axios from 'axios';
import { getPersonaAvatarUrl } from 'src/utils/personas';
import { useSettingsStore } from 'stores/settings';
import { Chat, SendMessageParams, UIMessage } from 'src/types/chats';
import dayjs from 'dayjs';
const $q = useQuasar();
const route = useRoute();
Expand All @@ -147,14 +136,12 @@ const router = useRouter();
// App state
const chatsStore = useChatsStore();
const modelsStore = useModelsStore();
// const knowledgeStore = useKnowledgeStore();
const settingsStore = useSettingsStore();
// Local page state
const isLoadingRef = ref(false);
const scrollAreaRef = ref<HTMLDivElement>();
const enableEditRef = ref(false);
// const showKnowledgeUploaderRef = ref(false);
const chatRef = ref<Chat>();
Expand Down Expand Up @@ -418,39 +405,6 @@ async function clearCookies() {
withCredentials: true,
});
}
// function openKnowledgeUploader() {
// showKnowledgeUploaderRef.value = true;
// }
// TODO: Replace this by using dayjs
function formatDate(d: string | undefined) {
const dateObj = d ? new Date(d) : new Date();
const currentDate = new Date();
const timeDiff = currentDate.getTime() / 1000 - dateObj.getTime() / 1000;
let unit: DateUnitOptions = 'hours';
let txtUnit = 'h';
if (timeDiff < 60) {
unit = 'seconds';
txtUnit = 's';
} else if (timeDiff < 3600) {
unit = 'minutes';
txtUnit = 'm';
} else if (timeDiff < 86400) {
unit = 'hours';
txtUnit = 'h';
} else if (timeDiff < 2592000) {
unit = 'days';
txtUnit = 'd';
} else if (timeDiff > 2592000) {
unit = 'months';
txtUnit = 'month';
}
const diff = date.getDateDiff(currentDate, dateObj, unit);
return diff + txtUnit;
}
</script>
<style>
/* Ensure message input expands to fill available space */
Expand Down
11 changes: 0 additions & 11 deletions src/pages/KnowledgeBase.vue

This file was deleted.

52 changes: 52 additions & 0 deletions src/pages/KnowledgeBasesList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<section class="max-sm:tw-mx-4 md:tw-mx-10 tw-my-5">
<h4 class="text-h4 text-semibold tw-mb-5">Knowledge base</h4>
<p>Manage your knowledge bases</p>
<div class="tw-mt-4 tw-mb-8 tw-flex md:tw-justify-end">
<q-btn
class="border-primary-highlight"
icon="img:icons/svg/add.svg"
label="Create knowledge base"
no-caps
rounded
unelevated
@click="createKnowledgeDialog = true"
/>
<knowledge-base-creation-dialog v-model="createKnowledgeDialog" @create="createKnowledgeBase" />
</div>

<div class="tw-space-y-4">
<RouterLink
v-for="knowledgeBase of knowledgeStore.knowledgeBases"
:key="knowledgeBase.id"
:to="`/knowledge-base/${knowledgeBase.id}`"
class="tw-block"
>
<div class="tw-flex tw-border tw-rounded-lg tw-p-4">
<img alt="folder" class="tw-mr-4" height="20" src="/icons/svg/folder.svg" width="20" />
<p class="tw-font-bold tw-text-base">{{ knowledgeBase.name }}</p>
<div class="tw-ml-auto tw-flex tw-gap-4">
<p>{{ knowledgeBase.documents.length }} File{{ knowledgeBase.documents.length !== 1 ? 's' : '' }}</p>
<p>Last updated: {{ dayjs(knowledgeBase.lastUpdatedAt).format('LL') }}</p>
<img alt="chevron" height="22" src="/icons/svg/chevron-right.svg" width="22" />
</div>
</div>
</RouterLink>
</div>
</section>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import KnowledgeBaseCreationDialog from 'components/dialog/KnowledgeBaseCreationDialog.vue';
import { useKnowledgeStore } from 'stores/knowledge';
import dayjs from 'dayjs';
const knowledgeStore = useKnowledgeStore();
const createKnowledgeDialog = ref(false);
const createKnowledgeBase = (name: string) => {
knowledgeStore.createKnowledgeBase(name);
};
</script>
4 changes: 2 additions & 2 deletions src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const routes = [
},
{
path: 'knowledge-base',
component: () => import('src/pages/KnowledgeBase.vue'),
component: () => import('pages/KnowledgeBasesList.vue'),
},
{
path: 'persona-management',
component: () => import('src/pages/PersonaManagement.vue'),
component: () => import('pages/PersonaManagement.vue'),
},
],
},
Expand Down
3 changes: 3 additions & 0 deletions src/stores/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getAccount, getBalance } from '@wagmi/core';
import { config } from 'src/config/wagmi';
import { base } from '@wagmi/vue/chains';
import { useTokensStore } from 'stores/tokens';
import { useKnowledgeStore } from 'stores/knowledge';

const LTAI_BASE_ADDRESS = '0xF8B1b47AA748F5C7b5D0e80C726a843913EB573a';

Expand All @@ -16,11 +17,13 @@ export const useAccountStore = defineStore('account', {
actions: {
async onAccountChange() {
const tokensStore = useTokensStore();
const knowledgeStore = useKnowledgeStore();

this.ltaiBalance = await this.getLTAIBalance();

await this.initAlephStorage();
await tokensStore.update();
await knowledgeStore.load();
},

async initAlephStorage() {
Expand Down
Loading

0 comments on commit d7a2f27

Please sign in to comment.