Skip to content

Commit 0737508

Browse files
akssrikarthink
authored andcommitted
gptel-bedrock: add bearer-token argument to backend
1 parent 61d09c8 commit 0737508

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

README.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ Register a backend with
11141114
#+end_src
11151115

11161116
AWS has numerous credential provisions; we follow this order precedence,
1117+
- (argument) ~:aws-bearer-token~
11171118
- (env. variable) ~AWS_BEARER_TOKEN_BEDROCK~
11181119
- (argument) ~:aws-profile~
11191120
If this option is specified, the Bedrock-backend uses the shared AWS config and credentials files to obtain credentials based on the AWS Profile selected. If ~:aws-profile~ is set to the keyword ~:static~, the IAM credentials are imported without a profile argument.

gptel-bedrock.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,11 @@ REGION is one of apac, eu or us."
577577
(or (alist-get model gptel-bedrock--model-ids nil nil #'eq)
578578
(error "Unknown Bedrock model: %s" model))))
579579

580-
(defun gptel-bedrock--curl-args (region profile)
580+
(defun gptel-bedrock--curl-args (region profile bearer-token)
581581
"Generate the curl arguments to get a bedrock request signed for use in REGION.
582582
583583
PROFILE specifies the aws profile to use for aws configure export-credentials."
584-
(let ((bearer-token (getenv "AWS_BEARER_TOKEN_BEDROCK"))
584+
(let ((bearer-token (or bearer-token (getenv "AWS_BEARER_TOKEN_BEDROCK")))
585585
(output-args (unless (memq system-type '(windows-nt ms-dos))
586586
'("--output" "/dev/stdout"))))
587587
(if bearer-token
@@ -610,7 +610,7 @@ PROFILE specifies the aws profile to use for aws configure export-credentials."
610610
(models gptel--bedrock-models)
611611
(model-region nil)
612612
stream curl-args request-params
613-
(aws-profile nil)
613+
aws-profile aws-bearer-token
614614
(protocol "https"))
615615
"Register an AWS Bedrock backend for gptel with NAME.
616616
@@ -620,12 +620,13 @@ REGION - AWS region name (e.g. \"us-east-1\")
620620
MODELS - The list of models supported by this backend
621621
MODEL-REGION - one of apac, eu, us or nil
622622
AWS-PROFILE - the aws profile to use for aws configure export-credentials
623+
AWS-BEARER-TOKEN - the aws bearer-token for authenticating with AWS
623624
CURL-ARGS - additional curl args
624625
STREAM - Whether to use streaming responses or not.
625626
REQUEST-PARAMS - a plist of additional HTTP request
626627
parameters (as plist keys) and values supported by the API."
627628
(declare (indent 1))
628-
(unless (getenv "AWS_BEARER_TOKEN_BEDROCK")
629+
(unless (or aws-bearer-token (getenv "AWS_BEARER_TOKEN_BEDROCK"))
629630
(unless (and gptel-use-curl (version<= "8.9" (gptel-bedrock--curl-version)))
630631
(error "Bedrock-backend requires curl >= 8.9, but gptel-use-curl := %s, curl-version := %s"
631632
gptel-use-curl (gptel-bedrock--curl-version))))
@@ -641,7 +642,7 @@ parameters (as plist keys) and values supported by the API."
641642
:endpoint "" ; Url is dynamically constructed based on other args
642643
:stream stream
643644
:coding-system (and stream 'binary)
644-
:curl-args (lambda () (append curl-args (gptel-bedrock--curl-args region aws-profile)))
645+
:curl-args (lambda () (append curl-args (gptel-bedrock--curl-args region aws-profile aws-bearer-token)))
645646
:request-params request-params
646647
:url
647648
(lambda ()

0 commit comments

Comments
 (0)