Skip to content

Commit d7bc647

Browse files
lichterspielimadilkhaliljeremyphilemonchibicodeshaper
authored
Sync fork (#8)
* fix: use correct model name in onUpdateDocument function (vercel#828) * feat: add tests (vercel#843) * chore: bump versions (vercel#845) * fix: check chat/vote ownership during actions (vercel#847) * Check for isComposing * feat: add reasoning tests (vercel#856) * feat: add artifact tests (vercel#859) * refactor: replace isLoading with status (vercel#861) * refactor: replace message.content with message.parts (vercel#868) * fix: poll votes after reaching minimum message count (vercel#869) * package updates * undo icon edits * feat (vscode): add suggested vscode extension and settings configs * fix quotes * rm small suffix, more quote fixes * version in lint action * chore: use explicit pnpm 9 version for reproducibility (vercel#873) * feat: reference geist from google fonts (vercel#876) --------- Co-authored-by: Adil Khalil <[email protected]> Co-authored-by: Jeremy <[email protected]> Co-authored-by: Shusaku Uesugi <[email protected]> Co-authored-by: Walter Korman <[email protected]> Co-authored-by: Walter Korman <[email protected]>
1 parent ef7eb9d commit d7bc647

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4990
-2249
lines changed

.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Get your xAI API Key here for chat models: https://console.x.ai/
2+
XAI_API_KEY=****
3+
14
# Get your OpenAI API Key here for chat models: https://platform.openai.com/account/api-keys
25
OPENAI_API_KEY=****
36

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Install pnpm
1414
uses: pnpm/action-setup@v4
1515
with:
16-
version: 9
16+
version: 9.12.3
1717
- name: Use Node.js ${{ matrix.node-version }}
1818
uses: actions/setup-node@v4
1919
with:

.github/workflows/playwright.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [main, master]
5+
pull_request:
6+
branches: [main, master]
7+
8+
jobs:
9+
test:
10+
timeout-minutes: 30
11+
runs-on: ubuntu-latest
12+
env:
13+
AUTH_SECRET: ${{ secrets.AUTH_SECRET }}
14+
POSTGRES_URL: ${{ secrets.POSTGRES_URL }}
15+
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 1
21+
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: lts/*
25+
26+
- name: Install pnpm
27+
uses: pnpm/action-setup@v2
28+
with:
29+
version: latest
30+
run_install: false
31+
32+
- name: Get pnpm store directory
33+
id: pnpm-cache
34+
shell: bash
35+
run: |
36+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
37+
38+
- uses: actions/cache@v3
39+
with:
40+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
41+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
42+
restore-keys: |
43+
${{ runner.os }}-pnpm-store-
44+
45+
- uses: actions/setup-node@v4
46+
with:
47+
node-version: lts/*
48+
cache: "pnpm"
49+
50+
- name: Install dependencies
51+
run: pnpm install --frozen-lockfile
52+
53+
- name: Cache Playwright browsers
54+
uses: actions/cache@v3
55+
id: playwright-cache
56+
with:
57+
path: ~/.cache/ms-playwright
58+
key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }}
59+
60+
- name: Install Playwright Browsers
61+
if: steps.playwright-cache.outputs.cache-hit != 'true'
62+
run: pnpm exec playwright install --with-deps chromium
63+
64+
- name: Run Playwright tests
65+
run: pnpm test
66+
67+
- uses: actions/upload-artifact@v4
68+
if: always() && !cancelled()
69+
with:
70+
name: playwright-report
71+
path: playwright-report/
72+
retention-days: 7

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@ yarn-error.log*
3434

3535
.env
3636
.vercel
37-
.vscode
3837
.env*.local
38+
39+
# Playwright
40+
/test-results/
41+
/playwright-report/
42+
/blob-report/
43+
/playwright/*

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["biomejs.biome"]
3+
}

.vscode/settings.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"[javascript]": {
4+
"editor.defaultFormatter": "biomejs.biome"
5+
},
6+
"[typescript]": {
7+
"editor.defaultFormatter": "biomejs.biome"
8+
},
9+
"[typescriptreact]": {
10+
"editor.defaultFormatter": "biomejs.biome"
11+
},
12+
"typescript.tsdk": "node_modules/typescript/lib",
13+
"eslint.workingDirectories": [
14+
{ "pattern": "app/*" },
15+
{ "pattern": "packages/*" }
16+
]
17+
}
18+

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- [AI SDK](https://sdk.vercel.ai/docs)
2424
- Unified API for generating text, structured objects, and tool calls with LLMs
2525
- Hooks for building dynamic chat and generative user interfaces
26-
- Supports OpenAI (default), Anthropic, Cohere, and other model providers
26+
- Supports xAI (default), OpenAI, Fireworks, and other model providers
2727
- [shadcn/ui](https://ui.shadcn.com)
2828
- Styling with [Tailwind CSS](https://tailwindcss.com)
2929
- Component primitives from [Radix UI](https://radix-ui.com) for accessibility and flexibility
@@ -35,19 +35,19 @@
3535

3636
## Model Providers
3737

38-
This template ships with OpenAI `gpt-4o` as the default. However, with the [AI SDK](https://sdk.vercel.ai/docs), you can switch LLM providers to [OpenAI](https://openai.com), [Anthropic](https://anthropic.com), [Cohere](https://cohere.com/), and [many more](https://sdk.vercel.ai/providers/ai-sdk-providers) with just a few lines of code.
38+
This template ships with [xAI](https://x.ai) `grok-2-1212` as the default chat model. However, with the [AI SDK](https://sdk.vercel.ai/docs), you can switch LLM providers to [OpenAI](https://openai.com), [Anthropic](https://anthropic.com), [Cohere](https://cohere.com/), and [many more](https://sdk.vercel.ai/providers/ai-sdk-providers) with just a few lines of code.
3939

4040
## Deploy Your Own
4141

4242
You can deploy your own version of the Next.js AI Chatbot to Vercel with one click:
4343

44-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fai-chatbot&env=AUTH_SECRET,OPENAI_API_KEY&envDescription=Learn%20more%20about%20how%20to%20get%20the%20API%20Keys%20for%20the%20application&envLink=https%3A%2F%2Fgithub.com%2Fvercel%2Fai-chatbot%2Fblob%2Fmain%2F.env.example&demo-title=AI%20Chatbot&demo-description=An%20Open-Source%20AI%20Chatbot%20Template%20Built%20With%20Next.js%20and%20the%20AI%20SDK%20by%20Vercel.&demo-url=https%3A%2F%2Fchat.vercel.ai&stores=[{%22type%22:%22postgres%22},{%22type%22:%22blob%22}])
44+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fai-chatbot&env=AUTH_SECRET,OPENAI_API_KEY,XAI_API_KEY,FIREWORKS_API_KEY&envDescription=Learn%20more%20about%20how%20to%20get%20the%20API%20Keys%20for%20the%20application&envLink=https%3A%2F%2Fgithub.com%2Fvercel%2Fai-chatbot%2Fblob%2Fmain%2F.env.example&demo-title=AI%20Chatbot&demo-description=An%20Open-Source%20AI%20Chatbot%20Template%20Built%20With%20Next.js%20and%20the%20AI%20SDK%20by%20Vercel.&demo-url=https%3A%2F%2Fchat.vercel.ai&stores=[{%22type%22:%22postgres%22},{%22type%22:%22blob%22}])
4545

4646
## Running locally
4747

4848
You will need to use the environment variables [defined in `.env.example`](.env.example) to run Next.js AI Chatbot. It's recommended you use [Vercel Environment Variables](https://vercel.com/docs/projects/environment-variables) for this, but a `.env` file is all that is necessary.
4949

50-
> Note: You should not commit your `.env` file or it will expose secrets that will allow others to control access to your various OpenAI and authentication provider accounts.
50+
> Note: You should not commit your `.env` file or it will expose secrets that will allow others to control access to your various AI and authentication provider accounts.
5151
5252
1. Install Vercel CLI: `npm i -g vercel`
5353
2. Link local instance with Vercel and GitHub accounts (creates `.vercel` directory): `vercel link`

app/(auth)/login/page.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import Link from 'next/link';
44
import { useRouter } from 'next/navigation';
55
import { useActionState, useEffect, useState } from 'react';
6-
import { toast } from 'sonner';
6+
import { toast } from '@/components/toast';
77

88
import { AuthForm } from '@/components/auth-form';
99
import { SubmitButton } from '@/components/submit-button';
@@ -25,14 +25,20 @@ export default function Page() {
2525

2626
useEffect(() => {
2727
if (state.status === 'failed') {
28-
toast.error('Invalid credentials!');
28+
toast({
29+
type: 'error',
30+
description: 'Invalid credentials!',
31+
});
2932
} else if (state.status === 'invalid_data') {
30-
toast.error('Failed validating your submission!');
33+
toast({
34+
type: 'error',
35+
description: 'Failed validating your submission!',
36+
});
3137
} else if (state.status === 'success') {
3238
setIsSuccessful(true);
3339
router.refresh();
3440
}
35-
}, [state.status, router]);
41+
}, [state.status]);
3642

3743
const handleSubmit = (formData: FormData) => {
3844
setEmail(formData.get('email') as string);

app/(auth)/register/page.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import Link from 'next/link';
44
import { useRouter } from 'next/navigation';
55
import { useActionState, useEffect, useState } from 'react';
6-
import { toast } from 'sonner';
76

87
import { AuthForm } from '@/components/auth-form';
98
import { SubmitButton } from '@/components/submit-button';
109

1110
import { register, type RegisterActionState } from '../actions';
11+
import { toast } from '@/components/toast';
1212

1313
export default function Page() {
1414
const router = useRouter();
@@ -25,17 +25,21 @@ export default function Page() {
2525

2626
useEffect(() => {
2727
if (state.status === 'user_exists') {
28-
toast.error('Account already exists');
28+
toast({ type: 'error', description: 'Account already exists!' });
2929
} else if (state.status === 'failed') {
30-
toast.error('Failed to create account');
30+
toast({ type: 'error', description: 'Failed to create account!' });
3131
} else if (state.status === 'invalid_data') {
32-
toast.error('Failed validating your submission!');
32+
toast({
33+
type: 'error',
34+
description: 'Failed validating your submission!',
35+
});
3336
} else if (state.status === 'success') {
34-
toast.success('Account created successfully');
37+
toast({ type: 'success', description: 'Account created successfully!' });
38+
3539
setIsSuccessful(true);
3640
router.refresh();
3741
}
38-
}, [state, router]);
42+
}, [state]);
3943

4044
const handleSubmit = (formData: FormData) => {
4145
setEmail(formData.get('email') as string);

app/(chat)/actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
updateChatVisiblityById,
1010
} from '@/lib/db/queries';
1111
import { VisibilityType } from '@/components/visibility-selector';
12-
import { myProvider } from '@/lib/ai/models';
12+
import { myProvider } from '@/lib/ai/providers';
1313

1414
export async function saveChatModelAsCookie(model: string) {
1515
const cookieStore = await cookies();

0 commit comments

Comments
 (0)