Open TSCarterJr opened 4 months ago
The task requires adding support for a new model type, "gpt-4-turbo", to the existing getModel
function. The solution involves updating the array of supported models to include "gpt-4-turbo" and ensuring that the function can instantiate the OpenAI class with the new model type. The reasoning behind this solution is to extend the functionality of the getModel
function to handle the new model type without altering the existing structure and logic of the code.
To implement the solution, you need to modify the getModel
function in the modules/model.js
file. Specifically, you will update the array that checks for supported model types to include "gpt-4-turbo". Here's the updated code snippet:
const { OpenAI } = require('langchain/llms');
function getModel(modelType){
let model
if (['gpt-3.5-turbo', 'gpt-4', 'gpt-4-turbo'].includes(modelType)) {
model = new OpenAI({
modelName: modelType,
maxTokens: parseInt(process.env.OPENAI_MAX_TOKEN_REPLY),
temperature: parseFloat(process.env.MODEL_TEMPERATURE),
presencePenalty: parseFloat(process.env.MODEL_PRESENCE_PENALTY),
frequencyPenalty: parseFloat(process.env.MODEL_FREQUENCY_PENALTY),
user: process.env.MODEL_USER,
openAIApiKey: process.env.OPENAI_API_KEY,
})
} else {
throw new Error(`Model type: ${modelType} not supported.`)
}
return model
}
module.exports = { getModel }
This updated function now includes "gpt-4-turbo" in the list of supported models and will create an instance of the OpenAI class with the correct model name when "gpt-4-turbo" is specified. No other changes are needed for this specific task. After updating the code, ensure to test the function with the new model type to verify that it works as expected.
Click here to create a Pull Request with the proposed solution
Files used for this task:
Background story explaining the current situation: https://github.com/fjrdomingues/autopilot/blob/main/modules/model.js
Please add support for "gpt-4-turbo", as it costs less, and performs better. Desired new situation: Added support for "gpt-4-turbo" Implementation details:
I am assuming, adding "gpt-4-turbo" to the if statement.