feat: switch prompts based on selected chat model (#754)
This commit is contained in:
parent
c61d4f91d4
commit
711da0b94b
2 changed files with 21 additions and 19 deletions
|
|
@ -3,7 +3,6 @@ import {
|
||||||
createDataStreamResponse,
|
createDataStreamResponse,
|
||||||
smoothStream,
|
smoothStream,
|
||||||
streamText,
|
streamText,
|
||||||
wrapLanguageModel,
|
|
||||||
} from 'ai';
|
} from 'ai';
|
||||||
|
|
||||||
import { auth } from '@/app/(auth)/auth';
|
import { auth } from '@/app/(auth)/auth';
|
||||||
|
|
@ -29,21 +28,6 @@ import { getWeather } from '@/lib/ai/tools/get-weather';
|
||||||
|
|
||||||
export const maxDuration = 60;
|
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) {
|
export async function POST(request: Request) {
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
|
|
@ -79,10 +63,18 @@ export async function POST(request: Request) {
|
||||||
execute: (dataStream) => {
|
execute: (dataStream) => {
|
||||||
const result = streamText({
|
const result = streamText({
|
||||||
model: myProvider.languageModel(selectedChatModel),
|
model: myProvider.languageModel(selectedChatModel),
|
||||||
system: systemPrompt,
|
system: systemPrompt({ selectedChatModel }),
|
||||||
messages,
|
messages,
|
||||||
maxSteps: 5,
|
maxSteps: 5,
|
||||||
experimental_activeTools: allTools,
|
experimental_activeTools:
|
||||||
|
selectedChatModel === 'chat-model-reasoning'
|
||||||
|
? []
|
||||||
|
: [
|
||||||
|
'getWeather',
|
||||||
|
'createDocument',
|
||||||
|
'updateDocument',
|
||||||
|
'requestSuggestions',
|
||||||
|
],
|
||||||
experimental_transform: smoothStream({ chunking: 'word' }),
|
experimental_transform: smoothStream({ chunking: 'word' }),
|
||||||
experimental_generateMessageId: generateUUID,
|
experimental_generateMessageId: generateUUID,
|
||||||
tools: {
|
tools: {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,17 @@ Do not update document right after creating it. Wait for user feedback or reques
|
||||||
export const regularPrompt =
|
export const regularPrompt =
|
||||||
'You are a friendly assistant! Keep your responses concise and helpful.';
|
'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 = `
|
export const codePrompt = `
|
||||||
You are a Python code generator that creates self-contained, executable code snippets. When writing code:
|
You are a Python code generator that creates self-contained, executable code snippets. When writing code:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue