{"id":14964841,"url":"https://github.com/lgrammel/modelfusion-llamacpp-nextjs-starter","last_synced_at":"2025-09-01T09:33:09.059Z","repository":{"id":208100852,"uuid":"720803520","full_name":"lgrammel/modelfusion-llamacpp-nextjs-starter","owner":"lgrammel","description":"Starter examples for using Next.js and the Vercel AI SDK with Llama.cpp and ModelFusion.","archived":false,"fork":false,"pushed_at":"2024-01-13T12:23:26.000Z","size":288,"stargazers_count":34,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-08-17T09:19:29.606Z","etag":null,"topics":["ai","llama2","llamacpp","mistral","modelfusion","next","nextjs","vercel-ai","vercel-ai-sdk"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lgrammel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-19T16:46:24.000Z","updated_at":"2025-06-02T08:38:12.000Z","dependencies_parsed_at":"2023-12-30T11:21:07.772Z","dependency_job_id":"f03f7a62-19d8-4f8d-a974-6e29e967d2a5","html_url":"https://github.com/lgrammel/modelfusion-llamacpp-nextjs-starter","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"621a2d88a8035edf41a9247163aed2ebbcd401a9"},"previous_names":["lgrammel/modelfusion-llamacpp-nextjs-starter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lgrammel/modelfusion-llamacpp-nextjs-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lgrammel%2Fmodelfusion-llamacpp-nextjs-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lgrammel%2Fmodelfusion-llamacpp-nextjs-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lgrammel%2Fmodelfusion-llamacpp-nextjs-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lgrammel%2Fmodelfusion-llamacpp-nextjs-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lgrammel","download_url":"https://codeload.github.com/lgrammel/modelfusion-llamacpp-nextjs-starter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lgrammel%2Fmodelfusion-llamacpp-nextjs-starter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271746913,"owners_count":24813595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","llama2","llamacpp","mistral","modelfusion","next","nextjs","vercel-ai","vercel-ai-sdk"],"created_at":"2024-09-24T13:33:51.295Z","updated_at":"2025-09-01T09:33:09.034Z","avatar_url":"https://github.com/lgrammel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next.js, Vercel AI SDK, Llama.cpp \u0026 ModelFusion starter\n\nThis starter example shows how to use [Next.js](https://nextjs.org/), the [Vercel AI SDK](https://sdk.vercel.ai/docs), [Llama.cpp](https://github.com/ggerganov/llama.cpp) and [ModelFusion](https://modelfusion.dev) to create a ChatGPT-like AI-powered streaming chat bot.\n\n## Setup\n\n1. Install [Llama.cpp](https://github.com/ggerganov/llama.cpp) on your machine.\n2. Clone the repository: `git clone https://github.com/lgrammel/modelfusion-llamacpp-nextjs-starter.git`\n3. Install dependencies: `npm install`\n4. Start the development server: `npm run dev`\n\nFor each example, you also need to download the GGUF model and start the Llama.cpp server:\n\n## Examples\n\n### Llama 2\n\n1. Model: [Llama-2-7B-Chat-GGUF](https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF)\n2. Server start: `./server -m models/llama-2-7b-chat.Q4_K_M.gguf` (with the right model path)\n3. Go to http://localhost:3000/llama2\n4. Code: `app/api/llama/route.ts`\n\n### Mistral Instruct\n\n1. Model: [Mistral-7B-Instruct-v0.2-GGUF](https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF)\n1. Server start: `./server -m models/mistral-7b-instruct-v0.2.Q4_K_M.gguf` (with the right model path)\n1. Go to http://localhost:3000/mistral\n1. Code: `app/api/mistral/route.ts`\n\n### Mixtral Instruct\n\n1. Model: [Mixtral-8x7B-Instruct-v0.1-GGUF](https://huggingface.co/TheBloke/Mixtral-8x7B-Instruct-v0.1-GGUF)\n1. Server start: `./server -m models/mixtral-8x7b-instruct-v0.1.Q4_K_M.gguf` (with the right model path)\n1. Go to http://localhost:3000/mixtral\n1. Code: `app/api/mixtral/route.ts`\n\n### OpenHermes 2.5\n\n1. Model: [OpenHermes-2.5-Mistral-7B-GGUF](https://huggingface.co/TheBloke/OpenHermes-2.5-Mistral-7B-GGUF)\n1. Server start: `./server -m models/openhermes-2.5-mistral-7b.Q4_K_M.gguf` (with the right model path)\n1. Go to http://localhost:3000/openhermes\n1. Code: `app/api/openhermes/route.ts`\n\n## Example Route\n\n```ts\nimport { ModelFusionTextStream, asChatMessages } from \"@modelfusion/vercel-ai\";\nimport { Message, StreamingTextResponse } from \"ai\";\nimport { llamacpp, streamText, trimChatPrompt } from \"modelfusion\";\n\nexport const runtime = \"edge\";\n\nexport async function POST(req: Request) {\n  const { messages }: { messages: Message[] } = await req.json();\n\n  const model = llamacpp\n    .CompletionTextGenerator({\n      promptTemplate: llamacpp.prompt.Llama2, // choose the correct prompt template\n      temperature: 0,\n      cachePrompt: true,\n      contextWindowSize: 4096, // Llama 2 context window size\n      maxGenerationTokens: 512, // Room for answer\n    })\n    .withChatPrompt();\n\n  // Use ModelFusion to call llama.cpp:\n  const textStream = await streamText({\n    model,\n    // reduce chat prompt length to fit the context window:\n    prompt: await trimChatPrompt({\n      model,\n      prompt: {\n        system:\n          \"You are an AI chat bot. \" +\n          \"Follow the user's instructions carefully.\",\n\n        // map Vercel AI SDK Message to ModelFusion ChatMessage:\n        messages: asChatMessages(messages),\n      },\n    }),\n  });\n\n  // Return the result using the Vercel AI SDK:\n  return new StreamingTextResponse(\n    ModelFusionTextStream(\n      textStream,\n      // optional callbacks:\n      {\n        onStart() {\n          console.log(\"onStart\");\n        },\n        onToken(token) {\n          console.log(\"onToken\", token);\n        },\n        onCompletion: () =\u003e {\n          console.log(\"onCompletion\");\n        },\n        onFinal(completion) {\n          console.log(\"onFinal\", completion);\n        },\n      }\n    )\n  );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flgrammel%2Fmodelfusion-llamacpp-nextjs-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flgrammel%2Fmodelfusion-llamacpp-nextjs-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flgrammel%2Fmodelfusion-llamacpp-nextjs-starter/lists"}