jackMort / ChatGPT.nvim

ChatGPT Neovim Plugin: Effortless Natural Language Generation with OpenAI's ChatGPT API
Apache License 2.0
3.56k stars 307 forks source link

Change models on the fly #414

Open barnii77 opened 3 months ago

barnii77 commented 3 months ago

I want to change models on the fly using commands so I can default to gpt-3.5 and if it is too stupid switch to gpt-4. The way I am attempting to do this is the following:

function SetModelGPT4()
  require("chatgpt").setup({
    openai_params = {
      model = "gpt-4-1106-preview",
      frequency_penalty = 0,
      presence_penalty = 0,
      max_tokens = 4095,
      temperature = 0.2,
      top_p = 0.1,
      n = 1,
    }
  })
end

However, the setup call (this is a repeated setup, setup has already been called when the plugin was loaded) does not seem to have any effect after the first call to setup. When the first thing I do is run the change model command, then the model is successfully switched to the correct model, but if the plugin is first loaded (eg I open chat window and close it again), this doesn't work. I tried to dig into the source code, but couldn't find out what values I have to modify to make the model change. Any help is appreciated.

Potential Solution: make openai_params.model be either a string or a function Example:

local ChatGPTModelState = { model = "gpt-3.5-turbo" }
local config = { model = function() ChatGPTModelState.model end, ... }
function SetModelGPT4()
  ChatGPTModelState.model = "gpt-4-turbo-preview"
end