fjrdomingues / autopilot

Code Autopilot, a tool that uses GPT to read a codebase, create context and solve tasks.
591 stars 62 forks source link

Add support for gpt-4-turbo #193

Open TSCarterJr opened 4 months ago

TSCarterJr commented 4 months ago

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.

codeautopilot[bot] commented 4 months ago

Potential solution

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.

How to implement

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:

Changes on modules/model.js To add support for "gpt-4-turbo" in the `modules/model.js` file, you will need to update the `getModel` function to include "gpt-4-turbo" in the array of supported models and ensure that an instance of the OpenAI class is created with the correct model name when "gpt-4-turbo" is specified. Here's how you can do it: ### Updated `getModel` function in `modules/model.js` ```javascript const { OpenAI } = require('langchain/llms'); /** * * Returns an instance of the specified language model. * @param {string} modelType - The type of language model to return. * Currently Supported ['gpt-3.5-turbo', 'gpt-4', 'gpt-4-turbo']. * @returns {Object} - An instance of the specified language model. * @throws {Error} if the input model type is not supported */ 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 } ``` By adding 'gpt-4-turbo' to the array of supported models, the `getModel` function will now be able to handle requests for this new model type. Make sure to test the updated function to ensure that it correctly instantiates the OpenAI class with "gpt-4-turbo" and that the rest of your application can interact with the new model as expected.