Spaces:
Paused
Paused
add file upload support
Browse files- src/lib/agents/evalBuilder.ts +20 -29
- src/routes/+page.svelte +1 -1
src/lib/agents/evalBuilder.ts
CHANGED
@@ -7,43 +7,34 @@ export async function evalBuilder(
|
|
7 |
files: FileList | null,
|
8 |
updateCallback: (message: string, data: undefined | string | Blob) => void
|
9 |
) {
|
10 |
-
let filetype = "";
|
11 |
-
|
12 |
-
if (files && files[0].type.startsWith("image")) {
|
13 |
-
filetype = "image";
|
14 |
-
} else if (files && files[0].type.startsWith("audio")) {
|
15 |
-
filetype = "audio";
|
16 |
-
}
|
17 |
-
|
18 |
async function wrapperEval() {
|
19 |
-
if (
|
20 |
// @ts-ignore
|
21 |
-
globalThis[
|
22 |
}
|
23 |
-
}
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
46 |
}
|
47 |
-
|
48 |
return wrapperEval;
|
49 |
}
|
|
|
7 |
files: FileList | null,
|
8 |
updateCallback: (message: string, data: undefined | string | Blob) => void
|
9 |
) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
async function wrapperEval() {
|
11 |
+
if (files && files.length > 0) {
|
12 |
// @ts-ignore
|
13 |
+
globalThis["file"] = await files[0];
|
14 |
}
|
|
|
15 |
|
16 |
+
// add tools to context
|
17 |
+
for (const tool of tools) {
|
18 |
+
// @ts-ignore
|
19 |
+
globalThis[tool.name] = tool.call;
|
20 |
+
}
|
21 |
|
22 |
+
// @ts-ignore
|
23 |
+
globalThis["message"] = updateCallback;
|
24 |
|
25 |
+
const returnString = "\nreturn await generate(file);";
|
26 |
|
27 |
+
await Object.getPrototypeOf(async function () {}).constructor(
|
28 |
+
code + returnString
|
29 |
+
)();
|
30 |
|
31 |
+
// clean up tools
|
32 |
+
for (const tool of tools) {
|
33 |
+
// @ts-ignore
|
34 |
+
delete globalThis[tool.name];
|
35 |
+
// @ts-ignore
|
36 |
+
delete globalThis["file"];
|
37 |
+
}
|
38 |
}
|
|
|
39 |
return wrapperEval;
|
40 |
}
|
src/routes/+page.svelte
CHANGED
@@ -86,7 +86,7 @@
|
|
86 |
bind:value={prompt}
|
87 |
/>
|
88 |
|
89 |
-
|
90 |
|
91 |
<button
|
92 |
class="btn btn-primary mt-auto w-fit mx-auto"
|
|
|
86 |
bind:value={prompt}
|
87 |
/>
|
88 |
|
89 |
+
<FileUpload bind:files />
|
90 |
|
91 |
<button
|
92 |
class="btn btn-primary mt-auto w-fit mx-auto"
|