Skip to content

mikeslattery/genie.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1. INTRODUCTION

Genie is a Neovim plugin that allows users to generate Lua code based on natural language instructions, using the power of GPT-based AI models. With Genie, you can perform actions within Neovim by simply providing natural language descriptions of what you wish to accomplish.

2. INSTALLATION

To install Genie, you can use either the vim-plug or lazy.nvim package manager.

Using vim-plug, add the following to your init.vim or init.lua:

Plug 'mikeslattery/genie'

And then run :PlugInstall in Neovim.

For lazy.nvim, include Genie in your configuration like this:

{
  "mikeslattery/genie",
}

Refer to the lazy.nvim documentation for more details on using this package manager.

3. USAGE

To use Genie, you should have an OpenAI API key set in your environment variables. Once installed and configured, you can use the :Wish command followed by a natural language instruction to execute Lua code in Neovim.

Example: :Wish Open a new tab.

This command will generate Lua code aimed at opening a new tab and execute it immediately.

4. CONFIGURATION

Genie can be configured by passing a table with desired configurations to the setup function. Configuration options include the AI model to use and the temperature setting for responses.

Example in Lua:

local genie = require('genie')
genie.setup({
    model = 'gpt-4',
    temperature = 0.7,
    access_key = 'your_openai_api_key'
})

The access_key is optional if you already have it as an environment variable.

5. COMMANDS

Commands included in Genie are listed below:

  • :Wish: Executes code generated by AI based on natural language input.

Examples:

:Wish Close all windows except current one
:Wish Close all buffers except current one
:Wish Close all *.lua buffers
:Wish Get length of longest line in current buffer. Set current window width to that length plus 9.
:Wish Create vertical split and make it current window. Edit README.md in prior buffer.
:Wish What is our our current location?  You can use `curl` to determine.
:Wish How tall is Mount Everest?
:Wish Send keys 'echo hello' to the tmux pane to the right of current one. Do not use plenary.

6. FUNCTIONS

The notable functions in the Genie plugin:

  • ai(prompt_string): Contacts OpenAI with the given prompt and returns the result.

  • generate_code(action): Generates Lua code based on the given action described in natural language.

  • wish(instruction): Takes a natural language instruction, generates Lua code, and executes it.

  • setup(config): Configures Genie with the given settings.

7. TESTING

Testing is facilitated by Plenary test runner. Refer to test/genie_spec.lua for example tests and how to execute them.

8. LICENSE

Genie is distributed under the Apache License, Version 2.0. See the LICENSE file in the GitHub repository for more details: https://github.com/mikeslattery/genie.nvim

Copyright (c) 2023 Mike Slattery

This is free software; you can redistribute it and/or modify it under the terms of the Apache 2.0 License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.