Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #580

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
46 changes: 33 additions & 13 deletions app/(chat)/actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use server';

import { type CoreUserMessage, generateText } from 'ai';
import { type CoreUserMessage, Message } from 'ai';
import { cookies } from 'next/headers';

import { customModel } from '@/lib/ai';

export async function saveModelId(model: string) {
const cookieStore = await cookies();
cookieStore.set('model-id', model);
Expand All @@ -13,17 +11,39 @@ export async function saveModelId(model: string) {
export async function generateTitleFromUserMessage({
message,
}: {
message: CoreUserMessage;
message: Message;
}) {
const { text: title } = await generateText({
model: customModel('gpt-4o-mini'),
system: `\n
- you will generate a short title based on the first message a user begins a conversation with
- ensure it is not more than 80 characters long
- the title should be a summary of the user's message
- do not use quotes or colons`,
prompt: JSON.stringify(message),
const response = await fetch('https://api.groq.com/openai/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.GROQ_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'mixtral-8x7b-32768', // or your preferred Groq model
messages: [
{
role: 'system',
content: `
- you will generate a short title based on the first message a user begins a conversation with
- ensure it is not more than 80 characters long
- the title should be a summary of the user's message
- do not use quotes or colons`
},
{
role: 'user',
content: message.content
}
],
temperature: 0.7,
max_tokens: 100,
}),
});

return title;
if (!response.ok) {
throw new Error(`Groq API error: ${response.statusText}`);
}

const result = await response.json();
return result.choices[0].message.content.trim();
}
Loading