create-llama: Error: Missing tiktoken_bg.wasm

for last few days I have been trying to solve this issue… I’m using create-llama as starter.

Screenshot 2024-07-15 at 05 32 16

package.json ` { “version”: “0.1.0”, “scripts”: { “format”: “prettier --ignore-unknown --cache --check .”, “format:write”: “prettier --ignore-unknown --write .”, “dev”: “next dev”, “build”: “next build”, “start”: “next start”, “lint”: “next lint”, “generate”: “tsx app/api/chat/engine/generate.ts” }, “dependencies”: { “@apidevtools/swagger-parser”: “^10.1.0”, “@e2b/code-interpreter”: “^0.0.5”, “@llamaindex/pdf-viewer”: “^1.1.1”, “@radix-ui/react-collapsible”: “^1.0.3”, “@radix-ui/react-hover-card”: “^1.0.7”, “@radix-ui/react-slot”: “^1.0.2”, “ai”: “^3.0.21”, “ajv”: “^8.12.0”, “class-variance-authority”: “^0.7.0”, “clsx”: “^2.1.1”, “dotenv”: “^16.3.1”, “duck-duck-scrape”: “^2.2.5”, “formdata-node”: “^6.0.3”, “got”: “^14.4.1”, “llamaindex”: “0.4.6”, “lucide-react”: “^0.294.0”, “next”: “^14.2.4”, “pdf2json”: “3.0.5”, “react”: “^18.2.0”, “react-dom”: “^18.2.0”, “react-markdown”: “^8.0.7”, “react-syntax-highlighter”: “^15.5.0”, “rehype-katex”: “^7.0.0”, “remark”: “^14.0.3”, “remark-code-import”: “^1.2.0”, “remark-gfm”: “^3.0.1”, “remark-math”: “^5.1.1”, “supports-color”: “^8.1.1”, “tailwind-merge”: “^2.1.0”, “tiktoken”: “^1.0.15”, “uuid”: “^9.0.1”, “vaul”: “^0.9.1” }, “devDependencies”: { “@types/node”: “^20.10.3”, “@types/react”: “^18.2.42”, “@types/react-dom”: “^18.2.17”, “@types/react-syntax-highlighter”: “^15.5.11”, “@types/uuid”: “^9.0.8”, “autoprefixer”: “^10.4.16”, “cross-env”: “^7.0.3”, “eslint”: “^8.55.0”, “eslint-config-next”: “^14.2.4”, “eslint-config-prettier”: “^8.10.0”, “postcss”: “^8.4.32”, “prettier”: “^3.2.5”, “prettier-plugin-organize-imports”: “^3.2.4”, “tailwindcss”: “^3.3.6”, “tsx”: “^4.7.2”, “typescript”: “^5.3.2” } }

`

app/chat/route `import { initObservability } from “@/app/observability”; import { Message, StreamData, StreamingTextResponse } from “ai”; import { ChatMessage, Settings } from “llamaindex”; import { NextRequest, NextResponse } from “next/server”; import { createChatEngine } from “./engine/chat”; import { initSettings } from “./engine/settings”; import { LlamaIndexStream, convertMessageContent } from “./llamaindex-stream”; import { createCallbackManager, createStreamTimeout } from “./stream-helper”;

initObservability(); initSettings();

export const runtime = “nodejs”; export const dynamic = “force-dynamic”;

export async function POST(request: NextRequest) { // Init Vercel AI StreamData and timeout const vercelStreamData = new StreamData(); const streamTimeout = createStreamTimeout(vercelStreamData);

try { const body = await request.json(); const { messages }: { messages: Message[] } = body; const userMessage = messages.pop(); if (!messages || !userMessage || userMessage.role !== “user”) { return NextResponse.json( { error: “messages are required in the request body and the last message must be from the user”, }, { status: 400 }, ); }

const chatEngine = await createChatEngine();

let annotations = userMessage.annotations;
if (!annotations) {
  // the user didn't send any new annotations with the last message
  // so use the annotations from the last user message that has annotations
  // REASON: GPT4 doesn't consider MessageContentDetail from previous messages, only strings
  annotations = messages
    .slice()
    .reverse()
    .find(
      (message) => message.role === "user" && message.annotations,
    )?.annotations;
}

// Convert message content from Vercel/AI format to LlamaIndex/OpenAI format
const userMessageContent = convertMessageContent(
  userMessage.content,
  annotations,
);

// Setup callbacks
const callbackManager = createCallbackManager(vercelStreamData);

// Calling LlamaIndex's ChatEngine to get a streamed response
const response = await Settings.withCallbackManager(callbackManager, () => {
  return chatEngine.chat({
    message: userMessageContent,
    chatHistory: messages as ChatMessage[],
    stream: true,
  });
});

// Transform LlamaIndex stream to Vercel/AI format
const stream = LlamaIndexStream(response, vercelStreamData);

// Return a StreamingTextResponse, which can be consumed by the Vercel/AI client
return new StreamingTextResponse(stream, {}, vercelStreamData);

} catch (error) { console.error(“[LlamaIndex]”, error); return NextResponse.json( { detail: (error as Error).message, }, { status: 500, }, ); } finally { clearTimeout(streamTimeout); } } `

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21

Commits related to this issue

Most upvoted comments

I had this issue as well. I had to update my Next config file to automatically trace the dependency for all api routes

nex.config.js experimental: { outputFileTracingIncludes: { "/api/**/*": ["./node_modules/**/*.wasm"], }, }

github repo

Makes a lot of sense that @wanasim 's patch is working - great job! I added a PR to include it: https://github.com/run-llama/create-llama/pull/201 Let me know if it solves your issue, then I’ll include it in one of the next releases.

ah this is outdated, please use at least 0.6.2

Fyi, I added @wanasim’s patch to the next.config.json file, and things are now working.