nvim-bard is a minimal plugin to interact with Bard using bardapi python package.
Important
Writing this plugin was a lot of fun, but I don't recommend using it for anything other than experimentation.
It works with bardapi which is not an official API and which can stop working at the slightest change in Bard's policy.
Since August, it seems that it is necessary to update the cookie values regularly.
Also, this AI is quite slow and seems to me less efficient than ChatGPT for coding.
This plugin requires bardapi
pip install bardapi
- Go to bard.google.com
- Open developer tools
- Go to Application
- Go to Cookies
- Copy the content of
__Secure-1PSID
innvim-bard
config (bard_api_key
)
{
'martineausimon/nvim-bard',
dependencies = 'MunifTanjim/nui.nvim', -- only for "popup" mode
config = function()
require('nvim-bard').setup({
bard_api_key = "", --required
display_mode = "popup", -- "popup", "vsplit" or "tabnew"
mappings = {
toggle_bard = "<leader>b",
hide_bard = { "q", "<esc>" },
send_bard = "<cr>",
new_chat = "<c-n>"
},
options = {
ui = {
question = {
signs = {
sign = "",
hi = "Function",
style = "single" -- "double", "none", "rounded", "solid"
},
border = { -- only for "popup" mode
style = "single", -- "double", "none", "shadow", "rounded", "solid"
text = {
top = "[Prompt]"
}
},
winhighlight = "Normal:Normal,FloatBorder:Normal"
},
bard = {
signs = {
sign = "🟆",
hi = "Statement",
style = "single"
},
border = {
style = "single",
text = {
top = "[Bard]"
}
},
winhighlight = "Normal:Normal,FloatBorder:Normal"
}
},
buffer_options = {
signcolumn = 'yes:1',
filetype = 'markdown',
conceallevel = 3,
buftype = "nofile",
},
}
})
end
}
Since august, Bard has updated it's policy and settings for different regions and you may need to set bard_api_key this way, retrieving the values from Secure-1PSID
, Secure-1PSIDCC
, et Secure-1PSIDTS
:
require('nvim-bard').setup({
bard_api_key = {
psid = "xxxx",
psidcc = "xxxx",
psidts = "xxxx"
},
}
⚠ __Secure-1PSID
is private ! If you don't want to write this Bard API key in your config directly, you can store it in a local file (e.g. $HOME/.bard_api_key
), and use the following function:
local api_key
local file = io.open('/home/user/.bard_api_key', 'r')
if file then
api_key = file:read()
file:close()
end
{
'martineausimon/nvim-bard',
dependencies = 'MunifTanjim/nui.nvim',
config = function()
require('nvim-bard').setup({
bard_api_key = api_key,
})
end
}