mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
32 lines
729 B
JavaScript
32 lines
729 B
JavaScript
|
|
const { ChatOpenAI } = require('langchain/chat_models/openai');
|
||
|
|
const { CallbackManager } = require('langchain/callbacks');
|
||
|
|
|
||
|
|
function createLLM({ modelOptions, configOptions, handlers, openAIApiKey, azure = {} }) {
|
||
|
|
let credentials = { openAIApiKey };
|
||
|
|
let configuration = {
|
||
|
|
apiKey: openAIApiKey,
|
||
|
|
};
|
||
|
|
|
||
|
|
if (azure) {
|
||
|
|
credentials = {};
|
||
|
|
configuration = {};
|
||
|
|
}
|
||
|
|
|
||
|
|
// console.debug('createLLM: configOptions');
|
||
|
|
// console.debug(configOptions);
|
||
|
|
|
||
|
|
return new ChatOpenAI(
|
||
|
|
{
|
||
|
|
streaming: true,
|
||
|
|
credentials,
|
||
|
|
configuration,
|
||
|
|
...azure,
|
||
|
|
...modelOptions,
|
||
|
|
callbackManager: handlers && CallbackManager.fromHandlers(handlers),
|
||
|
|
},
|
||
|
|
configOptions,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = createLLM;
|