feat(routes): add config route
This commit is contained in:
parent
a86378e726
commit
3ffbddd237
|
@ -0,0 +1,58 @@
|
|||
import express from 'express';
|
||||
import { getAvailableProviders } from '../lib/providers';
|
||||
import {
|
||||
getChatModel,
|
||||
getChatModelProvider,
|
||||
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['selectedProvider'] = getChatModelProvider();
|
||||
config['selectedChatModel'] = getChatModel();
|
||||
|
||||
config['openeaiApiKey'] = getOpenaiApiKey();
|
||||
config['ollamaApiUrl'] = getOllamaApiEndpoint();
|
||||
|
||||
res.status(200).json(config);
|
||||
});
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const config = req.body;
|
||||
|
||||
const updatedConfig = {
|
||||
GENERAL: {
|
||||
CHAT_MODEL_PROVIDER: config.selectedProvider,
|
||||
CHAT_MODEL: config.selectedChatModel,
|
||||
},
|
||||
API_KEYS: {
|
||||
OPENAI: config.openeaiApiKey,
|
||||
},
|
||||
API_ENDPOINTS: {
|
||||
OLLAMA: config.ollamaApiUrl,
|
||||
},
|
||||
};
|
||||
|
||||
updateConfig(updatedConfig);
|
||||
|
||||
res.status(200).json({ message: 'Config updated' });
|
||||
});
|
||||
|
||||
export default router;
|
|
@ -1,8 +1,10 @@
|
|||
import express from 'express';
|
||||
import imagesRouter from './images';
|
||||
import configRouter from './config';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.use('/images', imagesRouter);
|
||||
router.use('/config', configRouter);
|
||||
|
||||
export default router;
|
||||
|
|
Loading…
Reference in New Issue