server: (webui) use Map() to store file content
This commit is contained in:
parent
8d721dcca8
commit
b7a0c02658
3 changed files with 11 additions and 11 deletions
Binary file not shown.
|
@ -173,12 +173,12 @@
|
||||||
</div>
|
</div>
|
||||||
<!-- section to display uploaded files -->
|
<!-- section to display uploaded files -->
|
||||||
<div class="flex flex-wrap">
|
<div class="flex flex-wrap">
|
||||||
<div v-for="(file, index) in uploadedFiles" :key="index" class="flex items-center mr-4 mb-2">
|
<div v-for="([fileName, text]) in Array.from(fileTextMap.entries())" :key="fileName" class="flex items-center mr-4 mb-2">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 text-blue-500">
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 text-blue-500">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" d="M12 3.75v16.5m4.5-4.5H7.5M9 21h6a3 3 0 003-3V6a3 3 0 00-3-3H9a3 3 0 00-3 3v12a3 3 0 003 3z" />
|
<path stroke-linecap="round" stroke-linejoin="round" d="M12 3.75v16.5m4.5-4.5H7.5M9 21h6a3 3 0 003-3V6a3 3 0 00-3-3H9a3 3 0 00-3 3v12a3 3 0 003 3z" />
|
||||||
</svg>
|
</svg>
|
||||||
<span class="text-sm ml-1">{{ file.name }}</span>
|
<span class="text-sm ml-1">{{ fileName }}</span>
|
||||||
<button @click="removeFile(index)" class="ml-2 text-grey-500 hover:text-red-700">
|
<button @click="removeFile(fileName)" class="ml-2 text-grey-500 hover:text-red-700">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||||
</svg>
|
</svg>
|
||||||
|
|
|
@ -392,8 +392,7 @@ const mainApp = createApp({
|
||||||
viewingConvId: StorageUtils.getNewConvId(),
|
viewingConvId: StorageUtils.getNewConvId(),
|
||||||
inputMsg: '',
|
inputMsg: '',
|
||||||
isGenerating: false,
|
isGenerating: false,
|
||||||
uploadedFiles: [],
|
fileTextMap: new Map(),
|
||||||
fileText: '',
|
|
||||||
/** @type {Array<Message> | null} */
|
/** @type {Array<Message> | null} */
|
||||||
pendingMsg: null, // the on-going message from assistant
|
pendingMsg: null, // the on-going message from assistant
|
||||||
stopGeneration: () => {},
|
stopGeneration: () => {},
|
||||||
|
@ -474,8 +473,8 @@ const mainApp = createApp({
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
},
|
},
|
||||||
removeFile(index){
|
removeFile(filename){
|
||||||
this.uploadedFiles.splice(index, 1);
|
this.fileTextMap.delete(filename);
|
||||||
},
|
},
|
||||||
async handlePdfUpload(event) {
|
async handlePdfUpload(event) {
|
||||||
const file = event.target.files[0];
|
const file = event.target.files[0];
|
||||||
|
@ -488,8 +487,7 @@ const mainApp = createApp({
|
||||||
console.log("PDF loaded:", pdfDocument);
|
console.log("PDF loaded:", pdfDocument);
|
||||||
const pdfPromise = extractPdfText(file);
|
const pdfPromise = extractPdfText(file);
|
||||||
pdfPromise.then((data) => {
|
pdfPromise.then((data) => {
|
||||||
this.uploadedFiles.push(file);
|
this.fileTextMap.set(file.name, data);
|
||||||
this.fileText += data;
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
|
@ -507,16 +505,18 @@ const mainApp = createApp({
|
||||||
async sendMessage() {
|
async sendMessage() {
|
||||||
if (!this.inputMsg) return;
|
if (!this.inputMsg) return;
|
||||||
const currConvId = this.viewingConvId;
|
const currConvId = this.viewingConvId;
|
||||||
|
const fileTexts = await Promise.all([...this.fileTextMap.values()]);
|
||||||
|
const combinedFileText = fileTexts.join('\n');
|
||||||
|
|
||||||
StorageUtils.appendMsg(currConvId, {
|
StorageUtils.appendMsg(currConvId, {
|
||||||
id: Date.now(),
|
id: Date.now(),
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: this.fileText + '\n' + this.inputMsg,
|
content: combinedFileText + '\n' + this.inputMsg,
|
||||||
});
|
});
|
||||||
this.fetchConversation();
|
this.fetchConversation();
|
||||||
this.fetchMessages();
|
this.fetchMessages();
|
||||||
this.inputMsg = '';
|
this.inputMsg = '';
|
||||||
this.uploadedFiles = [];
|
this.fileTextMap.clear();
|
||||||
this.fileText = '';
|
this.fileText = '';
|
||||||
this.generateMessage(currConvId);
|
this.generateMessage(currConvId);
|
||||||
chatScrollToBottom();
|
chatScrollToBottom();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue