Skip to content

Commit

Permalink
update naming
Browse files Browse the repository at this point in the history
  • Loading branch information
hyusap committed Jan 18, 2025
1 parent 664b1dc commit 27557b7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
15 changes: 8 additions & 7 deletions www/app/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ What's on your mind? Let's dive in. 🌱`,
}
}

async function processSummary(messageToSend: string, conversationId: string) {
const summaryResponse = await fetch('/api/chat/summary', {
async function processName(messageToSend: string, conversationId: string) {
const nameResponse = await fetch('/api/chat/name', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -406,9 +406,9 @@ What's on your mind? Let's dive in. 🌱`,
}),
});

if (summaryResponse.ok) {
const { summary } = await summaryResponse.json();
await updateConversation(conversationId, summary);
if (nameResponse.ok) {
const { name } = await nameResponse.json();
await updateConversation(conversationId, name);
await mutateConversations();
}
}
Expand Down Expand Up @@ -454,7 +454,7 @@ What's on your mind? Let's dive in. 🌱`,
const [thoughtText] = await Promise.all([
processThought(messageToSend, conversationId!),
...(shouldGenerateSummary
? [processSummary(messageToSend, conversationId!)]
? [processName(messageToSend, conversationId!)]
: []),
]);

Expand Down Expand Up @@ -552,7 +552,8 @@ What's on your mind? Let's dive in. 🌱`,
<div className="p-3 pb-0 lg:p-5 lg:pb-0">
{messages!.length > 1 && (
<div className="disclaimer-text text-center mb-2">
Bloom can make mistakes. Always double-check important information.
Bloom can make mistakes. Always double-check important
information.
</div>
)}
<form
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createCompletion, getUserData, user } from '@/utils/ai';
import { summaryPrompt } from '@/utils/prompts/summary';
import { namePrompt } from '@/utils/prompts/name';
import { NextRequest, NextResponse } from 'next/server';

export const runtime = 'nodejs';
Expand All @@ -16,13 +16,13 @@ export async function POST(req: NextRequest) {
const { userId } = userData;

const finalMessage = user`${message}`;
const prompt = [...summaryPrompt, finalMessage];
const prompt = [...namePrompt, finalMessage];

const completion = await createCompletion(prompt, {
sessionId: 'summary',
sessionId: 'name',
userId,
type: 'summary',
type: 'name',
});

return NextResponse.json({ summary: completion.text });
return NextResponse.json({ name: completion.text });
}
17 changes: 17 additions & 0 deletions www/utils/prompts/name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Message, user, assistant } from '@/utils/ai';
export const namePrompt: Message[] = [
user`Your task is to create a 5-word or less summary of the conversation topic, starting with an action verb.
Rules:
1. Must start with an action verb
2. Maximum 5 words
3. Be specific but concise
4. Focus on the core topic/goal
Does that make sense?`,
assistant`Yes, it makes sense. Send the first message whenever you're ready.`,
user`I want to learn about quantum physics and understand the basic principles behind quantum mechanics`,
assistant`Exploring quantum physics fundamentals`,
user`Can you help me write a poem about love and loss? I want it to be meaningful and touching`,
assistant`Crafting emotional love poetry`,
];

0 comments on commit 27557b7

Please sign in to comment.