From 4f00972dec8836a9f5bfeb756bc5a078e4a285ef Mon Sep 17 00:00:00 2001 From: Ruslan Date: Thu, 19 Jun 2025 18:26:56 +0300 Subject: [PATCH] update parrot --- lua/crentist/lazy/parrot.lua | 37 +++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/lua/crentist/lazy/parrot.lua b/lua/crentist/lazy/parrot.lua index a650957..a02c200 100644 --- a/lua/crentist/lazy/parrot.lua +++ b/lua/crentist/lazy/parrot.lua @@ -1,12 +1,43 @@ return { 'frankroeder/parrot.nvim', + version = "2.1.0", dependencies = { 'ibhagwan/fzf-lua', 'nvim-lua/plenary.nvim' }, opts = { providers = { anthropic = { - -- OPTIONAL: Alternative methods to retrieve API key - -- Using GPG for decryption: - api_key = { "sops", "-d", vim.fn.expand("$HOME") .. "/.claude-api" }, + name = "anthropic", + endpoint = "https://api.anthropic.com/v1/messages", + model_endpoint = "https://api.anthropic.com/v1/models", + api_key = { "/usr/local/bin/sops", "--config", "/dev/null", "-d", vim.fn.expand("$HOME") .. "/.claude-api" }, + headers = function(self) + return { + ["Content-Type"] = "application/json", + ["x-api-key"] = self.api_key, + ["anthropic-version"] = "2023-06-01", + } + end, + params = { + chat = { max_tokens = 4096 }, + command = { max_tokens = 4096 }, + }, + models = { + "claude-sonnet-4-20250514", + "claude-3-7-sonnet-20250219", + "claude-3-5-sonnet-20241022", + "claude-3-5-haiku-20241022", + }, + preprocess_payload = function(payload) + for _, message in ipairs(payload.messages) do + message.content = message.content:gsub("^%s*(.-)%s*$", "%1") + end + if payload.messages[1] and payload.messages[1].role == "system" then + -- remove the first message that serves as the system prompt as anthropic + -- expects the system prompt to be part of the API call body and not the messages + payload.system = payload.messages[1].content + table.remove(payload.messages, 1) + end + return payload + end, } } }