Skip to content

Commit

Permalink
feat: switch prompts based on selected chat model
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyphilemon committed Feb 3, 2025
1 parent c61d4f9 commit c90c586
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
28 changes: 11 additions & 17 deletions app/(chat)/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,10 @@ import { createDocument } from '@/lib/ai/tools/create-document';
import { updateDocument } from '@/lib/ai/tools/update-document';
import { requestSuggestions } from '@/lib/ai/tools/request-suggestions';
import { getWeather } from '@/lib/ai/tools/get-weather';
import { getTools } from '@/lib/ai/tools';

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,
Expand Down Expand Up @@ -79,10 +65,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: {
Expand Down
12 changes: 11 additions & 1 deletion lib/ai/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c90c586

Please sign in to comment.