Skip to content
generated from S1M0N38/base.nvim

OpenAI chat completion request (JSON) ⇋ markdown & sent requests

License

Notifications You must be signed in to change notification settings

S1M0N38/chatml.nvim

Repository files navigation

⇋  chatml.nvim  

Tests workflow LuaRocks release GitHub release Reddit post

chatml.mp4

OpenAI chat completion request (JSON) ⇋ markdown & sent requests


💡 Idea

chatml.nvim is a simple Neovim plugin for working with LLM chat completion requests. It provides bidirectional conversion between two formats:

  • A human-friendly markdown format: readable and easy to edit and navigate
  • The JSON format required by OpenAI-compatible APIs

It follows the chat-completion-md specification.

While the plugin can send requests to LLM providers, it keeps a modest scope. It doesn't try to be context-aware or integrate with your development environment. Instead, it's just a playground for experimenting with prompts, letting you focus on crafting and refining your LLM interactions.

Think of it as a basic text converter with optional LLM integration, not a comprehensive AI coding assistant.

⚡️ Requirements

📦 Installation

You can install chatml.nvim using your preferred plugin manager. Here's an example configuration for lazy.nvim:

-- Using lazy.nvim
{
  "S1M0N38/chatml.nvim",
  version = "*",
  opts = {},
  dependencies = {
    {
      -- (Required) Used for parsing various formats
      "nvim-treesitter/nvim-treesitter",
      build = ":TSUpdate",
      opts = {
        ensure_installed = { "markdown", "markdown_inline", "yaml", "json" },
      },
    },
    {
      -- (Optional) It is required for sending requests to LLM providers
      "S1M0N38/ai.nvim",
      version = ">=1.4.2",
      opts = {
        -- (Required) Configure a provider. :help ai-setup or
        -- https://github.com/S1M0N38/ai.nvim/blob/main/doc/ai.txt
      },
    },
  },
  keys = {
    {
      "<leader>fa",
      function()
        --- Setup prompts search for your preferred picker. For LazyVim, use:
        LazyVim.pick("files", { cwd = "path/to/prompts/directory" })()
      end,
      desc = "Find ai-prompts (chatml)",
      mode = { "n" },
    },
    {
      "<S-CR>",
      function()
        require("chatml.llm").chat_completion(vim.api.nvim_get_current_buf())
      end,
      desc = "Send requests to LLM",
      ft = "markdown",
      mode = { "n" },
    },
    {
      "<C-CR>",
      function()
        require("chatml.parse").md_buf_to_json_buf(0, 0)
        vim.cmd("LspRestart")
        -- 2 space indentation for JSON in LazyVim:
        LazyVim.format({ force = true })
      end,
      desc = "Convert from markdown to JSON",
      ft = "markdown",
      mode = { "n" },
    },
    {
      "<C-CR>",
      function()
        require("chatml.parse").json_buf_to_md_buf(0, 0)
        vim.cmd("LspRestart")
      end,
      desc = "Convert from JSON to markdown",
      ft = "json",
      mode = { "n" },
    },
  },
}

🚀 Usage

To get started with chatml.nvim, read the documentation with :help chatml. This will provide you with a comprehensive overview of the plugin's features and usage.

Note

Learning Vim/Neovim Documentation: Vim/Neovim plugins are usually shipped with :help documentation. Learning how to navigate it is a valuable skill. If you are not familiar with it, start with :help and read the first 20 lines.

🙏 Acknowledgments

About

OpenAI chat completion request (JSON) ⇋ markdown & sent requests

Topics

Resources

License

Stars

Watchers

Forks

Languages