mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
* 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
38 lines
1,015 B
JavaScript
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;
|