Perplexica/src/routes/config.ts

53 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-04-23 16:46:14 +05:30
import express from 'express';
import { getAvailableProviders } from '../lib/providers';
import {
2024-05-01 19:43:06 +05:30
getGroqApiKey,
2024-04-23 16:46:14 +05:30
getOllamaApiEndpoint,
getOpenaiApiKey,
updateConfig,
} from '../config';
const router = express.Router();
router.get('/', async (_, res) => {
const config = {};
const providers = await getAvailableProviders();
for (const provider in providers) {
delete providers[provider]['embeddings'];
}
config['providers'] = {};
for (const provider in providers) {
config['providers'][provider] = Object.keys(providers[provider]);
}
config['openeaiApiKey'] = getOpenaiApiKey();
config['ollamaApiUrl'] = getOllamaApiEndpoint();
2024-05-01 19:43:06 +05:30
config['groqApiKey'] = getGroqApiKey();
2024-04-23 16:46:14 +05:30
res.status(200).json(config);
});
router.post('/', async (req, res) => {
const config = req.body;
const updatedConfig = {
API_KEYS: {
OPENAI: config.openeaiApiKey,
2024-05-01 19:43:06 +05:30
GROQ: config.groqApiKey,
2024-04-23 16:46:14 +05:30
},
API_ENDPOINTS: {
OLLAMA: config.ollamaApiUrl,
},
};
updateConfig(updatedConfig);
res.status(200).json({ message: 'Config updated' });
});
export default router;