Skip to content
Open
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
32 changes: 19 additions & 13 deletions gptel-gh.el
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,21 @@ Then we need a session token."
(name &key curl-args request-params
(header (lambda ()
(gptel--gh-auth)
`(("openai-intent" . "conversation-panel")
("authorization" . ,(concat "Bearer "
(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) ""))
,@(when (and gptel-track-media
(gptel--model-capable-p 'media))
`(("copilot-vision-request" . "true")))
("copilot-integration-id" . "vscode-chat"))))
(host "api.githubcopilot.com")
(protocol "https")
(pcase-let* (((map :token (:endpoints (map :api)))
(gptel--gh-token gptel-backend))
((cl-struct url host type) (url-generic-parse-url api)))
(setf (gptel-backend-host gptel-backend) (or host "api.githubcopilot.com")
(gptel-backend-protocol gptel-backend) (or type "https"))
`(("openai-intent" . "conversation-panel")
("authorization" . ,(concat "Bearer " token))
("x-request-id" . ,(gptel--gh-uuid))
("vscode-sessionid" . ,(or (gptel--gh-sessionid gptel-backend) ""))
("vscode-machineid" . ,(or (gptel--gh-machineid gptel-backend) ""))
,@(when (and gptel-track-media
(gptel--model-capable-p 'media))
`(("copilot-vision-request" . "true")))
("copilot-integration-id" . "vscode-chat")))))
host protocol
(endpoint "/chat/completions")
(stream t)
(models gptel--gh-models))
Expand Down Expand Up @@ -395,7 +398,10 @@ for."
:stream stream
:request-params request-params
:curl-args curl-args
:url (concat protocol "://" host endpoint)
:url (lambda ()
(pcase-let (((cl-struct gptel-backend protocol host endpoint)
gptel-backend))
(concat protocol "://" host endpoint)))
:machineid (gptel--gh-machine-id))))
(setf (alist-get name gptel--known-backends nil nil #'equal) backend)
backend))
Expand Down
8 changes: 4 additions & 4 deletions gptel-request.el
Original file line number Diff line number Diff line change
Expand Up @@ -2524,15 +2524,15 @@ INFO contains the request data, TOKEN is a unique identifier."
(gptel-backend (plist-get info :backend))
(gptel-model (plist-get info :model))
(gptel-stream (plist-get info :stream))
(url (let ((backend-url (gptel-backend-url gptel-backend)))
(if (functionp backend-url)
(funcall backend-url) backend-url)))
(data-json (decode-coding-string (gptel--json-encode data) 'utf-8 t))
(headers
(append '(("Content-Type" . "application/json"))
(when-let* ((header (gptel-backend-header gptel-backend)))
(if (functionp header)
(funcall header) header)))))
(url (let ((backend-url (gptel-backend-url gptel-backend)))
(if (functionp backend-url)
(funcall backend-url) backend-url)))
(data-json (decode-coding-string (gptel--json-encode data) 'utf-8 t))
(when gptel-log-level
(when (eq gptel-log-level 'debug)
(gptel--log (gptel--json-encode
Expand Down