diff --git a/.changeset/late-ties-design.md b/.changeset/late-ties-design.md new file mode 100644 index 0000000000000000000000000000000000000000..8a4894da5f5949f3e3ba2619137037440681170a --- /dev/null +++ b/.changeset/late-ties-design.md @@ -0,0 +1,5 @@ +--- +"llamaindex": patch +--- + +Add tiktoken WASM to withLlamaIndex diff --git a/apps/docs/docs/getting_started/environments.md b/apps/docs/docs/getting_started/environments.md index b86c28b3721389281ff8a1173af757a1f5eac42c..eac52837523b41368177b5f799d4c992f312480a 100644 --- a/apps/docs/docs/getting_started/environments.md +++ b/apps/docs/docs/getting_started/environments.md @@ -6,10 +6,17 @@ sidebar_position: 2 We support Node.JS versions 18, 20 and 22, with experimental support for Deno, Bun and Vercel Edge functions. -## NextJS App Router +## NextJS -If you're using NextJS App Router route handlers/serverless functions, you'll need to use the NodeJS mode: +If you're using NextJS you'll need to add `withLlamaIndex` to your `next.config.js` file. This will add the necessary configuration for included 3rd-party libraries to your build: ```js -export const runtime = "nodejs"; // default +// next.config.js +const withLlamaIndex = require("llamaindex/next"); + +module.exports = withLlamaIndex({ + // your next.js config +}); ``` + +For details, check the latest [withLlamaIndex](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/llamaindex/src/next.ts) implementation. diff --git a/packages/llamaindex/src/next.ts b/packages/llamaindex/src/next.ts index 26d31735c1ea15591f6898c47b14ce43082c84b3..3ff8d60647402b564d7f0d581cfb1f85197024d1 100644 --- a/packages/llamaindex/src/next.ts +++ b/packages/llamaindex/src/next.ts @@ -17,6 +17,13 @@ */ export default function withLlamaIndex(config: any) { config.experimental = config.experimental ?? {}; + // copy tiktoken WASM files to the NextJS build + config.experimental.outputFileTracingIncludes = + config.experimental.outputFileTracingIncludes ?? {}; + config.experimental.outputFileTracingIncludes["/**/*"] = [ + "./node_modules/tiktoken/*.wasm", + ]; + // needed for transformers, see https://huggingface.co/docs/transformers.js/en/tutorials/next#step-2-install-and-configure-transformersjs config.experimental.serverComponentsExternalPackages = config.experimental.serverComponentsExternalPackages ?? []; config.experimental.serverComponentsExternalPackages.push(