yetone / avante.nvim

Use your Neovim like using Cursor AI IDE!
Apache License 2.0
7.08k stars 258 forks source link

[Bug] Make sure to build avante (missing avante_templates) #474

Closed pidgeon777 closed 2 months ago

pidgeon777 commented 2 months ago

After running :AvanteAsk, and submitting the form, the following error is thrown:

E5108: Error executing lua: ...Data/Local/nvim-data/lazy/avante.nvim/lua/avante/llm.lua:59: Make sure to build avante (missing avante_templates)
stack traceback:
    [C]: in function 'error'
    ...ata/Local/nvim-data/lazy/avante.nvim/lua/avante/path.lua:75: in function 'get'
    ...Data/Local/nvim-data/lazy/avante.nvim/lua/avante/llm.lua:59: in function 'stream'
    .../Local/nvim-data/lazy/avante.nvim/lua/avante/sidebar.lua:1260: in function 'handle_submit'
    .../Local/nvim-data/lazy/avante.nvim/lua/avante/sidebar.lua:1313: in function <.../Local/nvim-data/lazy/avante.nvim/lua/avante/sidebar.lua:1303>

My config:

return {
  {
    "yetone/avante.nvim",

    dependencies = {
      "stevearc/dressing.nvim",
      "nvim-lua/plenary.nvim",
      "MunifTanjim/nui.nvim",
      --- The below dependencies are optional,
      "echasnovski/mini.icons", -- or nvim-tree/nvim-web-devicons
      "zbirenbaum/copilot.lua", -- for providers='copilot'
    },
    build = ":AvanteBuild",
    cmd = {
      "AvanteAsk",
      "AvanteEdit",
      "AvanteRefresh",
      "AvanteSwitchProviders",
    },
    keys = {
      {
        "<leader>3a",
        function()
          require("avante.api").ask()
        end,
        desc = "avante: ask",
        mode = { "n", "v" },
      },
      {
        "<leader>3r",
        function()
          require("avante.api").refresh()
        end,
        desc = "avante: refresh",
      },
      {
        "<leader>3e",
        function()
          require("avante.api").edit()
        end,
        desc = "avante: edit",
        mode = "v",
      },
    },
    opts = function(_, opts)
      local my_opts = {
        provider = "copilot",
        behaviour = {
          auto_suggestions = true, -- WARN: Experimental stage
        },
        windows = {
          position = "bottom",
          wrap = true,
        },
      }

      opts = vim.tbl_deep_extend("force", opts or {}, my_opts)

      return opts
    end,
    enabled = lvim.builtin.avante.active,
  },
}

nvim version:

NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1713484068
Run "nvim -V1 -v" for more info

Os is Windows 11 Pro.

aarnphm commented 2 months ago

do you have cargo?

ben-maclaurin commented 2 months ago

Getting the same error on macOS Sonoma.

cargo 1.80.1. NVIM v0.10.0

JoseConseco commented 2 months ago

Same. I have cargo. Linux manjaro.

aarnphm commented 2 months ago

can you check $HOME/.local/share/nvim/lazy/avante.nvim/build?

If it compiled binary?

Otherwise you can try installing from prebuilt (will require you to setup GITHUB_TOKEN)

cschmatzler commented 2 months ago

@aarnphm this is caused by build.sh checking for GITHUB_TOKEN even if source=false isn't set. So compiling from source also requires a GH token rn.

pidgeon777 commented 2 months ago

Output of cargo --version:

cargo 1.78.0 (54d8815d0 2024-03-26)

After installing the avante.nvim plugin for the first time, the directory C:\Users\<USERNAME>\AppData\Local\nvim-data\lazy\avante.nvim\build contains no files.

We should need to investigate why it is not possible to compile the source files with cargo in this case. It seems to affect all OS.

I also deleted the avante.nvim plugin folder, set the GITHUB_TOKEN variable to ghp_..., ran nvim, re-installed avante.nvim, but the problem still persists.

pidgeon777 commented 2 months ago

Those are the scopes I selected when generating the GitHub token:

image

pidgeon777 commented 2 months ago

On my setup, the Build.ps1 script executes:

cargo build --release --features=$feature

where $feature is supposed to be luajit.

This is the result:

Cargo build output: error: rustc 1.78.0 is not supported by the following packages: avante-templates@0.1.0 requires rustc 1.80 avante-tokenizers@0.1.0 requires rustc 1.80 mlua@0.10.0-beta.1 requires rustc 1.79.0 System.Management.Automation.RemoteException

I had cargo --version:

cargo 1.78.0 (54d8815d0 2024-03-26)

So I did rustup update:

info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
info: latest update on 2024-08-08, rust version 1.80.1 (3f5fd8dd4 2024-08-06)
info: downloading component 'rust-src'
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
 57.8 MiB /  57.8 MiB (100 %)  31.9 MiB/s in  2s ETA:  0s
info: downloading component 'rustfmt'
info: removing previous version of component 'rust-src'
info: removing previous version of component 'cargo'
info: removing previous version of component 'clippy'
info: removing previous version of component 'rust-docs'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: removing previous version of component 'rustfmt'
info: installing component 'rust-src'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 15.9 MiB /  15.9 MiB (100 %)   1.1 MiB/s in 14s ETA:  0s
info: installing component 'rust-std'
 18.2 MiB /  18.2 MiB (100 %)  16.6 MiB/s in  8s ETA:  0s
info: installing component 'rustc'
 57.8 MiB /  57.8 MiB (100 %)  15.5 MiB/s in  3s ETA:  0s
info: installing component 'rustfmt'
info: checking for self-update

  stable-x86_64-pc-windows-msvc updated - rustc 1.80.1 (3f5fd8dd4 2024-08-06) (from rustc 1.78.0 (9b00956e5 2024-04-29))

info: cleaning up downloads & tmp directories

and now I have cargo --version:

cargo 1.80.1 (376290515 2024-07-16)

I finally deleted again the avante.nvim folder, re-opened nvim, let it build the binaries from sources, and it was now able to generate the .dll files.

[!WARNING] The build process took around one minute on a laptop.

Also, this is the actual Build.ps1 script:

param (
    [string]$Version = "luajit"
)

$BuildDir = "build"
$BuildFromSource = $true

function Build-FromSource($feature) {
    if (-not (Test-Path $BuildDir)) {
        New-Item -ItemType Directory -Path $BuildDir | Out-Null
    }

    cargo build --release --features=$feature

    $targetTokenizerFile = "avante_tokenizers.dll"
    $targetTemplatesFile = "avante_templates.dll"
    Copy-Item (Join-Path "target\release\libavante_tokenizers.dll") (Join-Path $BuildDir $targetTokenizerFile)
    Copy-Item (Join-Path "target\release\libavante_templates.dll") (Join-Path $BuildDir $targetTemplatesFile)

    Remove-Item -Recurse -Force "target"
}

function Main {
    Set-Location $PSScriptRoot
    Write-Host "Building for $Version..."
    Build-FromSource $Version
    Write-Host "Completed!"
}

# Run the main function
Main

The problem is that once the build is finished, the two .dll files are created here:

but the script expects them to be named:

So, after manually copying the two .dll files to the build folder, AvanteAsk now produces this error when submitting the prompt:

E5108: Error executing lua: ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/path.lua:505: We couldn't mkdir: C:\Users\UA50D~1.USR\AppData\Local\Temp\nvim/avante\C:
stack traceback:
  [C]: in function 'error'
  ...a/Local/nvim-data/lazy/plenary.nvim/lua/plenary/path.lua:505: in function 'mkdir'
  ...ata/Local/nvim-data/lazy/avante.nvim/lua/avante/path.lua:82: in function 'get'
  ...Data/Local/nvim-data/lazy/avante.nvim/lua/avante/llm.lua:59: in function 'stream'
  .../Local/nvim-data/lazy/avante.nvim/lua/avante/sidebar.lua:1260: in function 'handle_submit'
  .../Local/nvim-data/lazy/avante.nvim/lua/avante/sidebar.lua:1313: in function <.../Local/nvim-data/lazy/avante.nvim/lua/avante/sidebar.lua:1303>
tcpessoa commented 2 months ago

I have macos (m chip). I have cargo installed, tried source=true did not work. I also set a GITHUB_TOKEN after, still did not work. Also tried to explicitly call AvanteBuild when inside neovim but it doesn't seem to do anything.

I was assuming that the build process happened at installation time of the plugin but maybe I am wrong.

let me know if you need any additional info.

tcpessoa commented 2 months ago

I have a working setup now by:

  1. cd $HOME/.local/share/nvim/lazy/avante.nvim/build
  2. chmod +x build.sh
  3. ./build.sh
  4. Restart neovim

This required the GITHUB_TOKEN though. I guess you could run cargo build or some equivalent command (I am not sure which command).

System is a MacOS M chip

yetone commented 2 months ago

It is unreasonable for the installation script to depend on $GITHUB_TOKEN, I will fix this issue as soon as possible.

HarrisDePerceptron commented 2 months ago

i think it works now..

yetone commented 2 months ago

I think it should be working normally now. Everyone can try reinstalling the latest version.

ohseunghyeon commented 2 months ago

this is what i get from lazynvim

    ● avante.nvim 19.09ms  VeryLazy
        LUA_VERSION=luajit sh ./build.sh
        + REPO_OWNER=yetone
        + REPO_NAME=avante.nvim
        +++ dirname -- ./build.sh
        ++ cd -- .
        ++ pwd
        + SCRIPT_DIR=/home/seunghyeonoh/.local/share/nvim/lazy/avante.nvim
        + TARGET_DIR=/home/seunghyeonoh/.local/share/nvim/lazy/avante.nvim/build
        + case "$(uname -s)" in
        ++ uname -s
        + PLATFORM=linux
        + LUA_VERSION=luajit
        + ARTIFACT_NAME_PATTERN=avante_lib-linux-latest-luajit
        ++ curl -s https://api.github.com/repos/yetone/avante.nvim/releases/latest
        ++ grep browser_download_url
        ++ cut -d '"' -f 4
        ++ grep avante_lib-linux-latest-luajit
        + ARTIFACT_URL=
        make: *** [Makefile:39: luajit] Error 1

i removed avante.nvim dir and tried reinstalling

yetone commented 2 months ago

@pidgeon777 Manually execute this command to see what the return value is:

curl -s https://api.github.com/repos/yetone/avante.nvim/releases/latest | grep browser_download_url | cut -d '"' -f 4
ohseunghyeon commented 2 months ago

i know you didn't mention me but the command returns this. avante_lib-linux-latest-luajit.tar.gz might be expected i think

https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-macos-latest-lua51.tar.gz https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-macos-latest-luajit.tar.gz https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-ubuntu-latest-lua51.tar.gz https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-ubuntu-latest-luajit.tar.gz https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-windows-latest-lua51.tar.gz https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-windows-latest-luajit.tar.gz

yetone commented 2 months ago

i know you didn't mention me but the command returns this. avante_lib-linux-latest-luajit.tar.gz might be expected i think

v0.0.1 avante_lib-macos-latest-lua51.tar.gz (download) v0.0.1 avante_lib-macos-latest-luajit.tar.gz (download) v0.0.1 avante_lib-ubuntu-latest-lua51.tar.gz (download) v0.0.1 avante_lib-ubuntu-latest-luajit.tar.gz (download) v0.0.1 avante_lib-windows-latest-lua51.tar.gz (download) v0.0.1 avante_lib-windows-latest-luajit.tar.gz (download)

Did you also encounter errors during the installation?

ohseunghyeon commented 2 months ago

i know you didn't mention me but the command returns this. avante_lib-linux-latest-luajit.tar.gz might be expected i think v0.0.1 avante_lib-macos-latest-lua51.tar.gz (download) v0.0.1 avante_lib-macos-latest-luajit.tar.gz (download) v0.0.1 avante_lib-ubuntu-latest-lua51.tar.gz (download) v0.0.1 avante_lib-ubuntu-latest-luajit.tar.gz (download) v0.0.1 avante_lib-windows-latest-lua51.tar.gz (download) v0.0.1 avante_lib-windows-latest-luajit.tar.gz (download)

Did you also encounter errors during the installation?

Yes. the build script(build.sh) doesn't run well. reason is that ARTIFACT_NAME_PATTERN variable is avante_lib-linux-latest-luajit on my environment and there's no matching tar.gz file from the release json file

yetone commented 2 months ago

i know you didn't mention me but the command returns this. avante_lib-linux-latest-luajit.tar.gz might be expected i think v0.0.1 avante_lib-macos-latest-lua51.tar.gz (download) v0.0.1 avante_lib-macos-latest-luajit.tar.gz (download) v0.0.1 avante_lib-ubuntu-latest-lua51.tar.gz (download) v0.0.1 avante_lib-ubuntu-latest-luajit.tar.gz (download) v0.0.1 avante_lib-windows-latest-lua51.tar.gz (download) v0.0.1 avante_lib-windows-latest-luajit.tar.gz (download)

Did you also encounter errors during the installation?

Yes. the build script(build.sh) doesn't run well. reason is that ARTIFACT_NAME_PATTERN variable is avante_lib-linux-latest-luajit on my environment and there's no matching tar.gz file from the release json file

Got it! Thank you for pointing out the issue!

yetone commented 2 months ago

@ohseunghyeon I have already fixed this issue in the latest version. Can you try again?

ohseunghyeon commented 2 months ago

@yetone it works. thanks

pidgeon777 commented 2 months ago

@pidgeon777 Manually execute this command to see what the return value is:

curl -s https://api.github.com/repos/yetone/avante.nvim/releases/latest | grep browser_download_url | cut -d '"' -f 4

I'm on Windows, I installed grep and curl but cut is missing, anyway I was able to execute this:

C:\Users\<USERNAME>>curl -s https://api.github.com/repos/yetone/avante.nvim/releases/latest | grep browser_download_url
      "browser_download_url": "https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-macos-latest-lua51.tar.gz"
      "browser_download_url": "https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-macos-latest-luajit.tar.gz"
      "browser_download_url": "https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-ubuntu-latest-lua51.tar.gz"
      "browser_download_url": "https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-ubuntu-latest-luajit.tar.gz"
      "browser_download_url": "https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-windows-latest-lua51.tar.gz"
      "browser_download_url": "https://github.com/yetone/avante.nvim/releases/download/v0.0.1/avante_lib-windows-latest-luajit.tar.gz"

Still, after removing the avante.nvim folder and running nvim, when submitting the prompt with AvanteAsk I get the same error:

E5108: Error executing lua: ...Data/Local/nvim-data/lazy/avante.nvim/lua/avante/llm.lua:59: Make sure to build avante (missing avante_templates)
stack traceback:
    [C]: in function 'error'
    ...ata/Local/nvim-data/lazy/avante.nvim/lua/avante/path.lua:75: in function 'get'
    ...Data/Local/nvim-data/lazy/avante.nvim/lua/avante/llm.lua:59: in function 'stream'
    .../Local/nvim-data/lazy/avante.nvim/lua/avante/sidebar.lua:1260: in function 'handle_submit'
    .../Local/nvim-data/lazy/avante.nvim/lua/avante/sidebar.lua:1313: in function <.../Local/nvim-data/lazy/avante.nvim/lua/avante/sidebar.lua:1303>
pidgeon777 commented 2 months ago

At this point, it seems that there are differences in how file paths (and build scripts) are managed differently by the plugin in Unix and Windows environments.

I have created an issue regarding the handling of file paths, as it seems there is a problem specifically in the Windows version:

GitHub Issue #480

In the meantime, it might be worth re-opening the current issue, as the problem appears to be unresolved on Windows.

Finally, I added some more notes here:

https://github.com/yetone/avante.nvim/issues/474#issuecomment-2326375512

yetone commented 2 months ago

The Windows build script is still on the way: https://github.com/yetone/avante.nvim/pull/483

yuchanns commented 2 months ago

@pidgeon777 Hi please try on the latest. Windows build script is now available.

pidgeon777 commented 2 months ago

@pidgeon777 Hi please try on the latest. Windows build script is now available.

On Windows it succeded, the following files have been created:

C:\Users\<USERNAME>\AppData\Local\nvim-data\lazy\avante.nvim\build\avante_tokenizers.dll
C:\Users\<USERNAME>\AppData\Local\nvim-data\lazy\avante.nvim\build\avante_templates.dll

Still, this problem persists:

https://github.com/yetone/avante.nvim/issues/480

making it not possible to run avante.nvim on Windows.

pidgeon777 commented 2 months ago

@pidgeon777 Hi please try on the latest. Windows build script is now available.

On Windows it succeded, the following files have been created:

C:\Users\<USERNAME>\AppData\Local\nvim-data\lazy\avante.nvim\build\avante_tokenizers.dll
C:\Users\<USERNAME>\AppData\Local\nvim-data\lazy\avante.nvim\build\avante_templates.dll

Still, this problem persists:

480

making it not possible to run avante.nvim on Windows.

It is now solved.

RomaLzhih commented 2 months ago

I am on rocky linux and installed the latest avante, but it has the same problem, please let me know if you need any info. Thanks.