-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd5a538
commit c8bc496
Showing
3 changed files
with
26 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,43 @@ | |
|
||
import * as types from "./main.d.ts"; | ||
|
||
import { dynamicImport } from 'https://deno.land/x/import/mod.ts'; | ||
import { build } from "https://deno.land/x/[email protected]/mod.js" | ||
|
||
export default async function importLLMFile(modulePath: string) { | ||
try { | ||
if (!globalThis.availableLLMs) { | ||
globalThis.availableLLMs = {}; | ||
} | ||
|
||
const module: types.llmFile = await dynamicImport(`${modulePath}`, { force: true }); | ||
const tsCode = await Deno.readTextFile(Deno.cwd() + `/${modulePath}`); | ||
|
||
const { outputFiles } = await build({ | ||
stdin: { | ||
contents: tsCode, | ||
loader: "ts", | ||
}, | ||
bundle: true, | ||
write: false, | ||
format: "esm", // Specify output format as ESM | ||
}); | ||
|
||
const jsCode = outputFiles[0].text; | ||
|
||
const base64Data = btoa(jsCode); | ||
|
||
// Create the Data URL | ||
const dataURL = `data:text/plain;base64,${base64Data}`; | ||
|
||
const module: types.llmFile = await import(dataURL) | ||
|
||
|
||
|
||
if (module && module.information && typeof module.send === "function") { | ||
globalThis.availableLLMs[module.information.id] = { | ||
information: module.information, | ||
send: module.send, | ||
}; | ||
} | ||
|
||
return module.information; // Return the information object | ||
} else { | ||
console.error( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,6 @@ import client from "./client.ts"; | |
|
||
import { walk, existsSync } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
|
||
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
|
||
import importLLMFile from "./importLLMFile.ts"; | ||
|
||
if (!existsSync("./bots")) { | ||
|
@@ -22,7 +20,7 @@ if (!existsSync("./bots")) { | |
for await (const entry of await walk("./bots")) { | ||
if (entry.isFile && entry.name.endsWith(".ts")) { | ||
await importLLMFile( | ||
`./${entry.path}` | ||
entry.path | ||
); | ||
} | ||
} | ||
|