diff --git a/bots/claude_3.ts b/bots/claude_3.ts index 53d3a80..b5bc798 100644 --- a/bots/claude_3.ts +++ b/bots/claude_3.ts @@ -86,11 +86,6 @@ export async function send( const resp: types.claudeResponse | types.Error = await res.json(); - if (types.isError(resp)) { - // Fuck. - throw resp.error.message; // well at least they know why the fuck it crashed?? - } - messages.push({ role: "assistant", content: resp.content[0].text }); const fresp = { diff --git a/importLLMFile.ts b/importLLMFile.ts index 6ee0d39..9e31cd7 100644 --- a/importLLMFile.ts +++ b/importLLMFile.ts @@ -2,7 +2,7 @@ import * as types from "./main.d.ts"; -import { dynamicImport } from 'https://deno.land/x/import/mod.ts'; +import { build } from "https://deno.land/x/esbuild@v0.20.2/mod.js" export default async function importLLMFile(modulePath: string) { try { @@ -10,13 +10,35 @@ export default async function importLLMFile(modulePath: string) { 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( diff --git a/main.ts b/main.ts index fc2581a..07e76b4 100644 --- a/main.ts +++ b/main.ts @@ -11,8 +11,6 @@ import client from "./client.ts"; import { walk, existsSync } from "https://deno.land/std@0.221.0/fs/mod.ts"; -import * as path from "https://deno.land/std@0.221.0/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 ); } }