Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ylovato01 committed May 2, 2024
2 parents 0eb673a + 23130e4 commit 9d3fff1
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 329 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
from typing import List

from chatsql.application.port.outcoming.persistance.BaseEmbeddingRepository import BaseEmbeddingRepository

import os
import numpy as np
from chatsql.domain.Embedding import Embedding
from chatsql.application.port.outcoming.persistance.BaseEmbeddingRepository import BaseEmbeddingRepository
from chatsql.utils import Exceptions

class EmbeddingRepositoryAdapter(BaseEmbeddingRepository):

def __init__(self, folder: str) -> None:
self._folder = folder

def save(self, filename: str, embeddings: List[Embedding]) -> bool:
raise NotImplementedError()
try:
filepath = os.path.join(self._folder, filename)
np.save(filepath, embeddings)
return True
except Exception as e:
raise Exceptions.FileNotSaved(f"Error while saving embeddings to {filename}: {e}")

def load(self, filename: str) -> List[Embedding]:
raise NotImplementedError()
try:
filepath = os.path.join(self._folder, filename)
embeddings = np.load(filepath, allow_pickle=True)
return embeddings.tolist() # Convert to list of Embedding objects
except Exception as e:
raise Exceptions.EmbeddingsNotLoaded(f"Error while loading embeddings from {filename}: {e}")

def remove(self, filename: str) -> bool:
raise NotImplementedError()

try:
filepath = os.path.join(self._folder, filename)
os.remove(filepath)
return True
except Exception as e:
raise Exceptions.FileNotRemoved(f"Error while removing embeddings file {filename}: {e}. Check if permissions are correct.")
15 changes: 15 additions & 0 deletions backend/chatsql/utils/Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@ def __init__(self, message="Invalid file structure"):
class FileAlreadyUploaded(CustomException):

def __init__(self, message="File Already uploaded"):
super().__init__(message)

class FileNotSaved(CustomException):

def __init__(self, message="Error saving file"):
super().__init__(message)

class EmbeddingsNotLoaded(CustomException):

def __init__(self, message="Error during embeddings loading from file"):
super().__init__(message)

class FileNotRemoved(CustomException):

def __init__(self, message="Error removing file. Check if permissions are correct"):
super().__init__(message)
6 changes: 5 additions & 1 deletion frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ module.exports = {
// Directory dove Jest deve mettere i risultati della copertura
coverageDirectory: '<rootDir>/coverage',

transformIgnorePatterns: ['node_modules/(?!(axios)/)'],
transformIgnorePatterns: [
'node_modules/(?!(axios)/)',
'/node_modules/(?!(bootstrap)/)',
'\\.css$'
],
}
14 changes: 0 additions & 14 deletions frontend/src/components/InputFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<input type="file" class="form-control" ref="fileInput" @change="handleFileUpload" />
<upload-button ref="uploadbtn" :class="uploadButtonClass" @upload-click="emitFile" :disabled="!file" :isuploading="isUploading"/>
</div>
<p>{{ message }}</p>
</div>
</template>

Expand Down Expand Up @@ -33,7 +32,6 @@ export default {
* @property {ref} isUploading - A reference to a boolean indicating if the file is currently being uploaded.
*/
const file = ref(null);
const message = ref(' ');
const isUploading = ref(false);
/**
Expand All @@ -43,7 +41,6 @@ export default {
* @param {Event} event - The file upload event.
*/
function handleFileUpload(event) {
this.changeMessage('');
file.value = event.target.files[0];
}
Expand All @@ -60,15 +57,6 @@ export default {
}
}
/**
* Updates the value of the message.
*
* @param {string} newMessage - The new message value.
*/
function changeMessage(newMessage) {
message.value = newMessage;
}
/**
* Sets the value of the isUploading reactive variable.
*
Expand All @@ -81,10 +69,8 @@ export default {
return {
file,
message,
handleFileUpload,
emitFile,
changeMessage,
isUploading,
setIsUploading
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/LoadButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default {
*
* @param {number} id - The ID of the dictionary to load.
*/
function loadDictionary(id) {
emit('load-click', id);
function loadDictionary() {
emit('load-click', props.id);
}
return {
Expand Down
76 changes: 39 additions & 37 deletions frontend/src/components/ToastPopup.vue
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
<template ref="Toast">
<div class="toast align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
{{ Message }}
<template>
<div ref="toast" class="toast align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
{{ Message }}
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" aria-label="Close" data-bs-dismiss="toast"></button>
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</template>

<script>
import { ref } from 'vue';
import 'bootstrap/dist/css/bootstrap.min.css';
import * as bootstrap from 'bootstrap';
export default {
name: 'ToastPopup',
setup() {
/**
* Represents a reactive reference to a message.
* @type {Ref<string>}
*/
const Message = ref('');
name: 'ToastPopup',
setup() {
/**
* Represents a reactive reference to a message.
* @type {Ref<string>}
*/
const Message = ref('');
/**
* Shows a toast notification.
*/
function showToast() {
const toastEl = document.querySelector('.toast');
/**
* Shows a toast message.
*/
function showToast() {
const toastEl = document.querySelector('.toast');
if (toastEl) {
const toast = new bootstrap.Toast(toastEl);
toast.show();
}
}
/**
* Sets the value of the Message variable to the specified message.
*
* @param {string} message - The message to set.
*/
function setTest(message){
Message.value=message;
}
return{
showToast,
setTest,
Message
}
/**
* Sets the value of the Message variable to the specified message.
*
* @param {string} message - The message to set the Message variable to.
*/
function setTest(message) {
Message.value = message;
}
}
</script>
return {
showToast,
setTest,
Message
};
}
};
</script>
10 changes: 0 additions & 10 deletions frontend/tests/unit/__snapshots__/sendrequestbutton.spec.js.snap

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9d3fff1

Please sign in to comment.