mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-05-04 10:12:34 +00:00
Compare commits
2 Commits
fec42d1927
...
v1.10.2
Author | SHA1 | Date | |
---|---|---|---|
|
a85f762c58 | ||
|
3ddcceda0a |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "perplexica-frontend",
|
"name": "perplexica-frontend",
|
||||||
"version": "1.10.1",
|
"version": "1.10.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "ItzCrazyKns",
|
"author": "ItzCrazyKns",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -29,7 +29,6 @@ type Message = {
|
|||||||
messageId: string;
|
messageId: string;
|
||||||
chatId: string;
|
chatId: string;
|
||||||
content: string;
|
content: string;
|
||||||
userSessionId: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type ChatModel = {
|
type ChatModel = {
|
||||||
@ -139,7 +138,6 @@ const handleHistorySave = async (
|
|||||||
where: eq(chats.id, message.chatId),
|
where: eq(chats.id, message.chatId),
|
||||||
});
|
});
|
||||||
|
|
||||||
let currentDate = new Date();
|
|
||||||
if (!chat) {
|
if (!chat) {
|
||||||
await db
|
await db
|
||||||
.insert(chats)
|
.insert(chats)
|
||||||
@ -149,8 +147,6 @@ const handleHistorySave = async (
|
|||||||
createdAt: new Date().toString(),
|
createdAt: new Date().toString(),
|
||||||
focusMode: focusMode,
|
focusMode: focusMode,
|
||||||
files: files.map(getFileDetails),
|
files: files.map(getFileDetails),
|
||||||
userSessionId: message.userSessionId,
|
|
||||||
timestamp: currentDate.toISOString(),
|
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
@ -1,47 +1,10 @@
|
|||||||
import db from '@/lib/db';
|
import db from '@/lib/db';
|
||||||
import { chats } from '@/lib/db/schema';
|
|
||||||
import { eq, sql} from 'drizzle-orm';
|
|
||||||
|
|
||||||
export const GET = async (req: Request) => {
|
export const GET = async (req: Request) => {
|
||||||
try {
|
try {
|
||||||
// get header from request
|
let chats = await db.query.chats.findMany();
|
||||||
const headers = await req.headers;
|
chats = chats.reverse();
|
||||||
let userSessionId = headers.get('user-session-id')?.toString() ?? '';
|
return Response.json({ chats: chats }, { status: 200 });
|
||||||
|
|
||||||
if (userSessionId == '') {
|
|
||||||
return Response.json({ chats: {} }, { status: 200 });
|
|
||||||
}
|
|
||||||
|
|
||||||
let chatsRes = await db.query.chats.findMany({
|
|
||||||
where: eq(chats.userSessionId, userSessionId),
|
|
||||||
});
|
|
||||||
|
|
||||||
chatsRes = chatsRes.reverse();
|
|
||||||
// Keep only the latest 20 records in the database. Delete older records.
|
|
||||||
let maxRecordLimit = 20;
|
|
||||||
if (chatsRes.length > maxRecordLimit) {
|
|
||||||
const deleteChatsQuery = sql`DELETE FROM chats
|
|
||||||
WHERE userSessionId = ${userSessionId} AND (
|
|
||||||
timestamp IS NULL OR
|
|
||||||
timestamp NOT in (
|
|
||||||
SELECT timestamp FROM chats
|
|
||||||
WHERE userSessionId = ${userSessionId}
|
|
||||||
ORDER BY timestamp DESC
|
|
||||||
LIMIT ${maxRecordLimit}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
`;
|
|
||||||
await db.run(deleteChatsQuery);
|
|
||||||
// Delete messages that no longer link with the chat from the database.
|
|
||||||
const deleteMessagesQuery = sql`DELETE FROM messages
|
|
||||||
WHERE chatId NOT IN (
|
|
||||||
SELECT id FROM chats
|
|
||||||
)
|
|
||||||
`;
|
|
||||||
await db.run(deleteMessagesQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Response.json({ chats: chatsRes }, { status: 200 });
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error in getting chats: ', err);
|
console.error('Error in getting chats: ', err);
|
||||||
return Response.json(
|
return Response.json(
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import crypto from 'crypto';
|
|
||||||
import DeleteChat from '@/components/DeleteChat';
|
import DeleteChat from '@/components/DeleteChat';
|
||||||
import { cn, formatTimeDifference } from '@/lib/utils';
|
import { cn, formatTimeDifference } from '@/lib/utils';
|
||||||
import { BookOpenText, ClockIcon, Delete, ScanEye } from 'lucide-react';
|
import { BookOpenText, ClockIcon, Delete, ScanEye } from 'lucide-react';
|
||||||
@ -22,17 +21,10 @@ const Page = () => {
|
|||||||
const fetchChats = async () => {
|
const fetchChats = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
let userSessionId = localStorage.getItem('userSessionId');
|
|
||||||
if (!userSessionId) {
|
|
||||||
userSessionId = crypto.randomBytes(20).toString('hex');
|
|
||||||
localStorage.setItem('userSessionId', userSessionId)
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await fetch(`/api/chats`, {
|
const res = await fetch(`/api/chats`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'user-session-id': userSessionId!,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -95,12 +95,6 @@ const checkConfig = async (
|
|||||||
if (!embeddingModel || !embeddingModelProvider) {
|
if (!embeddingModel || !embeddingModelProvider) {
|
||||||
const embeddingModelProviders = providers.embeddingModelProviders;
|
const embeddingModelProviders = providers.embeddingModelProviders;
|
||||||
|
|
||||||
let userSessionId = localStorage.getItem('userSessionId');
|
|
||||||
if (!userSessionId) {
|
|
||||||
userSessionId = crypto.randomBytes(20).toString('hex');
|
|
||||||
localStorage.setItem('userSessionId', userSessionId!)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!embeddingModelProviders ||
|
!embeddingModelProviders ||
|
||||||
Object.keys(embeddingModelProviders).length === 0
|
Object.keys(embeddingModelProviders).length === 0
|
||||||
@ -348,7 +342,6 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
|||||||
let added = false;
|
let added = false;
|
||||||
|
|
||||||
messageId = messageId ?? crypto.randomBytes(7).toString('hex');
|
messageId = messageId ?? crypto.randomBytes(7).toString('hex');
|
||||||
let userSessionId = localStorage.getItem('userSessionId');
|
|
||||||
|
|
||||||
setMessages((prevMessages) => [
|
setMessages((prevMessages) => [
|
||||||
...prevMessages,
|
...prevMessages,
|
||||||
@ -473,7 +466,6 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
|||||||
messageId: messageId,
|
messageId: messageId,
|
||||||
chatId: chatId!,
|
chatId: chatId!,
|
||||||
content: message,
|
content: message,
|
||||||
userSessionId: userSessionId,
|
|
||||||
},
|
},
|
||||||
chatId: chatId!,
|
chatId: chatId!,
|
||||||
files: fileIds,
|
files: fileIds,
|
||||||
|
@ -25,6 +25,4 @@ export const chats = sqliteTable('chats', {
|
|||||||
files: text('files', { mode: 'json' })
|
files: text('files', { mode: 'json' })
|
||||||
.$type<File[]>()
|
.$type<File[]>()
|
||||||
.default(sql`'[]'`),
|
.default(sql`'[]'`),
|
||||||
userSessionId: text('userSessionId'),
|
|
||||||
timestamp: text('timestamp'),
|
|
||||||
});
|
});
|
||||||
|
@ -40,8 +40,12 @@ const geminiChatModels: Record<string, string>[] = [
|
|||||||
|
|
||||||
const geminiEmbeddingModels: Record<string, string>[] = [
|
const geminiEmbeddingModels: Record<string, string>[] = [
|
||||||
{
|
{
|
||||||
displayName: 'Gemini Embedding',
|
displayName: 'Text Embedding 004',
|
||||||
key: 'gemini-embedding-exp',
|
key: 'models/text-embedding-004',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Embedding 001',
|
||||||
|
key: 'models/embedding-001',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user