Skip to content

Commit

Permalink
ensure claude enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Oct 29, 2024
1 parent 93a9f29 commit 8260483
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lua/CopilotChat/copilot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ local version_headers = {
['editor-plugin-version'] = 'CopilotChat.nvim/2.0.0',
['user-agent'] = 'CopilotChat.nvim/2.0.0',
}
local claude_enabled = false

local function uuid()
local template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
Expand Down Expand Up @@ -364,6 +365,36 @@ function Copilot:with_auth(on_done, on_error)
end
end

function Copilot:enable_claude()
if claude_enabled then
return
end
self:with_auth(function()
local url = 'https://api.githubcopilot.com/models/claude-3.5-sonnet/policy'
local headers = generate_headers(self.token.token, self.sessionid, self.machineid)
curl.post(url, {
timeout = timeout,
headers = headers,
proxy = self.proxy,
insecure = self.allow_insecure,
on_error = function(err)
err = 'Failed to enable Claude: ' .. vim.inspect(err)
log.error(err)
end,
body = temp_file('{"state": "enabled"}'),
callback = function(response)
if response.status ~= 200 then
local msg = 'Failed to enable Claude: ' .. tostring(response.status)
log.error(msg)
return
end
claude_enabled = true
log.info('Claude enabled')
end,
})
end)
end

--- Ask a question to Copilot
---@param prompt string: The prompt to send to Copilot
---@param opts CopilotChat.copilot.ask.opts: Options for the request
Expand Down Expand Up @@ -420,6 +451,10 @@ function Copilot:ask(prompt, opts)
embeddings_message.files = filtered_files
end

if vim.startswith(model, 'claude') then
self:enable_claude()
end

local url = 'https://api.githubcopilot.com/chat/completions'
local body = vim.json.encode(
generate_ask_request(
Expand Down

0 comments on commit 8260483

Please sign in to comment.