gen.nvim icon indicating copy to clipboard operation
gen.nvim copied to clipboard

Customize scheme and path

Open rdmcguire opened this issue 1 year ago • 2 comments

This is a great plugin! I have ollama running behind an Istio gateway in kubernetes, I'd like to be able to set the URI to something like https://myhost.mydomain/ai rather than having host and port parameters without support for TLS or serving the api out of a sub-path. I'm not awesome at lua, but I could scrap together a PR if desired.

rdmcguire avatar Aug 30 '24 20:08 rdmcguire

The plugin uses http in both the default command and list_models functions that are in the setup options. So I just set a custom command and list_models that is a copy of the default function with http changed to https to get TLS support. This works for me:

return {
  "David-Kunz/gen.nvim",
  opts = {
    command = function(options)
      local body = { model = options.model, stream = true }
      return "curl --silent --no-buffer -X POST https://" .. options.host .. ":" .. options.port .. "/api/chat -d $body"
    end,
    list_models = function(options)
        local response = vim.fn.systemlist(
                             "curl --silent --no-buffer https://" .. options.host ..
                                 ":" .. options.port .. "/api/tags")
        local list = vim.fn.json_decode(response)
        local models = {}
        for key, _ in pairs(list.models) do
            table.insert(models, list.models[key].name)
        end
        table.sort(models)
        return models
    end,
    -- ... other options
  }
}

In your case, you'd probably want to also set /api/chat to /ai/api/chat and /api/tags to /ai/api/tags or whatever works.

FlippingBinary avatar Sep 07 '24 23:09 FlippingBinary

Thank you @FlippingBinary and @rdmcguire , I hope the suggestion helps in your case!

David-Kunz avatar Oct 03 '24 09:10 David-Kunz