Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gpt-4-turbo #193

Open
TSCarterJr opened this issue Apr 23, 2024 · 1 comment · May be fixed by #194
Open

Add support for gpt-4-turbo #193

TSCarterJr opened this issue Apr 23, 2024 · 1 comment · May be fixed by #194
Labels
enhancement New feature or request

Comments

@TSCarterJr
Copy link

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.

@TSCarterJr TSCarterJr added the enhancement New feature or request label Apr 23, 2024
Copy link

codeautopilot bot commented Apr 23, 2024

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

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.

Disclaimer: This comment was entirely generated using AI. Be aware that the information provided may be incorrect.

Current plan usage: 8.23%

Have feedback or need help?
Discord
Documentation
support@codeautopilot.com

@codeautopilot codeautopilot bot linked a pull request Apr 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant