From 45d7b3a390956363a13749ba936dcbba28327b0e Mon Sep 17 00:00:00 2001 From: CsBigDataHub Date: Fri, 19 Sep 2025 17:44:11 -0400 Subject: [PATCH 1/5] support `api.business.githubcopilot.com` --- gptel-gh.el | 54 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/gptel-gh.el b/gptel-gh.el index 95b1782b..ae9e1ef0 100644 --- a/gptel-gh.el +++ b/gptel-gh.el @@ -25,6 +25,11 @@ (require 'gptel) (require 'browse-url) +(defgroup gptel-gh nil + "GitHub Copilot integration for gptel." + :group 'gptel + :prefix "gptel-gh-") + ;;; Github Copilot (defconst gptel--gh-models '((gpt-4o @@ -184,6 +189,21 @@ :type 'string :group 'gptel) +(defcustom gptel-gh-api-host "api.githubcopilot.com" + "Default host to use for the GitHub Copilot API. + +By default this is ""api.githubcopilot.com"" for the consumer Copilot +service. If you are using GitHub Copilot for Business, set this to +""api.business.githubcopilot.com"". + +This value is used when a host argument is not provided to +`gptel-make-gh-copilot'." + :type '(choice + (const :tag "Consumer (api.githubcopilot.com)" "api.githubcopilot.com") + (const :tag "Business (api.business.githubcopilot.com)" "api.business.githubcopilot.com") + string) + :group 'gptel) + (defconst gptel--gh-auth-common-headers `(("editor-plugin-version" . "gptel/*") ("editor-version" . ,(concat "emacs/" emacs-version)))) @@ -206,7 +226,7 @@ (length 65) hex) (dotimes (_ length) - (setq hex (nconc hex (list (aref hex-chars (random 16)))))) + (setq hex (nconc hex (list (aref hex-chars (random 16))))) ) (apply #'string hex))) (defun gptel--gh-restore (file) @@ -316,7 +336,7 @@ Then we need a session token." (gptel--gh-auth) `(("openai-intent" . "conversation-panel") ("authorization" . ,(concat "Bearer " - (plist-get (gptel--gh-token gptel-backend) :token))) + (plist-get (gptel--gh-token gptel-backend) :token))) ("x-request-id" . ,(gptel--gh-uuid)) ("vscode-sessionid" . ,(or (gptel--gh-sessionid gptel-backend) "")) ("vscode-machineid" . ,(or (gptel--gh-machineid gptel-backend) "")) @@ -324,7 +344,7 @@ Then we need a session token." (gptel--model-capable-p 'media)) `(("copilot-vision-request" . "true"))) ("copilot-integration-id" . "vscode-chat")))) - (host "api.githubcopilot.com") + (host nil) (protocol "https") (endpoint "/chat/completions") (stream t) @@ -335,7 +355,9 @@ Keyword arguments: CURL-ARGS (optional) is a list of additional Curl arguments. -HOST (optional) is the API host, typically \"api.githubcopilot.com\". +HOST (optional) is the API host, typically "api.githubcopilot.com". +If nil, `gptel-gh-api-host' is used. Set this to +"api.business.githubcopilot.com" when using Copilot for Business. MODELS is a list of available model names, as symbols. Additionally, you can specify supported LLM capabilities like @@ -348,15 +370,15 @@ For a list of currently recognized plist keys, see `gptel--openai-models'. An example of a model specification including both kinds of specs: -:models -\\='(gpt-3.5-turbo ;Simple specs - gpt-4-turbo - (gpt-4o-mini ;Full spec - :description - \"Affordable and intelligent small model for lightweight tasks\" - :capabilities (media tool json url) - :mime-types - (\"image/jpeg\" \"image/png\" \"image/gif\" \"image/webp\"))) + :models + \\='(gpt-3.5-turbo ;Simple specs + gpt-4-turbo + (gpt-4o-mini ;Full spec + :description + "Affordable and intelligent small model for lightweight tasks" + :capabilities (media tool json url) + :mime-types + ("image/jpeg" "image/png" "image/gif" "image/webp"))) Defaults to a list of models supported by GitHub Copilot. @@ -366,12 +388,12 @@ false. PROTOCOL (optional) specifies the protocol, https by default. ENDPOINT (optional) is the API endpoint for completions, defaults to -\"/chat/completions\". +"/chat/completions". HEADER (optional) is for additional headers to send with each request. It should be an alist or a function that returns an alist, like: - ((\"Content-Type\" . \"application/json\")) + (("Content-Type" . "application/json")) Defaults to headers required by GitHub Copilot. @@ -380,6 +402,8 @@ parameters (as plist keys) and values supported by the API. Use these to set parameters that gptel does not provide user options for." (declare (indent 1)) + (unless host + (setq host gptel-gh-api-host)) (let ((backend (gptel--make-gh :name name :host host From 4d6278c6c879f9aa2f4e963d5a73ea89504bf1e6 Mon Sep 17 00:00:00 2001 From: CsBigDataHub Date: Fri, 19 Sep 2025 17:55:15 -0400 Subject: [PATCH 2/5] support `api.business.githubcopilot.com` --- gptel-gh.el | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/gptel-gh.el b/gptel-gh.el index ae9e1ef0..503548d5 100644 --- a/gptel-gh.el +++ b/gptel-gh.el @@ -25,11 +25,6 @@ (require 'gptel) (require 'browse-url) -(defgroup gptel-gh nil - "GitHub Copilot integration for gptel." - :group 'gptel - :prefix "gptel-gh-") - ;;; Github Copilot (defconst gptel--gh-models '((gpt-4o @@ -191,17 +186,9 @@ (defcustom gptel-gh-api-host "api.githubcopilot.com" "Default host to use for the GitHub Copilot API. - -By default this is ""api.githubcopilot.com"" for the consumer Copilot -service. If you are using GitHub Copilot for Business, set this to -""api.business.githubcopilot.com"". - -This value is used when a host argument is not provided to -`gptel-make-gh-copilot'." - :type '(choice - (const :tag "Consumer (api.githubcopilot.com)" "api.githubcopilot.com") - (const :tag "Business (api.business.githubcopilot.com)" "api.business.githubcopilot.com") - string) +Set this to "api.business.githubcopilot.com" when using Copilot for Business. +" + :type 'string :group 'gptel) (defconst gptel--gh-auth-common-headers @@ -344,7 +331,7 @@ Then we need a session token." (gptel--model-capable-p 'media)) `(("copilot-vision-request" . "true"))) ("copilot-integration-id" . "vscode-chat")))) - (host nil) + (host gptel-gh-api-host) (protocol "https") (endpoint "/chat/completions") (stream t) @@ -402,8 +389,6 @@ parameters (as plist keys) and values supported by the API. Use these to set parameters that gptel does not provide user options for." (declare (indent 1)) - (unless host - (setq host gptel-gh-api-host)) (let ((backend (gptel--make-gh :name name :host host From cf4193bf0019eca07bde0917d38c18baa17ed4de Mon Sep 17 00:00:00 2001 From: CsBigDataHub Date: Fri, 19 Sep 2025 18:02:27 -0400 Subject: [PATCH 3/5] fix docs gptel-gh.el --- gptel-gh.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gptel-gh.el b/gptel-gh.el index 503548d5..2bd8ddef 100644 --- a/gptel-gh.el +++ b/gptel-gh.el @@ -213,7 +213,7 @@ Set this to "api.business.githubcopilot.com" when using Copilot for Business. (length 65) hex) (dotimes (_ length) - (setq hex (nconc hex (list (aref hex-chars (random 16))))) ) + (setq hex (nconc hex (list (aref hex-chars (random 16)))))) (apply #'string hex))) (defun gptel--gh-restore (file) @@ -344,7 +344,7 @@ CURL-ARGS (optional) is a list of additional Curl arguments. HOST (optional) is the API host, typically "api.githubcopilot.com". If nil, `gptel-gh-api-host' is used. Set this to -"api.business.githubcopilot.com" when using Copilot for Business. +\"api.business.githubcopilot.com\" when using Copilot for Business. MODELS is a list of available model names, as symbols. Additionally, you can specify supported LLM capabilities like @@ -362,10 +362,10 @@ including both kinds of specs: gpt-4-turbo (gpt-4o-mini ;Full spec :description - "Affordable and intelligent small model for lightweight tasks" + \"Affordable and intelligent small model for lightweight tasks\" :capabilities (media tool json url) :mime-types - ("image/jpeg" "image/png" "image/gif" "image/webp"))) + (\"image/jpeg\" \"image/png\" \"image/gif\" \"image/webp\"))) Defaults to a list of models supported by GitHub Copilot. @@ -375,12 +375,12 @@ false. PROTOCOL (optional) specifies the protocol, https by default. ENDPOINT (optional) is the API endpoint for completions, defaults to -"/chat/completions". +\"/chat/completions\". HEADER (optional) is for additional headers to send with each request. It should be an alist or a function that returns an alist, like: - (("Content-Type" . "application/json")) + ((\"Content-Type\" . \"application/json\")) Defaults to headers required by GitHub Copilot. From 14c829584e950b6b947d926d72bec0c0fa51dceb Mon Sep 17 00:00:00 2001 From: CsBigDataHub Date: Fri, 19 Sep 2025 18:05:11 -0400 Subject: [PATCH 4/5] defcustom gptel-gh-api-host --- gptel-gh.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gptel-gh.el b/gptel-gh.el index 2bd8ddef..bbb41f43 100644 --- a/gptel-gh.el +++ b/gptel-gh.el @@ -186,9 +186,11 @@ (defcustom gptel-gh-api-host "api.githubcopilot.com" "Default host to use for the GitHub Copilot API. -Set this to "api.business.githubcopilot.com" when using Copilot for Business. +Set this to \"api.business.githubcopilot.com\" when using Copilot for Business. " - :type 'string + :type '(choice (const :tag "Consumer" "api.githubcopilot.com") + (const :tag "Business" "api.business.githubcopilot.com") + string) :group 'gptel) (defconst gptel--gh-auth-common-headers From b6ce172ef8beb3829a1a3eeaabcbfcec70e2b3b1 Mon Sep 17 00:00:00 2001 From: CsBigDataHub Date: Fri, 19 Sep 2025 18:07:31 -0400 Subject: [PATCH 5/5] fix docs gptel-gh.el --- gptel-gh.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gptel-gh.el b/gptel-gh.el index bbb41f43..0f860ffb 100644 --- a/gptel-gh.el +++ b/gptel-gh.el @@ -344,7 +344,7 @@ Keyword arguments: CURL-ARGS (optional) is a list of additional Curl arguments. -HOST (optional) is the API host, typically "api.githubcopilot.com". +HOST (optional) is the API host, typically \"api.githubcopilot.com\". If nil, `gptel-gh-api-host' is used. Set this to \"api.business.githubcopilot.com\" when using Copilot for Business.