Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pidgeon777 opened this issue Sep 3, 2024 · 28 comments
Closed

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

pidgeon777 opened this issue Sep 3, 2024 · 28 comments

Comments

@pidgeon777
Copy link

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
Copy link
Collaborator

aarnphm commented Sep 3, 2024

do you have cargo?

@ben-maclaurin
Copy link

ben-maclaurin commented Sep 3, 2024

Getting the same error on macOS Sonoma.

cargo 1.80.1.
NVIM v0.10.0

@JoseConseco
Copy link

Same. I have cargo. Linux manjaro.

@aarnphm aarnphm closed this as completed in 24b66e0 Sep 3, 2024
@aarnphm aarnphm reopened this Sep 3, 2024
@aarnphm
Copy link
Collaborator

aarnphm commented Sep 3, 2024

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)

@aarnphm aarnphm closed this as completed Sep 3, 2024
@cschmatzler
Copy link

@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
Copy link
Author

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
Copy link
Author

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

image

@pidgeon777
Copy link
Author

pidgeon777 commented Sep 3, 2024

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:

  • target\release\avante_tokenizers.dll
  • target\release\avante_templates.dll

but the script expects them to be named:

  • target\release\libavante_tokenizers.dll
  • target\release\libavante_templates.dll

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>

@aarnphm aarnphm reopened this Sep 3, 2024
@tcpessoa
Copy link

tcpessoa commented Sep 3, 2024

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
Copy link

tcpessoa commented Sep 3, 2024

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
Copy link
Owner

yetone commented Sep 3, 2024

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

@HarrisDePerceptron
Copy link

i think it works now..

@yetone
Copy link
Owner

yetone commented Sep 3, 2024

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

@ohseunghyeon
Copy link

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
Copy link
Owner

yetone commented Sep 3, 2024

@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

@yetone
Copy link
Owner

yetone commented Sep 3, 2024

@ohseunghyeon
Copy link

ohseunghyeon commented Sep 3, 2024

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
Copy link
Owner

yetone commented Sep 3, 2024

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
Copy link
Owner

yetone commented Sep 3, 2024

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

@ohseunghyeon
Copy link

@yetone it works. thanks

@pidgeon777
Copy link
Author

@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
Copy link
Author

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:

#474 (comment)

@yetone
Copy link
Owner

yetone commented Sep 3, 2024

The Windows build script is still on the way: #483

@yuchanns
Copy link
Collaborator

yuchanns commented Sep 4, 2024

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

@pidgeon777
Copy link
Author

pidgeon777 commented Sep 4, 2024

@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.

@pidgeon777
Copy link
Author

@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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests