Spaces:
Runtime error
Runtime error
Thomas G. Lopes
commited on
Commit
·
92d7705
1
Parent(s):
c6c1fff
working file upload
Browse files
src/lib/components/inference-playground/message-textarea.svelte
CHANGED
|
@@ -2,6 +2,8 @@
|
|
| 2 |
import { autofocus } from "$lib/attachments/autofocus.js";
|
| 3 |
import { TextareaAutosize } from "$lib/spells/textarea-autosize.svelte.js";
|
| 4 |
import { conversations } from "$lib/state/conversations.svelte";
|
|
|
|
|
|
|
| 5 |
import { fileToDataURL } from "$lib/utils/file.js";
|
| 6 |
import { cmdOrCtrl } from "$lib/utils/platform.js";
|
| 7 |
import { FileUpload } from "melt/builders";
|
|
@@ -24,11 +26,36 @@
|
|
| 24 |
}
|
| 25 |
}
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
async function sendMessage() {
|
| 28 |
const c = conversations.active;
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
c.forEach(c => c.genNextMessage());
|
| 31 |
input = "";
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
const canUploadImgs = $derived(conversations.active.every(c => c.supportsImgUpload));
|
|
|
|
| 2 |
import { autofocus } from "$lib/attachments/autofocus.js";
|
| 3 |
import { TextareaAutosize } from "$lib/spells/textarea-autosize.svelte.js";
|
| 4 |
import { conversations } from "$lib/state/conversations.svelte";
|
| 5 |
+
import { images } from "$lib/state/images.svelte";
|
| 6 |
+
import type { ConversationMessage } from "$lib/types.js";
|
| 7 |
import { fileToDataURL } from "$lib/utils/file.js";
|
| 8 |
import { cmdOrCtrl } from "$lib/utils/platform.js";
|
| 9 |
import { FileUpload } from "melt/builders";
|
|
|
|
| 26 |
}
|
| 27 |
}
|
| 28 |
|
| 29 |
+
async function uploadImages() {
|
| 30 |
+
const keys: string[] = [];
|
| 31 |
+
const files = Array.from(fileUpload.selected);
|
| 32 |
+
await Promise.all(
|
| 33 |
+
files.map(async file => {
|
| 34 |
+
const key = await images.upload(file);
|
| 35 |
+
keys.push(key);
|
| 36 |
+
}),
|
| 37 |
+
);
|
| 38 |
+
return keys;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
async function sendMessage() {
|
| 42 |
const c = conversations.active;
|
| 43 |
+
|
| 44 |
+
let images: string[] | undefined;
|
| 45 |
+
if (canUploadImgs) {
|
| 46 |
+
images = await uploadImages();
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
const message: ConversationMessage = { role: "user", content: input };
|
| 50 |
+
if (images) {
|
| 51 |
+
message.images = images;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
await Promise.all(c.map(c => c.addMessage(message)));
|
| 55 |
c.forEach(c => c.genNextMessage());
|
| 56 |
input = "";
|
| 57 |
+
|
| 58 |
+
fileUpload.clear();
|
| 59 |
}
|
| 60 |
|
| 61 |
const canUploadImgs = $derived(conversations.active.every(c => c.supportsImgUpload));
|