mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-06-17 23:38:30 +00:00
make it possible to configure multiple engines
This commit is contained in:
@ -2,7 +2,12 @@
|
|||||||
PORT = 3001 # Port to run the server on
|
PORT = 3001 # Port to run the server on
|
||||||
SIMILARITY_MEASURE = "cosine" # "cosine" or "dot"
|
SIMILARITY_MEASURE = "cosine" # "cosine" or "dot"
|
||||||
KEEP_ALIVE = "5m" # How long to keep Ollama models loaded into memory. (Instead of using -1 use "-1m")
|
KEEP_ALIVE = "5m" # How long to keep Ollama models loaded into memory. (Instead of using -1 use "-1m")
|
||||||
SEARCH_ENGINE_BACKEND = "searxng" # "google" | "searxng" | "bing" | "brave" | "yacy"
|
|
||||||
|
[SEARCH_ENGINE_BACKENDS] # "google" | "searxng" | "bing" | "brave" | "yacy"
|
||||||
|
SEARCH = "searxng"
|
||||||
|
IMAGE = "searxng"
|
||||||
|
VIDEO = "searxng"
|
||||||
|
NEWS = "searxng"
|
||||||
|
|
||||||
[KEYCLOAK]
|
[KEYCLOAK]
|
||||||
URL = ""
|
URL = ""
|
||||||
|
@ -12,7 +12,7 @@ import { searchGooglePSE } from '../lib/searchEngines/google_pse';
|
|||||||
import { searchBraveAPI } from '../lib/searchEngines/brave';
|
import { searchBraveAPI } from '../lib/searchEngines/brave';
|
||||||
import { searchYaCy } from '../lib/searchEngines/yacy';
|
import { searchYaCy } from '../lib/searchEngines/yacy';
|
||||||
import { searchBingAPI } from '../lib/searchEngines/bing';
|
import { searchBingAPI } from '../lib/searchEngines/bing';
|
||||||
import { getSearchEngineBackend } from '../config';
|
import { getImageSearchEngineBackend } from '../config';
|
||||||
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
||||||
|
|
||||||
const imageSearchChainPrompt = `
|
const imageSearchChainPrompt = `
|
||||||
@ -42,7 +42,7 @@ type ImageSearchChainInput = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function performImageSearch(query: string) {
|
async function performImageSearch(query: string) {
|
||||||
const searchEngine = getSearchEngineBackend();
|
const searchEngine = getImageSearchEngineBackend();
|
||||||
let images = [];
|
let images = [];
|
||||||
|
|
||||||
switch (searchEngine) {
|
switch (searchEngine) {
|
||||||
|
@ -11,7 +11,7 @@ import { searchSearxng } from '../lib/searchEngines/searxng';
|
|||||||
import { searchGooglePSE } from '../lib/searchEngines/google_pse';
|
import { searchGooglePSE } from '../lib/searchEngines/google_pse';
|
||||||
import { searchBraveAPI } from '../lib/searchEngines/brave';
|
import { searchBraveAPI } from '../lib/searchEngines/brave';
|
||||||
import { searchBingAPI } from '../lib/searchEngines/bing';
|
import { searchBingAPI } from '../lib/searchEngines/bing';
|
||||||
import { getSearchEngineBackend } from '../config';
|
import { getVideoSearchEngineBackend } from '../config';
|
||||||
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
||||||
|
|
||||||
const VideoSearchChainPrompt = `
|
const VideoSearchChainPrompt = `
|
||||||
@ -43,7 +43,7 @@ type VideoSearchChainInput = {
|
|||||||
const strParser = new StringOutputParser();
|
const strParser = new StringOutputParser();
|
||||||
|
|
||||||
async function performVideoSearch(query: string) {
|
async function performVideoSearch(query: string) {
|
||||||
const searchEngine = getSearchEngineBackend();
|
const searchEngine = getVideoSearchEngineBackend();
|
||||||
const youtubeQuery = `${query} site:youtube.com`;
|
const youtubeQuery = `${query} site:youtube.com`;
|
||||||
let videos = [];
|
let videos = [];
|
||||||
|
|
||||||
|
@ -9,8 +9,13 @@ interface Config {
|
|||||||
PORT: number;
|
PORT: number;
|
||||||
SIMILARITY_MEASURE: string;
|
SIMILARITY_MEASURE: string;
|
||||||
KEEP_ALIVE: string;
|
KEEP_ALIVE: string;
|
||||||
SEARCH_ENGINE_BACKEND: string;
|
|
||||||
};
|
};
|
||||||
|
SEARCH_ENGINE_BACKENDS: {
|
||||||
|
SEARCH: string;
|
||||||
|
IMAGE: string;
|
||||||
|
VIDEO: string;
|
||||||
|
NEWS: string;
|
||||||
|
}
|
||||||
KEYCLOAK: {
|
KEYCLOAK: {
|
||||||
URL: string;
|
URL: string;
|
||||||
REALM: string;
|
REALM: string;
|
||||||
@ -83,7 +88,16 @@ export const getAnthropicApiKey = () => loadConfig().MODELS.ANTHROPIC.API_KEY;
|
|||||||
export const getGeminiApiKey = () => loadConfig().MODELS.GEMINI.API_KEY;
|
export const getGeminiApiKey = () => loadConfig().MODELS.GEMINI.API_KEY;
|
||||||
|
|
||||||
export const getSearchEngineBackend = () =>
|
export const getSearchEngineBackend = () =>
|
||||||
loadConfig().GENERAL.SEARCH_ENGINE_BACKEND;
|
loadConfig().SEARCH_ENGINE_BACKENDS.SEARCH;
|
||||||
|
|
||||||
|
export const getImageSearchEngineBackend = () =>
|
||||||
|
loadConfig().SEARCH_ENGINE_BACKENDS.IMAGE || getSearchEngineBackend();
|
||||||
|
|
||||||
|
export const getVideoSearchEngineBackend = () =>
|
||||||
|
loadConfig().SEARCH_ENGINE_BACKENDS.VIDEO || getSearchEngineBackend();
|
||||||
|
|
||||||
|
export const getNewsSearchEngineBackend = () =>
|
||||||
|
loadConfig().SEARCH_ENGINE_BACKENDS.NEWS || getSearchEngineBackend();
|
||||||
|
|
||||||
export const getGoogleApiKey = () => loadConfig().SEARCH_ENGINES.GOOGLE.API_KEY;
|
export const getGoogleApiKey = () => loadConfig().SEARCH_ENGINES.GOOGLE.API_KEY;
|
||||||
|
|
||||||
|
@ -4,13 +4,13 @@ import { searchGooglePSE } from '../lib/searchEngines/google_pse';
|
|||||||
import { searchBraveAPI } from '../lib/searchEngines/brave';
|
import { searchBraveAPI } from '../lib/searchEngines/brave';
|
||||||
import { searchYaCy } from '../lib/searchEngines/yacy';
|
import { searchYaCy } from '../lib/searchEngines/yacy';
|
||||||
import { searchBingAPI } from '../lib/searchEngines/bing';
|
import { searchBingAPI } from '../lib/searchEngines/bing';
|
||||||
import { getSearchEngineBackend } from '../config';
|
import { getNewsSearchEngineBackend } from '../config';
|
||||||
import logger from '../utils/logger';
|
import logger from '../utils/logger';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
async function performSearch(query: string, site: string) {
|
async function performSearch(query: string, site: string) {
|
||||||
const searchEngine = getSearchEngineBackend();
|
const searchEngine = getNewsSearchEngineBackend();
|
||||||
switch (searchEngine) {
|
switch (searchEngine) {
|
||||||
case 'google': {
|
case 'google': {
|
||||||
const googleResult = await searchGooglePSE(query);
|
const googleResult = await searchGooglePSE(query);
|
||||||
|
Reference in New Issue
Block a user