mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-06-22 17:58:31 +00:00
feat(handlers): use new custom openai
This commit is contained in:
@ -9,6 +9,11 @@ import type { Embeddings } from '@langchain/core/embeddings';
|
||||
import type { IncomingMessage } from 'http';
|
||||
import logger from '../utils/logger';
|
||||
import { ChatOpenAI } from '@langchain/openai';
|
||||
import {
|
||||
getCustomOpenaiApiKey,
|
||||
getCustomOpenaiApiUrl,
|
||||
getCustomOpenaiModelName,
|
||||
} from '../config';
|
||||
|
||||
export const handleConnection = async (
|
||||
ws: WebSocket,
|
||||
@ -48,14 +53,20 @@ export const handleConnection = async (
|
||||
llm = chatModelProviders[chatModelProvider][chatModel]
|
||||
.model as unknown as BaseChatModel | undefined;
|
||||
} else if (chatModelProvider == 'custom_openai') {
|
||||
llm = new ChatOpenAI({
|
||||
modelName: chatModel,
|
||||
openAIApiKey: searchParams.get('openAIApiKey'),
|
||||
temperature: 0.7,
|
||||
configuration: {
|
||||
baseURL: searchParams.get('openAIBaseURL'),
|
||||
},
|
||||
}) as unknown as BaseChatModel;
|
||||
const customOpenaiApiKey = getCustomOpenaiApiKey();
|
||||
const customOpenaiApiUrl = getCustomOpenaiApiUrl();
|
||||
const customOpenaiModelName = getCustomOpenaiModelName();
|
||||
|
||||
if (customOpenaiApiKey && customOpenaiApiUrl && customOpenaiModelName) {
|
||||
llm = new ChatOpenAI({
|
||||
modelName: customOpenaiModelName,
|
||||
openAIApiKey: customOpenaiApiKey,
|
||||
temperature: 0.7,
|
||||
configuration: {
|
||||
baseURL: customOpenaiApiUrl,
|
||||
},
|
||||
}) as unknown as BaseChatModel;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
|
Reference in New Issue
Block a user