-
-
Notifications
You must be signed in to change notification settings - Fork 122
fix(copilot)!: allow overriding headers, api_base #1061
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
base: main
Are you sure you want to change the base?
Conversation
I would rather fix the actual issue. I dont like this solution because I am intentionally keeping the provider interfaces simple, and also its not even actual solution because the user is expected to override the headers until it starts working. But for example zed is using the static url always, and github usually properly redirects them too: And they also do not need to fake that they are going through vscode: |
But sending self might be fine but I dont think you need to add the changing api base anywhere else other than copilot provider, in embeddings simply use value from there when building the url and thats it and you dont need to do any changes to github_models. And it def shouldnt be part of the type definition. But def remove the default_headers, you are supposed to make your own provider when doing that (which is very simple you just reference the methods from your custom implementation and thats it right) |
@deathbeam, I agree with you. Anyways, do you agree with keeping the api_base? A few points:
|
Well I dont want to keep api base as part of the default api, it should be copilot provider specific. you can always refer to it from other providers in the actual functions, and updating it from the inside of copilot provider. E.g its very specific to the copilot provider so it should just stay there imo. |
@deathbeam Can you review now ? For others, the following lazy.nvim config shows how I'm able to override them. {
"CopilotC-Nvim/CopilotChat.nvim",
-- url = "https://github.com/80avin/CopilotChat.nvim",
opts = function(opts)
local providers = require("CopilotChat.config.providers")
local orig_provider = providers.copilot
---@diagnostic disable-next-line: inject-field
orig_provider._cache_get_header = orig_provider._cache_get_header or orig_provider.get_headers
local orig_get_header = orig_provider._cache_get_header
orig_provider.get_headers = function(self)
---@diagnostic disable-next-line: need-check-nil
local headers, expires_at = orig_get_header(self)
return vim.tbl_extend("force", headers, {
["Editor-Version"] = "vscode/1.98.2",
["Editor-Plugin-Version"] = "copilot-chat/0.25.1",
}),
expires_at
end
providers.github_models.disabled = true
if true then
return nil
end
end,
} |
We are using organizational version of Github copilot and I used to get unauthorized error, similar to #1052 ,
Digging deeper into the vscode's Copilot-chat extension, I found 2 differences which are required to fix this
api.business.githubcopilot.com
As a solution, this PR implements
self
as function argument helps this case.Note: I haven't tested github_models because they weren't working under my credentials.