mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-06-25 11:18:43 +00:00
LM Studio Integration: - Added LM Studio provider with OpenAI-compatible API support - Dynamic model discovery via /v1/models endpoint - Support for both chat and embeddings models - Docker-compatible networking configuration Thinking Model Panel: - Added collapsible UI panel for model's chain of thought - Parses responses with <think> tags to separate reasoning - Maintains backward compatibility with regular responses - Styled consistently with app theme for light/dark modes - Preserves all existing message functionality (sources, markdown, etc.) These improvements enhance the app's compatibility with local LLMs and provide better visibility into model reasoning processes while maintaining existing functionality.
89 lines
2.3 KiB
TypeScript
89 lines
2.3 KiB
TypeScript
import express from 'express';
|
|
import {
|
|
getAvailableChatModelProviders,
|
|
getAvailableEmbeddingModelProviders,
|
|
} from '../lib/providers';
|
|
import {
|
|
getGroqApiKey,
|
|
getOllamaApiEndpoint,
|
|
getLMStudioApiEndpoint,
|
|
getAnthropicApiKey,
|
|
getGeminiApiKey,
|
|
getOpenaiApiKey,
|
|
updateConfig,
|
|
} from '../config';
|
|
import logger from '../utils/logger';
|
|
|
|
const router = express.Router();
|
|
|
|
router.get('/', async (_, res) => {
|
|
try {
|
|
const config = {};
|
|
|
|
const [chatModelProviders, embeddingModelProviders] = await Promise.all([
|
|
getAvailableChatModelProviders(),
|
|
getAvailableEmbeddingModelProviders(),
|
|
]);
|
|
|
|
config['chatModelProviders'] = {};
|
|
config['embeddingModelProviders'] = {};
|
|
|
|
for (const provider in chatModelProviders) {
|
|
config['chatModelProviders'][provider] = Object.keys(
|
|
chatModelProviders[provider],
|
|
).map((model) => {
|
|
return {
|
|
name: model,
|
|
displayName: chatModelProviders[provider][model].displayName,
|
|
};
|
|
});
|
|
}
|
|
|
|
for (const provider in embeddingModelProviders) {
|
|
config['embeddingModelProviders'][provider] = Object.keys(
|
|
embeddingModelProviders[provider],
|
|
).map((model) => {
|
|
return {
|
|
name: model,
|
|
displayName: embeddingModelProviders[provider][model].displayName,
|
|
};
|
|
});
|
|
}
|
|
|
|
config['openaiApiKey'] = getOpenaiApiKey();
|
|
config['ollamaApiUrl'] = getOllamaApiEndpoint();
|
|
config['lmStudioApiUrl'] = getLMStudioApiEndpoint();
|
|
config['anthropicApiKey'] = getAnthropicApiKey();
|
|
config['groqApiKey'] = getGroqApiKey();
|
|
config['geminiApiKey'] = getGeminiApiKey();
|
|
|
|
res.status(200).json(config);
|
|
} catch (err: any) {
|
|
res.status(500).json({ message: 'An error has occurred.' });
|
|
logger.error(`Error getting config: ${err.message}`);
|
|
}
|
|
});
|
|
|
|
router.post('/', async (req, res) => {
|
|
const config = req.body;
|
|
|
|
const updatedConfig = {
|
|
API_KEYS: {
|
|
OPENAI: config.openaiApiKey,
|
|
GROQ: config.groqApiKey,
|
|
ANTHROPIC: config.anthropicApiKey,
|
|
GEMINI: config.geminiApiKey,
|
|
},
|
|
API_ENDPOINTS: {
|
|
OLLAMA: config.ollamaApiUrl,
|
|
LMSTUDIO: config.lmStudioApiUrl,
|
|
},
|
|
};
|
|
|
|
updateConfig(updatedConfig);
|
|
|
|
res.status(200).json({ message: 'Config updated' });
|
|
});
|
|
|
|
export default router;
|