LibreChat/api/app/clients/llm/createLLM.js
Danny Avila 0886441461
feat(azureOpenAI): Allow Switching Deployment Name by Model Name (#1137)
* feat(azureOpenAI): allow switching deployment name by model name

* ci: add unit tests and throw error on no api key provided to avoid API call

* fix(gptPlugins/initializeClient): check if azure is enabled; ci: add unit tests for gptPlugins/initializeClient

* fix(ci): fix expected error message for partial regex match:  unexpected token
2023-11-04 15:03:31 -04:00

42 lines
865 B
JavaScript

const { ChatOpenAI } = require('langchain/chat_models/openai');
const { sanitizeModelName } = require('../../../utils');
function createLLM({
modelOptions,
configOptions,
callbacks,
streaming = false,
openAIApiKey,
azure = {},
}) {
let credentials = { openAIApiKey };
let configuration = {
apiKey: openAIApiKey,
};
let azureOptions = {};
if (azure) {
credentials = {};
configuration = {};
azureOptions = azure;
azureOptions.azureOpenAIApiDeploymentName = sanitizeModelName(modelOptions.modelName);
}
// console.debug('createLLM: configOptions');
// console.debug(configOptions);
return new ChatOpenAI(
{
streaming,
verbose: true,
credentials,
configuration,
...azureOptions,
...modelOptions,
callbacks,
},
configOptions,
);
}
module.exports = createLLM;