Skip to content

bug fixes and improvements #185

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

Merged
merged 7 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lua/gp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ local config = {
-- directory for persisting state dynamically changed by user (like model or persona)
state_dir = vim.fn.stdpath("data"):gsub("/$", "") .. "/gp/persisted",

-- default agent names set during startup, if nil last used agent is used
default_command_agent = nil,
default_chat_agent = nil,

-- default command agents (model + persona)
-- name, model and system_prompt are mandatory fields
-- to use agent for chat set chat = true, for command set command = true
Expand Down Expand Up @@ -122,7 +126,7 @@ local config = {
chat = true,
command = false,
-- string with model name or table with model name and parameters
model = { model = "gpt-4", temperature = 1.1, top_p = 1 },
model = { model = "gpt-4o", temperature = 1.1, top_p = 1 },
-- system prompt (use this to specify the persona/role of the AI)
system_prompt = require("gp.defaults").chat_system_prompt,
},
Expand Down Expand Up @@ -220,7 +224,7 @@ local config = {
chat = false,
command = true,
-- string with the Copilot engine name or table with engine name and parameters if applicable
model = { model = "gpt-4", temperature = 0.8, top_p = 1, n = 1 },
model = { model = "gpt-4o", temperature = 0.8, top_p = 1, n = 1 },
-- system prompt (use this to specify the persona/role of the AI)
system_prompt = require("gp.defaults").code_system_prompt,
},
Expand Down
46 changes: 33 additions & 13 deletions lua/gp/dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,8 @@ D.setup = function(opts)
end
end


for name, provider in pairs(D.providers) do
if name == "copilot" then
vault.resolve_secret(name, provider.secret, vault.refresh_copilot_bearer)
else
vault.resolve_secret(name, provider.secret)
end
vault.add_secret(name, provider.secret)
provider.secret = nil
end

Expand Down Expand Up @@ -152,6 +147,10 @@ D.prepare_payload = function(messages, model, provider)
return payload
end

if provider == "copilot" and model.model == "gpt-4o" then
model.model = "gpt-4o-2024-05-13"
end

return {
model = model.model,
stream = true,
Expand All @@ -168,7 +167,7 @@ end
---@param handler function # response handler
---@param on_exit function | nil # optional on_exit handler
---@param callback function | nil # optional callback handler
D.query = function(buf, provider, payload, handler, on_exit, callback)
local query = function(buf, provider, payload, handler, on_exit, callback)
-- make sure handler is a function
if type(handler) ~= "function" then
logger.error(
Expand Down Expand Up @@ -296,17 +295,18 @@ D.query = function(buf, provider, payload, handler, on_exit, callback)
---TODO: this could be moved to a separate function returning endpoint and headers
local endpoint = D.providers[provider].endpoint
local headers = {}
local bearer = vault.get_secret(provider)

local secret = provider
if provider == "copilot" then
secret = "copilot_bearer"
end
local bearer = vault.get_secret(secret)
if not bearer then
logger.warning(provider .. " bearer token is missing")
return
end

if provider == "copilot" then
vault.refresh_copilot_bearer()
bearer = vault.get_secret("copilot_bearer")
if not bearer then
return
end
headers = {
"-H",
"editor-version: vscode/1.85.1",
Expand Down Expand Up @@ -371,6 +371,26 @@ D.query = function(buf, provider, payload, handler, on_exit, callback)
tasker.run(buf, "curl", curl_params, nil, out_reader(), nil)
end

-- gpt query
---@param buf number | nil # buffer number
---@param provider string # provider name
---@param payload table # payload for api
---@param handler function # response handler
---@param on_exit function | nil # optional on_exit handler
---@param callback function | nil # optional callback handler
D.query = function(buf, provider, payload, handler, on_exit, callback)
if provider == "copilot" then
return vault.run_with_secret(provider, function()
vault.refresh_copilot_bearer(function()
query(buf, provider, payload, handler, on_exit, callback)
end)
end)
end
vault.run_with_secret(provider, function()
query(buf, provider, payload, handler, on_exit, callback)
end)
end

-- response handler
---@param buf number | nil # buffer to insert response into
---@param win number | nil # window to insert response into
Expand Down
6 changes: 0 additions & 6 deletions lua/gp/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ function M.check()
vim.health.error("grep is not installed")
end

if vim.fn.executable("ln") == 1 then
vim.health.ok("ln is installed")
else
vim.health.error("ln is not installed")
end

require("gp.whisper").check_health()
require("gp.deprecator").check_health()
end
Expand Down
12 changes: 9 additions & 3 deletions lua/gp/imager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ I.setup = function(opts)
I.refresh()

for cmd, _ in pairs(I.cmd) do
helpers.create_user_command(I.config.cmd_prefix .. cmd, I.cmd[cmd], function()
helpers.create_user_command(I.config.cmd_prefix .. cmd, I.cmd[cmd], function()
if cmd == "ImageAgent" then
return I._agents
end
Expand All @@ -84,7 +84,7 @@ I.setup = function(opts)
end)
end

vault.resolve_secret("imager_secret", I.config.secret)
vault.add_secret("imager_secret", I.config.secret)
I.config.secret = nil

logger.debug("imager setup finished")
Expand Down Expand Up @@ -156,7 +156,7 @@ I.cmd.Image = function(params)
end
end

I.generate_image = function(prompt, model, quality, style, size)
local generate_image = function(prompt, model, quality, style, size)
local bearer = vault.get_secret("imager_secret")
if not bearer then
return
Expand Down Expand Up @@ -262,4 +262,10 @@ I.generate_image = function(prompt, model, quality, style, size)
end)
end

I.generate_image = function(prompt, model, quality, style, size)
vault.run_with_secret("imager_secret", function()
generate_image(prompt, model, quality, style, size)
end)
end

return I
Loading
Loading