nsarrazin commited on
Commit
65d7bbe
·
1 Parent(s): 97aa76a

add file upload support

Browse files
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 (filetype !== "") {
20
  // @ts-ignore
21
- globalThis[filetype] = await files[0];
22
  }
23
- }
24
 
25
- // add tools to context
26
- for (const tool of tools) {
27
- // @ts-ignore
28
- globalThis[tool.name] = tool.call;
29
- }
30
 
31
- // @ts-ignore
32
- globalThis["message"] = updateCallback;
33
 
34
- const returnString = "\nreturn await generate(" + filetype + ");";
35
 
36
- await Object.getPrototypeOf(async function () {}).constructor(
37
- code + returnString
38
- )();
39
 
40
- // clean up tools
41
- for (const tool of tools) {
42
- // @ts-ignore
43
- delete globalThis[tool.name];
44
- // @ts-ignore
45
- delete globalThis[filetype];
 
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
- <!-- <FileUpload bind:files /> -->
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"