huynle / ogpt.nvim

Chat with Ollama/Huggingface/TextGen/OpenAI/Gemini/Anthropic GPT Neovim Plugin: Effortless Natural Language Generation with LLM API
Apache License 2.0
166 stars 14 forks source link

I can't use OGPTRun command with Gemini #21

Closed Lautron closed 7 months ago

Lautron commented 7 months ago

My setup

I'm using packer.nvim

Configuration

packer.lua

-- ...
    use {
        'huynle/ogpt.nvim',
        requires = {
            'MunifTanjim/nui.nvim',
            'nvim-lua/plenary.nvim',
            'nvim-telescope/telescope.nvim',
        },
    }
-- ...

nvim/after/plugin/ogpt.lua

require('ogpt').setup({
    default_provider = "gemini",
    actions = {
        grammar_correction = {
            strategy = "replace",
            template = "Correct the given text to standard {{lang}}:\n\n```{{input}}```",
            system =
            "You are a helpful note writing assistant, given a text input, correct the text only for grammar and spelling error. You are to keep all formatting the same, e.g. markdown bullets, should stay as a markdown bullet in the result, and indents should stay the same. Return ONLY the corrected text.",
            params = {
                temperature = 0.3,
            },
            args = {
                lang = {
                    type = "string",
                    optional = "true",
                    default = "english",
                },
            },
        },
    }
})

The main issue

The command I'm using

:OGPTRun grammar_correction

The error I get

Error executing Lua callback: ...k/packer/start/ogpt.nvim/lua/ogpt/flows/actions/init.lua:79: attempt to call local 'class' (a nil value)
stack traceback:
        ...k/packer/start/ogpt.nvim/lua/ogpt/flows/actions/init.lua:79: in function 'run_action'
        ...vim/site/pack/packer/start/ogpt.nvim/lua/ogpt/module.lua:87: in function 'run_action'
        ...share/nvim/site/pack/packer/start/ogpt.nvim/lua/ogpt.lua:113: in function 'run_action'
        ...re/nvim/site/pack/packer/start/ogpt.nvim/plugin/ogpt.lua:16: in function <...re/nvim/site/pack/packer/start/ogpt.nvim/plugin/ogpt.lua:15>
Lautron commented 7 months ago

Fixed this error by adding type = "popup" to grammar_correction table.

But now I'm getting this error:

Error detected while processing command line:
Error executing Lua callback: ...nvim/site/pack/packer/start/ogpt.nvim/lua/ogpt/utils.lua:292: attempt to call method 'gsub' (a nil value)
stack traceback:
        ...nvim/site/pack/packer/start/ogpt.nvim/lua/ogpt/utils.lua:292: in function 'escape_pattern'
        ...k/packer/start/ogpt.nvim/lua/ogpt/flows/actions/base.lua:162: in function 'render_template'
        ...k/packer/start/ogpt.nvim/lua/ogpt/flows/actions/base.lua:180: in function 'get_params'
        ...er/start/ogpt.nvim/lua/ogpt/flows/actions/popup/init.lua:53: in function 'run'
        ...k/packer/start/ogpt.nvim/lua/ogpt/flows/actions/init.lua:82: in function 'run_action'
        ...vim/site/pack/packer/start/ogpt.nvim/lua/ogpt/module.lua:87: in function 'run_action'
        ...share/nvim/site/pack/packer/start/ogpt.nvim/lua/ogpt.lua:113: in function 'run_action'
        ...re/nvim/site/pack/packer/start/ogpt.nvim/plugin/ogpt.lua:16: in function <...re/nvim/site/pack/packer/start/ogpt.nvim/plugin/ogpt.lua:15>
Lautron commented 7 months ago

It seems to work if I use the following configs:

Using "edit"

require('ogpt').setup({
    default_provider = "gemini",
    actions = {
        grammar_correction = {
            type = "edit",
            template = "Correct this to standard:\n\n{{input}}",
        },
    }
})

Using "display"

require('ogpt').setup({
    default_provider = "gemini",
    actions = {
        grammar_correction = {
            type = "popup",
            strategy = "display",
            template = "Correct this to standard:\n\n{{input}}",
        },
    }
})
huynle commented 7 months ago

There's definitely a lot more documentation that can be added, I'm going to add some wiki articles to help with some of these configurations! Glad to see you got it figured out