changes
This commit is contained in:
@@ -6,18 +6,24 @@ interface Message {
|
|||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use a fast, consistent model for title generation
|
||||||
|
const TITLE_MODEL = 'deepseek-r1:8b';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a short, descriptive title for a chat based on the conversation
|
* Generate a short, descriptive title for a chat based on the conversation
|
||||||
*/
|
*/
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const { model, messages } = await request.json();
|
const { messages } = await request.json();
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('[Title API] Request received:', { model, messageCount: messages?.length });
|
console.log('[Title API] Request received:', {
|
||||||
|
model: TITLE_MODEL,
|
||||||
|
messageCount: messages?.length,
|
||||||
|
});
|
||||||
|
|
||||||
if (!model || !messages || !Array.isArray(messages) || messages.length === 0) {
|
if (!messages || !Array.isArray(messages) || messages.length === 0) {
|
||||||
return NextResponse.json({ error: 'Model and messages array are required' }, { status: 400 });
|
return NextResponse.json({ error: 'Messages array is required' }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the conversation for context (truncate long messages)
|
// Format the conversation for context (truncate long messages)
|
||||||
@@ -44,7 +50,7 @@ Rules:
|
|||||||
- "React Component Tutorial"`;
|
- "React Component Tutorial"`;
|
||||||
|
|
||||||
const response = await ollama.chat({
|
const response = await ollama.chat({
|
||||||
model,
|
model: TITLE_MODEL,
|
||||||
messages: [
|
messages: [
|
||||||
{ role: 'system', content: systemPrompt },
|
{ role: 'system', content: systemPrompt },
|
||||||
{
|
{
|
||||||
@@ -54,7 +60,7 @@ Rules:
|
|||||||
],
|
],
|
||||||
options: {
|
options: {
|
||||||
temperature: 0.3, // Lower temperature for more focused output
|
temperature: 0.3, // Lower temperature for more focused output
|
||||||
num_predict: 20, // Limit output length
|
num_predict: 50, // Allow more tokens for thinking models
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ export default function ChatLayout() {
|
|||||||
// Generate a title for new chats using the model
|
// Generate a title for new chats using the model
|
||||||
let chatTitle = `${userMessage.content.slice(0, 30)}...`; // Fallback title
|
let chatTitle = `${userMessage.content.slice(0, 30)}...`; // Fallback title
|
||||||
|
|
||||||
if (isNewChat && selectedModel) {
|
if (isNewChat) {
|
||||||
try {
|
try {
|
||||||
// Build conversation context (excluding the initial greeting)
|
// Build conversation context (excluding the initial greeting)
|
||||||
const conversationForTitle = [...newMessages, responseMessage]
|
const conversationForTitle = [...newMessages, responseMessage]
|
||||||
@@ -460,7 +460,6 @@ export default function ChatLayout() {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: selectedModel,
|
|
||||||
messages: conversationForTitle,
|
messages: conversationForTitle,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user