Adds full text indexes, and advanced search capabilities to the StyleAI chat bot.
This commit is contained in:
parent
ef002ec79b
commit
8dda301461
11 changed files with 252 additions and 36 deletions
|
@ -28,13 +28,13 @@ async function getUserAuthenticators(userId)
|
|||
}
|
||||
|
||||
// Helper function to get a user by username
|
||||
async function getUserByUsername(username)
|
||||
export async function getUserByUsername(username)
|
||||
{
|
||||
return prisma.user.findUnique({ where: { username } });
|
||||
}
|
||||
|
||||
// Helper function to get a user by ID
|
||||
async function getUserById(id)
|
||||
export async function getUserById(id)
|
||||
{
|
||||
return prisma.user.findUnique({ where: { id } });
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import { requireAuth } from '../middlewares/authMiddleware.js'; // Import the mi
|
|||
|
||||
import { askGeminiChat } from '../utils/gemini.js';
|
||||
|
||||
import { getUserById } from './auth.js';
|
||||
|
||||
const router = Router();
|
||||
|
||||
// Apply the authentication middleware to all chat routes
|
||||
|
@ -47,7 +49,14 @@ router.post('/threads', async(req, res) =>
|
|||
|
||||
if(content)
|
||||
{
|
||||
await askGeminiChat(newThread.id, content); // Call the function to handle the bot response
|
||||
const user = await getUserById(req.session.loggedInUserId);
|
||||
if (!user)
|
||||
{
|
||||
req.session.destroy(err =>
|
||||
{});
|
||||
return res.status(401).json({ status: 'unauthenticated' });
|
||||
}
|
||||
await askGeminiChat(newThread.id, `[${user.fullName || user.username}] ${content}`);
|
||||
}
|
||||
|
||||
// Respond with the new thread ID and messages (if any)
|
||||
|
@ -146,7 +155,14 @@ router.post('/threads/:threadId/messages', async(req, res) =>
|
|||
data: { updatedAt: new Date() }
|
||||
});
|
||||
|
||||
await askGeminiChat(threadId, content); // Call the function to handle the bot response
|
||||
const user = await getUserById(req.session.loggedInUserId);
|
||||
if (!user)
|
||||
{
|
||||
req.session.destroy(err =>
|
||||
{});
|
||||
return res.status(401).json({ status: 'unauthenticated' });
|
||||
}
|
||||
await askGeminiChat(threadId, `[${user.fullName || user.username}] ${content}`);
|
||||
|
||||
res.status(201).json({ ...newMessage, createdAt: newMessage.createdAt.toISOString() });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue