mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-12-16 16:48:14 +00:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
874505cd0e | ||
|
|
b4a80d8ca0 | ||
|
|
c7bab91803 | ||
|
|
a58adbfecc | ||
|
|
9e746aea5e | ||
|
|
5e1331144a | ||
|
|
d789c970b1 | ||
|
|
e699cb2921 | ||
|
|
03eed9693b | ||
|
|
011570dd9b | ||
|
|
18529391f4 | ||
|
|
a1a7470ca6 | ||
|
|
10c5ac1076 | ||
|
|
7c01d2656e | ||
|
|
afb4786ac0 | ||
|
|
1e99fe8d69 | ||
|
|
012dfa5a74 | ||
|
|
65d057a05e | ||
|
|
3e7645614f | ||
|
|
7c6ee2ead1 | ||
|
|
540f38ae68 | ||
|
|
f1c0b5435b | ||
|
|
b33e5fefba | ||
|
|
03d0ff2ca4 | ||
|
|
687cbb365f |
Binary file not shown.
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 641 KiB |
@@ -18,7 +18,8 @@ Before diving into coding, setting up your local environment is key. Here's what
|
|||||||
1. In the root directory, locate the `sample.config.toml` file.
|
1. In the root directory, locate the `sample.config.toml` file.
|
||||||
2. Rename it to `config.toml` and fill in the necessary configuration fields specific to the backend.
|
2. Rename it to `config.toml` and fill in the necessary configuration fields specific to the backend.
|
||||||
3. Run `npm install` to install dependencies.
|
3. Run `npm install` to install dependencies.
|
||||||
4. Use `npm run dev` to start the backend in development mode.
|
4. Run `npm run db:push` to set up the local sqlite.
|
||||||
|
5. Use `npm run dev` to start the backend in development mode.
|
||||||
|
|
||||||
### Frontend
|
### Frontend
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# 🚀 Perplexica - An AI-powered search engine 🔎 <!-- omit in toc -->
|
# 🚀 Perplexica - An AI-powered search engine 🔎 <!-- omit in toc -->
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Table of Contents <!-- omit in toc -->
|
## Table of Contents <!-- omit in toc -->
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM node:alpine
|
FROM node:20.18.0-alpine
|
||||||
|
|
||||||
ARG NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001
|
ARG NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001
|
||||||
ARG NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api
|
ARG NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "perplexica-backend",
|
"name": "perplexica-backend",
|
||||||
"version": "1.9.1",
|
"version": "1.9.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "ItzCrazyKns",
|
"author": "ItzCrazyKns",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ const createBasicWebSearchAnsweringChain = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (query.toLocaleLowerCase() === 'summarize') {
|
if (query.toLocaleLowerCase() === 'summarize') {
|
||||||
return docs;
|
return docs.slice(0, 15)
|
||||||
}
|
}
|
||||||
|
|
||||||
const docsWithContent = docs.filter(
|
const docsWithContent = docs.filter(
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class LineListOutputParser extends BaseOutputParser<string[]> {
|
|||||||
const startKeyIndex = text.indexOf(`<${this.key}>`);
|
const startKeyIndex = text.indexOf(`<${this.key}>`);
|
||||||
const endKeyIndex = text.indexOf(`</${this.key}>`);
|
const endKeyIndex = text.indexOf(`</${this.key}>`);
|
||||||
|
|
||||||
if (startKeyIndex === -1 || endKeyIndex === -1) {
|
if (startKeyIndex === -1 && endKeyIndex === -1) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,28 @@ import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|||||||
import { getAvailableChatModelProviders } from '../lib/providers';
|
import { getAvailableChatModelProviders } from '../lib/providers';
|
||||||
import { HumanMessage, AIMessage } from '@langchain/core/messages';
|
import { HumanMessage, AIMessage } from '@langchain/core/messages';
|
||||||
import logger from '../utils/logger';
|
import logger from '../utils/logger';
|
||||||
|
import { ChatOpenAI } from '@langchain/openai';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
interface ChatModel {
|
||||||
|
provider: string;
|
||||||
|
model: string;
|
||||||
|
customOpenAIBaseURL?: string;
|
||||||
|
customOpenAIKey?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImageSearchBody {
|
||||||
|
query: string;
|
||||||
|
chatHistory: any[];
|
||||||
|
chatModel?: ChatModel;
|
||||||
|
}
|
||||||
|
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
let { query, chat_history, chat_model_provider, chat_model } = req.body;
|
let body: ImageSearchBody = req.body;
|
||||||
|
|
||||||
chat_history = chat_history.map((msg: any) => {
|
const chatHistory = body.chatHistory.map((msg: any) => {
|
||||||
if (msg.role === 'user') {
|
if (msg.role === 'user') {
|
||||||
return new HumanMessage(msg.content);
|
return new HumanMessage(msg.content);
|
||||||
} else if (msg.role === 'assistant') {
|
} else if (msg.role === 'assistant') {
|
||||||
@@ -19,22 +33,50 @@ router.post('/', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const chatModels = await getAvailableChatModelProviders();
|
const chatModelProviders = await getAvailableChatModelProviders();
|
||||||
const provider = chat_model_provider ?? Object.keys(chatModels)[0];
|
|
||||||
const chatModel = chat_model ?? Object.keys(chatModels[provider])[0];
|
const chatModelProvider =
|
||||||
|
body.chatModel?.provider || Object.keys(chatModelProviders)[0];
|
||||||
|
const chatModel =
|
||||||
|
body.chatModel?.model ||
|
||||||
|
Object.keys(chatModelProviders[chatModelProvider])[0];
|
||||||
|
|
||||||
let llm: BaseChatModel | undefined;
|
let llm: BaseChatModel | undefined;
|
||||||
|
|
||||||
if (chatModels[provider] && chatModels[provider][chatModel]) {
|
if (body.chatModel?.provider === 'custom_openai') {
|
||||||
llm = chatModels[provider][chatModel].model as BaseChatModel | undefined;
|
if (
|
||||||
|
!body.chatModel?.customOpenAIBaseURL ||
|
||||||
|
!body.chatModel?.customOpenAIKey
|
||||||
|
) {
|
||||||
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({ message: 'Missing custom OpenAI base URL or key' });
|
||||||
|
}
|
||||||
|
|
||||||
|
llm = new ChatOpenAI({
|
||||||
|
modelName: body.chatModel.model,
|
||||||
|
openAIApiKey: body.chatModel.customOpenAIKey,
|
||||||
|
temperature: 0.7,
|
||||||
|
configuration: {
|
||||||
|
baseURL: body.chatModel.customOpenAIBaseURL,
|
||||||
|
},
|
||||||
|
}) as unknown as BaseChatModel;
|
||||||
|
} else if (
|
||||||
|
chatModelProviders[chatModelProvider] &&
|
||||||
|
chatModelProviders[chatModelProvider][chatModel]
|
||||||
|
) {
|
||||||
|
llm = chatModelProviders[chatModelProvider][chatModel]
|
||||||
|
.model as unknown as BaseChatModel | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!llm) {
|
if (!llm) {
|
||||||
res.status(500).json({ message: 'Invalid LLM model selected' });
|
return res.status(400).json({ message: 'Invalid model selected' });
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const images = await handleImageSearch({ query, chat_history }, llm);
|
const images = await handleImageSearch(
|
||||||
|
{ query: body.query, chat_history: chatHistory },
|
||||||
|
llm,
|
||||||
|
);
|
||||||
|
|
||||||
res.status(200).json({ images });
|
res.status(200).json({ images });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -4,14 +4,27 @@ import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|||||||
import { getAvailableChatModelProviders } from '../lib/providers';
|
import { getAvailableChatModelProviders } from '../lib/providers';
|
||||||
import { HumanMessage, AIMessage } from '@langchain/core/messages';
|
import { HumanMessage, AIMessage } from '@langchain/core/messages';
|
||||||
import logger from '../utils/logger';
|
import logger from '../utils/logger';
|
||||||
|
import { ChatOpenAI } from '@langchain/openai';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
interface ChatModel {
|
||||||
|
provider: string;
|
||||||
|
model: string;
|
||||||
|
customOpenAIBaseURL?: string;
|
||||||
|
customOpenAIKey?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SuggestionsBody {
|
||||||
|
chatHistory: any[];
|
||||||
|
chatModel?: ChatModel;
|
||||||
|
}
|
||||||
|
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
let { chat_history, chat_model, chat_model_provider } = req.body;
|
let body: SuggestionsBody = req.body;
|
||||||
|
|
||||||
chat_history = chat_history.map((msg: any) => {
|
const chatHistory = body.chatHistory.map((msg: any) => {
|
||||||
if (msg.role === 'user') {
|
if (msg.role === 'user') {
|
||||||
return new HumanMessage(msg.content);
|
return new HumanMessage(msg.content);
|
||||||
} else if (msg.role === 'assistant') {
|
} else if (msg.role === 'assistant') {
|
||||||
@@ -19,22 +32,50 @@ router.post('/', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const chatModels = await getAvailableChatModelProviders();
|
const chatModelProviders = await getAvailableChatModelProviders();
|
||||||
const provider = chat_model_provider ?? Object.keys(chatModels)[0];
|
|
||||||
const chatModel = chat_model ?? Object.keys(chatModels[provider])[0];
|
const chatModelProvider =
|
||||||
|
body.chatModel?.provider || Object.keys(chatModelProviders)[0];
|
||||||
|
const chatModel =
|
||||||
|
body.chatModel?.model ||
|
||||||
|
Object.keys(chatModelProviders[chatModelProvider])[0];
|
||||||
|
|
||||||
let llm: BaseChatModel | undefined;
|
let llm: BaseChatModel | undefined;
|
||||||
|
|
||||||
if (chatModels[provider] && chatModels[provider][chatModel]) {
|
if (body.chatModel?.provider === 'custom_openai') {
|
||||||
llm = chatModels[provider][chatModel].model as BaseChatModel | undefined;
|
if (
|
||||||
|
!body.chatModel?.customOpenAIBaseURL ||
|
||||||
|
!body.chatModel?.customOpenAIKey
|
||||||
|
) {
|
||||||
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({ message: 'Missing custom OpenAI base URL or key' });
|
||||||
|
}
|
||||||
|
|
||||||
|
llm = new ChatOpenAI({
|
||||||
|
modelName: body.chatModel.model,
|
||||||
|
openAIApiKey: body.chatModel.customOpenAIKey,
|
||||||
|
temperature: 0.7,
|
||||||
|
configuration: {
|
||||||
|
baseURL: body.chatModel.customOpenAIBaseURL,
|
||||||
|
},
|
||||||
|
}) as unknown as BaseChatModel;
|
||||||
|
} else if (
|
||||||
|
chatModelProviders[chatModelProvider] &&
|
||||||
|
chatModelProviders[chatModelProvider][chatModel]
|
||||||
|
) {
|
||||||
|
llm = chatModelProviders[chatModelProvider][chatModel]
|
||||||
|
.model as unknown as BaseChatModel | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!llm) {
|
if (!llm) {
|
||||||
res.status(500).json({ message: 'Invalid LLM model selected' });
|
return res.status(400).json({ message: 'Invalid model selected' });
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const suggestions = await generateSuggestions({ chat_history }, llm);
|
const suggestions = await generateSuggestions(
|
||||||
|
{ chat_history: chatHistory },
|
||||||
|
llm,
|
||||||
|
);
|
||||||
|
|
||||||
res.status(200).json({ suggestions: suggestions });
|
res.status(200).json({ suggestions: suggestions });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -4,14 +4,28 @@ import { getAvailableChatModelProviders } from '../lib/providers';
|
|||||||
import { HumanMessage, AIMessage } from '@langchain/core/messages';
|
import { HumanMessage, AIMessage } from '@langchain/core/messages';
|
||||||
import logger from '../utils/logger';
|
import logger from '../utils/logger';
|
||||||
import handleVideoSearch from '../agents/videoSearchAgent';
|
import handleVideoSearch from '../agents/videoSearchAgent';
|
||||||
|
import { ChatOpenAI } from '@langchain/openai';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
interface ChatModel {
|
||||||
|
provider: string;
|
||||||
|
model: string;
|
||||||
|
customOpenAIBaseURL?: string;
|
||||||
|
customOpenAIKey?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface VideoSearchBody {
|
||||||
|
query: string;
|
||||||
|
chatHistory: any[];
|
||||||
|
chatModel?: ChatModel;
|
||||||
|
}
|
||||||
|
|
||||||
router.post('/', async (req, res) => {
|
router.post('/', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
let { query, chat_history, chat_model_provider, chat_model } = req.body;
|
let body: VideoSearchBody = req.body;
|
||||||
|
|
||||||
chat_history = chat_history.map((msg: any) => {
|
const chatHistory = body.chatHistory.map((msg: any) => {
|
||||||
if (msg.role === 'user') {
|
if (msg.role === 'user') {
|
||||||
return new HumanMessage(msg.content);
|
return new HumanMessage(msg.content);
|
||||||
} else if (msg.role === 'assistant') {
|
} else if (msg.role === 'assistant') {
|
||||||
@@ -19,22 +33,50 @@ router.post('/', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const chatModels = await getAvailableChatModelProviders();
|
const chatModelProviders = await getAvailableChatModelProviders();
|
||||||
const provider = chat_model_provider ?? Object.keys(chatModels)[0];
|
|
||||||
const chatModel = chat_model ?? Object.keys(chatModels[provider])[0];
|
const chatModelProvider =
|
||||||
|
body.chatModel?.provider || Object.keys(chatModelProviders)[0];
|
||||||
|
const chatModel =
|
||||||
|
body.chatModel?.model ||
|
||||||
|
Object.keys(chatModelProviders[chatModelProvider])[0];
|
||||||
|
|
||||||
let llm: BaseChatModel | undefined;
|
let llm: BaseChatModel | undefined;
|
||||||
|
|
||||||
if (chatModels[provider] && chatModels[provider][chatModel]) {
|
if (body.chatModel?.provider === 'custom_openai') {
|
||||||
llm = chatModels[provider][chatModel].model as BaseChatModel | undefined;
|
if (
|
||||||
|
!body.chatModel?.customOpenAIBaseURL ||
|
||||||
|
!body.chatModel?.customOpenAIKey
|
||||||
|
) {
|
||||||
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({ message: 'Missing custom OpenAI base URL or key' });
|
||||||
|
}
|
||||||
|
|
||||||
|
llm = new ChatOpenAI({
|
||||||
|
modelName: body.chatModel.model,
|
||||||
|
openAIApiKey: body.chatModel.customOpenAIKey,
|
||||||
|
temperature: 0.7,
|
||||||
|
configuration: {
|
||||||
|
baseURL: body.chatModel.customOpenAIBaseURL,
|
||||||
|
},
|
||||||
|
}) as unknown as BaseChatModel;
|
||||||
|
} else if (
|
||||||
|
chatModelProviders[chatModelProvider] &&
|
||||||
|
chatModelProviders[chatModelProvider][chatModel]
|
||||||
|
) {
|
||||||
|
llm = chatModelProviders[chatModelProvider][chatModel]
|
||||||
|
.model as unknown as BaseChatModel | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!llm) {
|
if (!llm) {
|
||||||
res.status(500).json({ message: 'Invalid LLM model selected' });
|
return res.status(400).json({ message: 'Invalid model selected' });
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const videos = await handleVideoSearch({ chat_history, query }, llm);
|
const videos = await handleVideoSearch(
|
||||||
|
{ chat_history: chatHistory, query: body.query },
|
||||||
|
llm,
|
||||||
|
);
|
||||||
|
|
||||||
res.status(200).json({ videos });
|
res.status(200).json({ videos });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ const Page = () => {
|
|||||||
href={`/?q=Summary: ${item.url}`}
|
href={`/?q=Summary: ${item.url}`}
|
||||||
key={i}
|
key={i}
|
||||||
className="max-w-sm rounded-lg overflow-hidden bg-light-secondary dark:bg-dark-secondary hover:-translate-y-[1px] transition duration-200"
|
className="max-w-sm rounded-lg overflow-hidden bg-light-secondary dark:bg-dark-secondary hover:-translate-y-[1px] transition duration-200"
|
||||||
|
target="_blank"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
className="object-cover w-full aspect-video"
|
className="object-cover w-full aspect-video"
|
||||||
|
|||||||
@@ -318,6 +318,7 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
|||||||
console.log('[DEBUG] closed');
|
console.log('[DEBUG] closed');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const messagesRef = useRef<Message[]>([]);
|
const messagesRef = useRef<Message[]>([]);
|
||||||
@@ -503,7 +504,7 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
|||||||
<div>
|
<div>
|
||||||
{messages.length > 0 ? (
|
{messages.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
<Navbar messages={messages} />
|
<Navbar chatId={chatId!} messages={messages} />
|
||||||
<Chat
|
<Chat
|
||||||
loading={loading}
|
loading={loading}
|
||||||
messages={messages}
|
messages={messages}
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ const DeleteChat = ({
|
|||||||
chatId,
|
chatId,
|
||||||
chats,
|
chats,
|
||||||
setChats,
|
setChats,
|
||||||
|
redirect = false,
|
||||||
}: {
|
}: {
|
||||||
chatId: string;
|
chatId: string;
|
||||||
chats: Chat[];
|
chats: Chat[];
|
||||||
setChats: (chats: Chat[]) => void;
|
setChats: (chats: Chat[]) => void;
|
||||||
|
redirect?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
|
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -44,6 +46,10 @@ const DeleteChat = ({
|
|||||||
const newChats = chats.filter((chat) => chat.id !== chatId);
|
const newChats = chats.filter((chat) => chat.id !== chatId);
|
||||||
|
|
||||||
setChats(newChats);
|
setChats(newChats);
|
||||||
|
|
||||||
|
if (redirect) {
|
||||||
|
window.location.href = '/';
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
toast.error(err.message);
|
toast.error(err.message);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
import { Settings } from 'lucide-react';
|
||||||
import EmptyChatMessageInput from './EmptyChatMessageInput';
|
import EmptyChatMessageInput from './EmptyChatMessageInput';
|
||||||
|
import SettingsDialog from './SettingsDialog';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
const EmptyChat = ({
|
const EmptyChat = ({
|
||||||
sendMessage,
|
sendMessage,
|
||||||
@@ -13,8 +16,17 @@ const EmptyChat = ({
|
|||||||
optimizationMode: string;
|
optimizationMode: string;
|
||||||
setOptimizationMode: (mode: string) => void;
|
setOptimizationMode: (mode: string) => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
<SettingsDialog isOpen={isSettingsOpen} setIsOpen={setIsSettingsOpen} />
|
||||||
|
<div className="absolute w-full flex flex-row items-center justify-end mr-5 mt-5">
|
||||||
|
<Settings
|
||||||
|
className="cursor-pointer lg:hidden"
|
||||||
|
onClick={() => setIsSettingsOpen(true)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="flex flex-col items-center justify-center min-h-screen max-w-screen-sm mx-auto p-2 space-y-8">
|
<div className="flex flex-col items-center justify-center min-h-screen max-w-screen-sm mx-auto p-2 space-y-8">
|
||||||
<h2 className="text-black/70 dark:text-white/70 text-3xl font-medium -mt-8">
|
<h2 className="text-black/70 dark:text-white/70 text-3xl font-medium -mt-8">
|
||||||
Research begins here.
|
Research begins here.
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ const EmptyChatMessageInput = ({
|
|||||||
|
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
document.addEventListener('keydown', handleKeyDown);
|
||||||
|
|
||||||
|
inputRef.current?.focus();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('keydown', handleKeyDown);
|
document.removeEventListener('keydown', handleKeyDown);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -186,10 +186,10 @@ const MessageBox = ({
|
|||||||
<div className="lg:sticky lg:top-20 flex flex-col items-center space-y-3 w-full lg:w-3/12 z-30 h-full pb-4">
|
<div className="lg:sticky lg:top-20 flex flex-col items-center space-y-3 w-full lg:w-3/12 z-30 h-full pb-4">
|
||||||
<SearchImages
|
<SearchImages
|
||||||
query={history[messageIndex - 1].content}
|
query={history[messageIndex - 1].content}
|
||||||
chat_history={history.slice(0, messageIndex - 1)}
|
chatHistory={history.slice(0, messageIndex - 1)}
|
||||||
/>
|
/>
|
||||||
<SearchVideos
|
<SearchVideos
|
||||||
chat_history={history.slice(0, messageIndex - 1)}
|
chatHistory={history.slice(0, messageIndex - 1)}
|
||||||
query={history[messageIndex - 1].content}
|
query={history[messageIndex - 1].content}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,8 +2,15 @@ import { Clock, Edit, Share, Trash } from 'lucide-react';
|
|||||||
import { Message } from './ChatWindow';
|
import { Message } from './ChatWindow';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { formatTimeDifference } from '@/lib/utils';
|
import { formatTimeDifference } from '@/lib/utils';
|
||||||
|
import DeleteChat from './DeleteChat';
|
||||||
|
|
||||||
const Navbar = ({ messages }: { messages: Message[] }) => {
|
const Navbar = ({
|
||||||
|
chatId,
|
||||||
|
messages,
|
||||||
|
}: {
|
||||||
|
messages: Message[];
|
||||||
|
chatId: string;
|
||||||
|
}) => {
|
||||||
const [title, setTitle] = useState<string>('');
|
const [title, setTitle] = useState<string>('');
|
||||||
const [timeAgo, setTimeAgo] = useState<string>('');
|
const [timeAgo, setTimeAgo] = useState<string>('');
|
||||||
|
|
||||||
@@ -39,10 +46,12 @@ const Navbar = ({ messages }: { messages: Message[] }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed z-40 top-0 left-0 right-0 px-4 lg:pl-[104px] lg:pr-6 lg:px-8 flex flex-row items-center justify-between w-full py-4 text-sm text-black dark:text-white/70 border-b bg-light-primary dark:bg-dark-primary border-light-100 dark:border-dark-200">
|
<div className="fixed z-40 top-0 left-0 right-0 px-4 lg:pl-[104px] lg:pr-6 lg:px-8 flex flex-row items-center justify-between w-full py-4 text-sm text-black dark:text-white/70 border-b bg-light-primary dark:bg-dark-primary border-light-100 dark:border-dark-200">
|
||||||
<Edit
|
<a
|
||||||
size={17}
|
href="/"
|
||||||
className="active:scale-95 transition duration-100 cursor-pointer lg:hidden"
|
className="active:scale-95 transition duration-100 cursor-pointer lg:hidden"
|
||||||
/>
|
>
|
||||||
|
<Edit size={17} />
|
||||||
|
</a>
|
||||||
<div className="hidden lg:flex flex-row items-center justify-center space-x-2">
|
<div className="hidden lg:flex flex-row items-center justify-center space-x-2">
|
||||||
<Clock size={17} />
|
<Clock size={17} />
|
||||||
<p className="text-xs">{timeAgo} ago</p>
|
<p className="text-xs">{timeAgo} ago</p>
|
||||||
@@ -54,10 +63,7 @@ const Navbar = ({ messages }: { messages: Message[] }) => {
|
|||||||
size={17}
|
size={17}
|
||||||
className="active:scale-95 transition duration-100 cursor-pointer"
|
className="active:scale-95 transition duration-100 cursor-pointer"
|
||||||
/>
|
/>
|
||||||
<Trash
|
<DeleteChat redirect chatId={chatId} chats={[]} setChats={() => {}} />
|
||||||
size={17}
|
|
||||||
className="text-red-400 active:scale-95 transition duration-100 cursor-pointer"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ type Image = {
|
|||||||
|
|
||||||
const SearchImages = ({
|
const SearchImages = ({
|
||||||
query,
|
query,
|
||||||
chat_history,
|
chatHistory,
|
||||||
}: {
|
}: {
|
||||||
query: string;
|
query: string;
|
||||||
chat_history: Message[];
|
chatHistory: Message[];
|
||||||
}) => {
|
}) => {
|
||||||
const [images, setImages] = useState<Image[] | null>(null);
|
const [images, setImages] = useState<Image[] | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -33,6 +33,9 @@ const SearchImages = ({
|
|||||||
const chatModelProvider = localStorage.getItem('chatModelProvider');
|
const chatModelProvider = localStorage.getItem('chatModelProvider');
|
||||||
const chatModel = localStorage.getItem('chatModel');
|
const chatModel = localStorage.getItem('chatModel');
|
||||||
|
|
||||||
|
const customOpenAIBaseURL = localStorage.getItem('openAIBaseURL');
|
||||||
|
const customOpenAIKey = localStorage.getItem('openAIApiKey');
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/images`,
|
`${process.env.NEXT_PUBLIC_API_URL}/images`,
|
||||||
{
|
{
|
||||||
@@ -42,9 +45,15 @@ const SearchImages = ({
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
query: query,
|
query: query,
|
||||||
chat_history: chat_history,
|
chatHistory: chatHistory,
|
||||||
chat_model_provider: chatModelProvider,
|
chatModel: {
|
||||||
chat_model: chatModel,
|
provider: chatModelProvider,
|
||||||
|
model: chatModel,
|
||||||
|
...(chatModelProvider === 'custom_openai' && {
|
||||||
|
customOpenAIBaseURL: customOpenAIBaseURL,
|
||||||
|
customOpenAIKey: customOpenAIKey,
|
||||||
|
}),
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ declare module 'yet-another-react-lightbox' {
|
|||||||
|
|
||||||
const Searchvideos = ({
|
const Searchvideos = ({
|
||||||
query,
|
query,
|
||||||
chat_history,
|
chatHistory,
|
||||||
}: {
|
}: {
|
||||||
query: string;
|
query: string;
|
||||||
chat_history: Message[];
|
chatHistory: Message[];
|
||||||
}) => {
|
}) => {
|
||||||
const [videos, setVideos] = useState<Video[] | null>(null);
|
const [videos, setVideos] = useState<Video[] | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -46,6 +46,9 @@ const Searchvideos = ({
|
|||||||
const chatModelProvider = localStorage.getItem('chatModelProvider');
|
const chatModelProvider = localStorage.getItem('chatModelProvider');
|
||||||
const chatModel = localStorage.getItem('chatModel');
|
const chatModel = localStorage.getItem('chatModel');
|
||||||
|
|
||||||
|
const customOpenAIBaseURL = localStorage.getItem('openAIBaseURL');
|
||||||
|
const customOpenAIKey = localStorage.getItem('openAIApiKey');
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/videos`,
|
`${process.env.NEXT_PUBLIC_API_URL}/videos`,
|
||||||
{
|
{
|
||||||
@@ -55,9 +58,15 @@ const Searchvideos = ({
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
query: query,
|
query: query,
|
||||||
chat_history: chat_history,
|
chatHistory: chatHistory,
|
||||||
chat_model_provider: chatModelProvider,
|
chatModel: {
|
||||||
chat_model: chatModel,
|
provider: chatModelProvider,
|
||||||
|
model: chatModel,
|
||||||
|
...(chatModelProvider === 'custom_openai' && {
|
||||||
|
customOpenAIBaseURL: customOpenAIBaseURL,
|
||||||
|
customOpenAIKey: customOpenAIKey,
|
||||||
|
}),
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,15 +4,24 @@ export const getSuggestions = async (chatHisory: Message[]) => {
|
|||||||
const chatModel = localStorage.getItem('chatModel');
|
const chatModel = localStorage.getItem('chatModel');
|
||||||
const chatModelProvider = localStorage.getItem('chatModelProvider');
|
const chatModelProvider = localStorage.getItem('chatModelProvider');
|
||||||
|
|
||||||
|
const customOpenAIKey = localStorage.getItem('openAIApiKey');
|
||||||
|
const customOpenAIBaseURL = localStorage.getItem('openAIBaseURL');
|
||||||
|
|
||||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/suggestions`, {
|
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/suggestions`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
chat_history: chatHisory,
|
chatHistory: chatHisory,
|
||||||
chat_model: chatModel,
|
chatModel: {
|
||||||
chat_model_provider: chatModelProvider,
|
provider: chatModelProvider,
|
||||||
|
model: chatModel,
|
||||||
|
...(chatModelProvider === 'custom_openai' && {
|
||||||
|
customOpenAIKey,
|
||||||
|
customOpenAIBaseURL,
|
||||||
|
}),
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "perplexica-frontend",
|
"name": "perplexica-frontend",
|
||||||
"version": "1.9.1",
|
"version": "1.9.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "ItzCrazyKns",
|
"author": "ItzCrazyKns",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
"clsx": "^2.1.0",
|
"clsx": "^2.1.0",
|
||||||
"langchain": "^0.1.30",
|
"langchain": "^0.1.30",
|
||||||
"lucide-react": "^0.363.0",
|
"lucide-react": "^0.363.0",
|
||||||
"markdown-to-jsx": "^7.4.5",
|
"markdown-to-jsx": "^7.6.2",
|
||||||
"next": "14.1.4",
|
"next": "14.1.4",
|
||||||
"next-themes": "^0.3.0",
|
"next-themes": "^0.3.0",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
|||||||
@@ -2210,10 +2210,10 @@ lucide-react@^0.363.0:
|
|||||||
resolved "https://registry.yarnpkg.com/lucide-react/-/lucide-react-0.363.0.tgz#2bb1f9d09b830dda86f5118fcd097f87247fe0e3"
|
resolved "https://registry.yarnpkg.com/lucide-react/-/lucide-react-0.363.0.tgz#2bb1f9d09b830dda86f5118fcd097f87247fe0e3"
|
||||||
integrity sha512-AlsfPCsXQyQx7wwsIgzcKOL9LwC498LIMAo+c0Es5PkHJa33xwmYAkkSoKoJWWWSYQEStqu58/jT4tL2gi32uQ==
|
integrity sha512-AlsfPCsXQyQx7wwsIgzcKOL9LwC498LIMAo+c0Es5PkHJa33xwmYAkkSoKoJWWWSYQEStqu58/jT4tL2gi32uQ==
|
||||||
|
|
||||||
markdown-to-jsx@^7.4.5:
|
markdown-to-jsx@^7.6.2:
|
||||||
version "7.4.6"
|
version "7.6.2"
|
||||||
resolved "https://registry.yarnpkg.com/markdown-to-jsx/-/markdown-to-jsx-7.4.6.tgz#1ea0018c549bf00c9ce35e8f4ea57e48028d9cf7"
|
resolved "https://registry.yarnpkg.com/markdown-to-jsx/-/markdown-to-jsx-7.6.2.tgz#254cbf7d412a37073486c0a2dd52266d2191a793"
|
||||||
integrity sha512-3cyNxI/PwotvYkjg6KmFaN1uyN/7NqETteD2DobBB8ro/FR9jsHIh4Fi7ywAz0s9QHRKCmGlOUggs5GxSWACKA==
|
integrity sha512-gEcyiJXzBxmId2Y/kydLbD6KRNccDiUy/Src1cFGn3s2X0LZZ/hUiEc2VisFyA5kUE3SXclTCczjQiAuqKZiFQ==
|
||||||
|
|
||||||
md5@^2.3.0:
|
md5@^2.3.0:
|
||||||
version "2.3.0"
|
version "2.3.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user