feat(chatModels): load model from localstorage
This commit is contained in:
parent
ed9ff3c20f
commit
f618b713af
16 changed files with 126 additions and 81 deletions
|
|
@ -1,15 +1,23 @@
|
|||
import { WebSocket } from 'ws';
|
||||
import { handleMessage } from './messageHandler';
|
||||
import { getChatModel, getChatModelProvider } from '../config';
|
||||
import { getAvailableProviders } from '../lib/providers';
|
||||
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
||||
import type { Embeddings } from '@langchain/core/embeddings';
|
||||
import type { IncomingMessage } from 'http';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
export const handleConnection = async (ws: WebSocket) => {
|
||||
export const handleConnection = async (
|
||||
ws: WebSocket,
|
||||
request: IncomingMessage,
|
||||
) => {
|
||||
const searchParams = new URL(request.url, `http://${request.headers.host}`)
|
||||
.searchParams;
|
||||
|
||||
const models = await getAvailableProviders();
|
||||
const provider = getChatModelProvider();
|
||||
const chatModel = getChatModel();
|
||||
const provider =
|
||||
searchParams.get('chatModelProvider') || Object.keys(models)[0];
|
||||
const chatModel =
|
||||
searchParams.get('chatModel') || Object.keys(models[provider])[0];
|
||||
|
||||
let llm: BaseChatModel | undefined;
|
||||
let embeddings: Embeddings | undefined;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ export const initServer = (
|
|||
const port = getPort();
|
||||
const wss = new WebSocketServer({ server });
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
handleConnection(ws);
|
||||
});
|
||||
wss.on('connection', handleConnection);
|
||||
|
||||
logger.info(`WebSocket server started on port ${port}`);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue