Skip to content

Commit 711da0b

Browse files
feat: switch prompts based on selected chat model (vercel#754)
1 parent c61d4f9 commit 711da0b

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

app/(chat)/api/chat/route.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
createDataStreamResponse,
44
smoothStream,
55
streamText,
6-
wrapLanguageModel,
76
} from 'ai';
87

98
import { auth } from '@/app/(auth)/auth';
@@ -29,21 +28,6 @@ import { getWeather } from '@/lib/ai/tools/get-weather';
2928

3029
export const maxDuration = 60;
3130

32-
type AllowedTools =
33-
| 'createDocument'
34-
| 'updateDocument'
35-
| 'requestSuggestions'
36-
| 'getWeather';
37-
38-
const blocksTools: AllowedTools[] = [
39-
'createDocument',
40-
'updateDocument',
41-
'requestSuggestions',
42-
];
43-
44-
const weatherTools: AllowedTools[] = ['getWeather'];
45-
const allTools: AllowedTools[] = [...blocksTools, ...weatherTools];
46-
4731
export async function POST(request: Request) {
4832
const {
4933
id,
@@ -79,10 +63,18 @@ export async function POST(request: Request) {
7963
execute: (dataStream) => {
8064
const result = streamText({
8165
model: myProvider.languageModel(selectedChatModel),
82-
system: systemPrompt,
66+
system: systemPrompt({ selectedChatModel }),
8367
messages,
8468
maxSteps: 5,
85-
experimental_activeTools: allTools,
69+
experimental_activeTools:
70+
selectedChatModel === 'chat-model-reasoning'
71+
? []
72+
: [
73+
'getWeather',
74+
'createDocument',
75+
'updateDocument',
76+
'requestSuggestions',
77+
],
8678
experimental_transform: smoothStream({ chunking: 'word' }),
8779
experimental_generateMessageId: generateUUID,
8880
tools: {

lib/ai/prompts.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ Do not update document right after creating it. Wait for user feedback or reques
3434
export const regularPrompt =
3535
'You are a friendly assistant! Keep your responses concise and helpful.';
3636

37-
export const systemPrompt = `${regularPrompt}\n\n${blocksPrompt}`;
37+
export const systemPrompt = ({
38+
selectedChatModel,
39+
}: {
40+
selectedChatModel: string;
41+
}) => {
42+
if (selectedChatModel === 'chat-model-reasoning') {
43+
return regularPrompt;
44+
} else {
45+
return `${regularPrompt}\n\n${blocksPrompt}`;
46+
}
47+
};
3848

3949
export const codePrompt = `
4050
You are a Python code generator that creates self-contained, executable code snippets. When writing code:

0 commit comments

Comments
 (0)