mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-12-02 01:38:14 +00:00
feat: update backend services and routes
- Add business routes and middleware\n- Update search and database services\n- Improve health check implementation\n- Update CI workflow configuration
This commit is contained in:
@@ -1,89 +1,40 @@
|
||||
import { config } from 'dotenv';
|
||||
import { z } from 'zod';
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
config();
|
||||
// Load environment variables
|
||||
dotenv.config();
|
||||
|
||||
// Define the environment schema
|
||||
const envSchema = z.object({
|
||||
PORT: z.string().default('3000'),
|
||||
NODE_ENV: z.string().default('development'),
|
||||
SUPABASE_URL: z.string(),
|
||||
SUPABASE_KEY: z.string(),
|
||||
OLLAMA_URL: z.string().default('http://localhost:11434'),
|
||||
OLLAMA_MODEL: z.string().default('llama2'),
|
||||
SEARXNG_URL: z.string().default('http://localhost:4000'),
|
||||
SEARXNG_INSTANCES: z.string().default('["http://localhost:4000"]'),
|
||||
MAX_RESULTS_PER_QUERY: z.string().default('50'),
|
||||
CACHE_DURATION_HOURS: z.string().default('24'),
|
||||
CACHE_DURATION_DAYS: z.string().default('7'),
|
||||
HUGGING_FACE_API_KEY: z.string({
|
||||
required_error: "HUGGING_FACE_API_KEY is required in .env"
|
||||
})
|
||||
});
|
||||
// Environment configuration
|
||||
const env = {
|
||||
// Supabase Configuration
|
||||
SUPABASE_URL: process.env.SUPABASE_URL || '',
|
||||
SUPABASE_KEY: process.env.SUPABASE_KEY || '',
|
||||
|
||||
// Define the final environment type
|
||||
export interface EnvConfig {
|
||||
PORT: string;
|
||||
NODE_ENV: string;
|
||||
searxng: {
|
||||
currentUrl: string;
|
||||
instances: string[];
|
||||
};
|
||||
ollama: {
|
||||
url: string;
|
||||
model: string;
|
||||
};
|
||||
supabase: {
|
||||
url: string;
|
||||
anonKey: string;
|
||||
};
|
||||
cache: {
|
||||
maxResultsPerQuery: number;
|
||||
durationHours: number;
|
||||
durationDays: number;
|
||||
};
|
||||
ai: {
|
||||
model: string;
|
||||
temperature: number;
|
||||
maxTokens: number;
|
||||
batchSize: number;
|
||||
};
|
||||
huggingface: {
|
||||
apiKey: string;
|
||||
};
|
||||
// Server Configuration
|
||||
PORT: parseInt(process.env.PORT || '3001', 10),
|
||||
NODE_ENV: process.env.NODE_ENV || 'development',
|
||||
|
||||
// Search Configuration
|
||||
MAX_RESULTS_PER_QUERY: parseInt(process.env.MAX_RESULTS_PER_QUERY || '50', 10),
|
||||
CACHE_DURATION_HOURS: parseInt(process.env.CACHE_DURATION_HOURS || '24', 10),
|
||||
CACHE_DURATION_DAYS: parseInt(process.env.CACHE_DURATION_DAYS || '7', 10),
|
||||
|
||||
// SearxNG Configuration
|
||||
SEARXNG_URL: process.env.SEARXNG_URL || 'http://localhost:4000',
|
||||
|
||||
// Ollama Configuration
|
||||
OLLAMA_URL: process.env.OLLAMA_URL || 'http://localhost:11434',
|
||||
OLLAMA_MODEL: process.env.OLLAMA_MODEL || 'deepseek-coder:6.7b',
|
||||
|
||||
// Hugging Face Configuration
|
||||
HUGGING_FACE_API_KEY: process.env.HUGGING_FACE_API_KEY || ''
|
||||
};
|
||||
|
||||
// Validate required environment variables
|
||||
const requiredEnvVars = ['SUPABASE_URL', 'SUPABASE_KEY', 'SEARXNG_URL'];
|
||||
for (const envVar of requiredEnvVars) {
|
||||
if (!env[envVar as keyof typeof env]) {
|
||||
throw new Error(`Missing required environment variable: ${envVar}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Parse and transform the environment variables
|
||||
const rawEnv = envSchema.parse(process.env);
|
||||
|
||||
// Create the final environment object with parsed configurations
|
||||
export const env: EnvConfig = {
|
||||
PORT: rawEnv.PORT,
|
||||
NODE_ENV: rawEnv.NODE_ENV,
|
||||
searxng: {
|
||||
currentUrl: rawEnv.SEARXNG_URL,
|
||||
instances: JSON.parse(rawEnv.SEARXNG_INSTANCES)
|
||||
},
|
||||
ollama: {
|
||||
url: rawEnv.OLLAMA_URL,
|
||||
model: rawEnv.OLLAMA_MODEL
|
||||
},
|
||||
supabase: {
|
||||
url: rawEnv.SUPABASE_URL,
|
||||
anonKey: rawEnv.SUPABASE_KEY
|
||||
},
|
||||
cache: {
|
||||
maxResultsPerQuery: parseInt(rawEnv.MAX_RESULTS_PER_QUERY),
|
||||
durationHours: parseInt(rawEnv.CACHE_DURATION_HOURS),
|
||||
durationDays: parseInt(rawEnv.CACHE_DURATION_DAYS)
|
||||
},
|
||||
ai: {
|
||||
model: 'deepseek-ai/deepseek-coder-6.7b-instruct',
|
||||
temperature: 0.7,
|
||||
maxTokens: 512,
|
||||
batchSize: 3
|
||||
},
|
||||
huggingface: {
|
||||
apiKey: rawEnv.HUGGING_FACE_API_KEY
|
||||
}
|
||||
};
|
||||
export { env };
|
||||
Reference in New Issue
Block a user