logancyang_obsidian-copilot/wasmPlugin.mjs
Logan Yang 7eafa110eb
Migrate to LangChainJS (#17)
* Migrate to LangChainJS

* Add wasmPlugin to solve tiktoken wasm loading issue in esbuild

* Wire in default system prompt for langchain params

* Implement stop generation for langchain

* Remove the streaming mode toggle in settings
2023-05-16 14:52:45 -07:00

38 lines
1,015 B
JavaScript

import * as fs from 'fs/promises';
import * as path from 'path';
const wasmPlugin = {
name: 'wasm',
setup(build) {
build.onResolve({ filter: /\.wasm$/ }, args => {
if (args.namespace === 'wasm-stub') {
return {
path: args.path,
namespace: 'wasm-binary',
}
}
if (args.resolveDir === '') {
return
}
return {
path: path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path),
namespace: 'wasm-stub',
}
})
build.onLoad({ filter: /.*/, namespace: 'wasm-stub' }, async (args) => ({
contents: `import wasm from ${JSON.stringify(args.path)}
export default (imports) =>
WebAssembly.instantiate(wasm, imports).then(
result => result.instance.exports)`,
}))
build.onLoad({ filter: /.*/, namespace: 'wasm-binary' }, async (args) => ({
contents: await fs.readFile(args.path),
loader: 'binary',
}))
},
}
export default wasmPlugin;