WIP
This commit is contained in:
parent
0eea40e03e
commit
37b4bdb7dc
|
@ -18,7 +18,16 @@ M.opts = {
|
|||
nerdfonts = false,
|
||||
}
|
||||
|
||||
M.resources = {}
|
||||
M.resources = {
|
||||
icons = {
|
||||
user = "User:",
|
||||
assistant = "Assistant:",
|
||||
},
|
||||
spinner = {
|
||||
fps = 12,
|
||||
parts = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" },
|
||||
},
|
||||
}
|
||||
|
||||
function M.setup(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
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
local VERSION = "2023-06-01"
|
||||
-- local USERAGENT = "anthropic.nvim/0.0.0"
|
||||
|
||||
local opts = require("anthropic").opts
|
||||
|
||||
local M = {}
|
||||
|
@ -13,7 +15,12 @@ function M.make_headers()
|
|||
return
|
||||
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
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local session = require("anthropic.util.session")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.load_session()
|
||||
|
@ -5,10 +7,15 @@ function M.load_session()
|
|||
-- Redraw chat window with session
|
||||
end
|
||||
|
||||
function M.chat_message()
|
||||
-- Append user message to session
|
||||
--- # Message request wrapper function
|
||||
---
|
||||
--- 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
|
||||
-- Stream response to chat window and session
|
||||
-- Stream response to chat window and
|
||||
-- Update session
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -25,6 +25,7 @@ function M.save()
|
|||
end
|
||||
|
||||
--- # Load session from file
|
||||
---
|
||||
---@param name string
|
||||
function M.load(name)
|
||||
local path = filename(name)
|
||||
|
@ -47,6 +48,7 @@ function M.load(name)
|
|||
end
|
||||
|
||||
--- # List saved session names
|
||||
---
|
||||
---@return string[]
|
||||
function M.list()
|
||||
local sessions = vim.fn.glob(session_dir .. "/*.json", false, true)
|
||||
|
@ -56,4 +58,18 @@ function M.list()
|
|||
return sessions
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue