WIP
This commit is contained in:
parent
0eea40e03e
commit
37b4bdb7dc
|
@ -18,7 +18,16 @@ M.opts = {
|
||||||
nerdfonts = false,
|
nerdfonts = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
M.resources = {}
|
M.resources = {
|
||||||
|
icons = {
|
||||||
|
user = "User:",
|
||||||
|
assistant = "Assistant:",
|
||||||
|
},
|
||||||
|
spinner = {
|
||||||
|
fps = 12,
|
||||||
|
parts = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.opts = vim.tbl_deep_extend("force", M.opts, opts)
|
M.opts = vim.tbl_deep_extend("force", M.opts, opts)
|
||||||
|
@ -38,17 +47,6 @@ function M.setup(opts)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
else
|
|
||||||
M.resources = {
|
|
||||||
icons = {
|
|
||||||
user = "User:",
|
|
||||||
assistant = "Assistant:",
|
|
||||||
},
|
|
||||||
spinner = {
|
|
||||||
fps = 12,
|
|
||||||
parts = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
local VERSION = "2023-06-01"
|
local VERSION = "2023-06-01"
|
||||||
|
-- local USERAGENT = "anthropic.nvim/0.0.0"
|
||||||
|
|
||||||
local opts = require("anthropic").opts
|
local opts = require("anthropic").opts
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
@ -13,7 +15,12 @@ function M.make_headers()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local headers = { ["content-type"] = "application/json", ["anthropic-version"] = VERSION, ["x-api-key"] = opts.token }
|
local headers = {
|
||||||
|
-- ["user-agent"] = USERAGENT,
|
||||||
|
["content-type"] = "application/json",
|
||||||
|
["anthropic-version"] = VERSION,
|
||||||
|
["x-api-key"] = opts.token,
|
||||||
|
}
|
||||||
|
|
||||||
return headers
|
return headers
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
local session = require("anthropic.util.session")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.load_session()
|
function M.load_session()
|
||||||
|
@ -5,10 +7,15 @@ function M.load_session()
|
||||||
-- Redraw chat window with session
|
-- Redraw chat window with session
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.chat_message()
|
--- # Message request wrapper function
|
||||||
-- Append user message to session
|
---
|
||||||
|
--- Calls the Anthropic API and writes the response to the chatbox
|
||||||
|
---@param message string
|
||||||
|
function M.send_message(message)
|
||||||
|
session.add_message(message, "user")
|
||||||
-- Call API with session
|
-- Call API with session
|
||||||
-- Stream response to chat window and session
|
-- Stream response to chat window and
|
||||||
|
-- Update session
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -25,6 +25,7 @@ function M.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- # Load session from file
|
--- # Load session from file
|
||||||
|
---
|
||||||
---@param name string
|
---@param name string
|
||||||
function M.load(name)
|
function M.load(name)
|
||||||
local path = filename(name)
|
local path = filename(name)
|
||||||
|
@ -47,6 +48,7 @@ function M.load(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- # List saved session names
|
--- # List saved session names
|
||||||
|
---
|
||||||
---@return string[]
|
---@return string[]
|
||||||
function M.list()
|
function M.list()
|
||||||
local sessions = vim.fn.glob(session_dir .. "/*.json", false, true)
|
local sessions = vim.fn.glob(session_dir .. "/*.json", false, true)
|
||||||
|
@ -56,4 +58,18 @@ function M.list()
|
||||||
return sessions
|
return sessions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- # Add a message to the session
|
||||||
|
---
|
||||||
|
---@param message string
|
||||||
|
---@param role "user" | "assistant"
|
||||||
|
function M.add_message(message, role)
|
||||||
|
local msgs = M.session.messages
|
||||||
|
if msgs[#msgs - 1].role == role then
|
||||||
|
vim.notify("anthropic: " .. role .. " message added after a " .. role .. " message", vim.log.levels.ERROR)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(msgs, { role = role, content = message })
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in New Issue