Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Full-featured AI Chatbot Nuxt application with authentication, chat history, mul
- ⚡️ **Streaming AI messages** powered by the [AI SDK v5](https://sdk.vercel.ai)
- 🤖 **Multiple model support** via various AI providers with built-in AI Gateway support
- 🔐 **Authentication** via [nuxt-auth-utils](https://github.com/atinux/nuxt-auth-utils)
- 💾 **Chat history persistence** using PostgreSQL database and [Drizzle ORM](https://orm.drizzle.team)
- 💾 **Chat history persistence** using SQLite database (Turso in production) and [Drizzle ORM](https://orm.drizzle.team)
- 🚀 **Easy deploy** to Vercel with zero configuration

## Quick Start
Expand All @@ -31,7 +31,7 @@ npm create nuxt@latest -- -t ui/chat

## Deploy your own

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-name=chat&repository-url=https%3A%2F%2Fgithub.com%2Fnuxt-ui-templates%2Fchat&env=NUXT_SESSION_PASSWORD,NUXT_OAUTH_GITHUB_CLIENT_ID,NUXT_OAUTH_GITHUB_CLIENT_SECRET&products=%5B%7B%22type%22%3A%22integration%22%2C%22group%22%3A%22postgres%22%7D%5D&demo-image=https%3A%2F%2Fui.nuxt.com%2Fassets%2Ftemplates%2Fnuxt%2Fchat-dark.png&demo-url=https%3A%2F%2Fchat-template.nuxt.dev%2F&demo-title=Nuxt%20Chat%20Template&demo-description=An%20AI%20chatbot%20template%20to%20build%20your%20own%20chatbot%20powered%20by%20Nuxt%20MDC%20and%20Vercel%20AI%20SDK.)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-name=chat&repository-url=https%3A%2F%2Fgithub.com%2Fnuxt-ui-templates%2Fchat&env=NUXT_SESSION_PASSWORD,NUXT_OAUTH_GITHUB_CLIENT_ID,NUXT_OAUTH_GITHUB_CLIENT_SECRET&products=%5B%7B%22type%22%3A%22integration%22%2C%22protocol%22%3A%22storage%22%2C%22productSlug%22%3A%22database%22%2C%22integrationSlug%22%3A%22tursocloud%22%7D%5D&demo-image=https%3A%2F%2Fui.nuxt.com%2Fassets%2Ftemplates%2Fnuxt%2Fchat-dark.png&demo-url=https%3A%2F%2Fchat-template.nuxt.dev%2F&demo-title=Nuxt%20Chat%20Template&demo-description=An%20AI%20chatbot%20template%20to%20build%20your%20own%20chatbot%20powered%20by%20Nuxt%20MDC%20and%20Vercel%20AI%20SDK.)

## Setup

Expand Down
7 changes: 2 additions & 5 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
dialect: 'postgresql',
dialect: 'sqlite',
schema: './server/database/schema.ts',
out: './server/database/migrations',
dbCredentials: {
url: process.env.DATABASE_URL!
}
out: './server/database/migrations'
})
6 changes: 6 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default defineNuxtConfig({
'@nuxt/eslint',
'@nuxt/ui',
'@nuxtjs/mdc',
'@nuxthub/core',
'nuxt-auth-utils',
'nuxt-charts'
],
Expand Down Expand Up @@ -36,6 +37,11 @@ export default defineNuxtConfig({
}
},

hub: {
ai: 'vercel',
database: 'sqlite'
},

eslint: {
config: {
stylistic: {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
"@iconify-json/logos": "^1.2.9",
"@iconify-json/lucide": "^1.2.71",
"@iconify-json/simple-icons": "^1.2.55",
"@libsql/client": "^0.15.15",
"@nuxt/ui": "^4.1.0",
"@nuxthub/core": "npm:@nuxthub/[email protected]",
"@nuxtjs/mdc": "^0.18.0",
"ai": "^5.0.80",
"date-fns": "^4.1.0",
"drizzle-orm": "^0.44.7",
"nuxt": "^4.2.0",
"nuxt-auth-utils": "^0.5.25",
"nuxt-charts": "0.2.4",
"pg": "^8.16.3",
"shiki-stream": "^0.1.2"
"shiki-stream": "^0.1.2",
"workers-ai-provider": "^2.0.0"
},
"devDependencies": {
"@nuxt/eslint": "^1.9.0",
Expand Down
1,407 changes: 1,347 additions & 60 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ ignoredBuiltDependencies:
- unrs-resolver
- vue-demi

onlyBuiltDependencies:
- better-sqlite3

patchedDependencies:
'@nuxt/vite-builder': patches/@nuxt__vite-builder.patch
5 changes: 2 additions & 3 deletions server/api/chats/[id].post.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { convertToModelMessages, createUIMessageStream, createUIMessageStreamResponse, generateText, smoothStream, stepCountIs, streamText } from 'ai'
import { gateway } from '@ai-sdk/gateway'
import type { UIMessage } from 'ai'
import { z } from 'zod'

Expand Down Expand Up @@ -36,7 +35,7 @@ export default defineEventHandler(async (event) => {

if (!chat.title) {
const { text: title } = await generateText({
model: gateway('openai/gpt-4o-mini'),
model: hubAI('openai/gpt-4o-mini'),
system: `You are a title generator for a chat:
- Generate a short title based on the first user's message
- The title should be less than 30 characters long
Expand All @@ -61,7 +60,7 @@ export default defineEventHandler(async (event) => {
const stream = createUIMessageStream({
execute: ({ writer }) => {
const result = streamText({
model: gateway(model),
model: hubAI(model),
system: `You are a knowledgeable and helpful AI assistant. ${session.user?.username ? `The user's name is ${session.user.username}.` : ''} Your goal is to provide clear, accurate, and well-structured responses.

**FORMATTING RULES (CRITICAL):**
Expand Down
32 changes: 0 additions & 32 deletions server/database/migrations/0000_amusing_gunslinger.sql

This file was deleted.

30 changes: 30 additions & 0 deletions server/database/migrations/0000_fancy_dracula.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE TABLE `chats` (
`id` text PRIMARY KEY NOT NULL,
`title` text,
`user_id` text NOT NULL,
`created_at` integer NOT NULL
);
--> statement-breakpoint
CREATE INDEX `chats_user_id_idx` ON `chats` (`user_id`);--> statement-breakpoint
CREATE TABLE `messages` (
`id` text PRIMARY KEY NOT NULL,
`chat_id` text NOT NULL,
`role` text NOT NULL,
`parts` text,
`created_at` integer NOT NULL,
FOREIGN KEY (`chat_id`) REFERENCES `chats`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `messages_chat_id_idx` ON `messages` (`chat_id`);--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`email` text NOT NULL,
`name` text NOT NULL,
`avatar` text NOT NULL,
`username` text NOT NULL,
`provider` text NOT NULL,
`provider_id` text NOT NULL,
`created_at` integer NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `users_provider_id_idx` ON `users` (`provider`,`provider_id`);
Loading