feat: switch prompts based on selected chat model (#754)

This commit is contained in:
Jeremy 2025-02-03 20:41:32 +05:30 committed by GitHub
parent c61d4f91d4
commit 711da0b94b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 19 deletions

View file

@ -3,7 +3,6 @@ import {
createDataStreamResponse,
smoothStream,
streamText,
wrapLanguageModel,
} from 'ai';
import { auth } from '@/app/(auth)/auth';
@ -29,21 +28,6 @@ import { getWeather } from '@/lib/ai/tools/get-weather';
export const maxDuration = 60;
type AllowedTools =
| 'createDocument'
| 'updateDocument'
| 'requestSuggestions'
| 'getWeather';
const blocksTools: AllowedTools[] = [
'createDocument',
'updateDocument',
'requestSuggestions',
];
const weatherTools: AllowedTools[] = ['getWeather'];
const allTools: AllowedTools[] = [...blocksTools, ...weatherTools];
export async function POST(request: Request) {
const {
id,
@ -79,10 +63,18 @@ export async function POST(request: Request) {
execute: (dataStream) => {
const result = streamText({
model: myProvider.languageModel(selectedChatModel),
system: systemPrompt,
system: systemPrompt({ selectedChatModel }),
messages,
maxSteps: 5,
experimental_activeTools: allTools,
experimental_activeTools:
selectedChatModel === 'chat-model-reasoning'
? []
: [
'getWeather',
'createDocument',
'updateDocument',
'requestSuggestions',
],
experimental_transform: smoothStream({ chunking: 'word' }),
experimental_generateMessageId: generateUUID,
tools: {

View file

@ -34,7 +34,17 @@ Do not update document right after creating it. Wait for user feedback or reques
export const regularPrompt =
'You are a friendly assistant! Keep your responses concise and helpful.';
export const systemPrompt = `${regularPrompt}\n\n${blocksPrompt}`;
export const systemPrompt = ({
selectedChatModel,
}: {
selectedChatModel: string;
}) => {
if (selectedChatModel === 'chat-model-reasoning') {
return regularPrompt;
} else {
return `${regularPrompt}\n\n${blocksPrompt}`;
}
};
export const codePrompt = `
You are a Python code generator that creates self-contained, executable code snippets. When writing code: