From 21549a8d6bceddf579457bb9f5a964f66deb475c Mon Sep 17 00:00:00 2001 From: "David J. Rosenbaum" Date: Thu, 12 Jun 2025 19:55:21 -0700 Subject: [PATCH 1/2] Allow the maximum number of thinking tokens to be allowed for Claude By default chatgpt-shell-anthropic-thinking-budget-tokens is 32000. This exceeds the maximum number of tokens for some models (e.g. Opus 4) and is a pain since the maximum number of tokens differs across different anthropic models. This PR allows a value of 'max which uses as many thinking tokens as possible. --- chatgpt-shell-anthropic.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/chatgpt-shell-anthropic.el b/chatgpt-shell-anthropic.el index f8b9d74..131c982 100644 --- a/chatgpt-shell-anthropic.el +++ b/chatgpt-shell-anthropic.el @@ -54,11 +54,11 @@ If you use Claude through a proxy service, change the URL base." :type 'boolean :group 'chatgpt-shell) -(defcustom chatgpt-shell-anthropic-thinking-budget-tokens 32000 +(defcustom chatgpt-shell-anthropic-thinking-budget-tokens 'max "The token budget allocated for Anthropic model thinking. Needs `chatgpt-shell-anthropic-thinking-budget-tokens' set to non-nil." - :type 'integer + :type '(choice integer (const max)) :group 'chatgpt-shell) (cl-defun chatgpt-shell-anthropic--make-model (&key version @@ -201,11 +201,16 @@ or (when (map-elt settings :system-prompt) `((system . ,(map-elt settings :system-prompt)))) (when chatgpt-shell-anthropic-thinking - (when (>= chatgpt-shell-anthropic-thinking-budget-tokens (map-elt model :max-tokens)) + (when (and (integerp chatgpt-shell-anthropic-thinking-budget-tokens) + (>= chatgpt-shell-anthropic-thinking-budget-tokens (map-elt model :max-tokens))) (error "chatgpt-shell-anthropic-thinking-budget-tokens must be smaller than %d" (map-elt model :max-tokens))) - `((thinking . ((type . "enabled") - (budget_tokens . ,chatgpt-shell-anthropic-thinking-budget-tokens))))) + (let ((chatgpt-shell-anthropic-thinking-budget-tokens + (if (eq chatgpt-shell-anthropic-thinking-budget-tokens 'max) + (1- (map-elt model :max-tokens)) + chatgpt-shell-anthropic-thinking-budget-tokens))) + `((thinking . ((type . "enabled") + (budget_tokens . ,chatgpt-shell-anthropic-thinking-budget-tokens)))))) `((max_tokens . ,(or (map-elt model :max-tokens) (error "Missing %s :max-tokens" (map-elt model :name)))) (model . ,(map-elt model :version)) From bd516eb893ab61b089b873a4dc0661c08182e4e7 Mon Sep 17 00:00:00 2001 From: "David J. Rosenbaum" Date: Wed, 18 Jun 2025 14:24:43 -0700 Subject: [PATCH 2/2] Use nil instead of 'max for the maximum number of thinking tokens --- chatgpt-shell-anthropic.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/chatgpt-shell-anthropic.el b/chatgpt-shell-anthropic.el index 131c982..53d38c7 100644 --- a/chatgpt-shell-anthropic.el +++ b/chatgpt-shell-anthropic.el @@ -54,11 +54,13 @@ If you use Claude through a proxy service, change the URL base." :type 'boolean :group 'chatgpt-shell) -(defcustom chatgpt-shell-anthropic-thinking-budget-tokens 'max +(defcustom chatgpt-shell-anthropic-thinking-budget-tokens nil "The token budget allocated for Anthropic model thinking. -Needs `chatgpt-shell-anthropic-thinking-budget-tokens' set to non-nil." - :type '(choice integer (const max)) +Needs `chatgpt-shell-anthropic-thinking-budget-tokens' set to +non-nil. nil means to use the maximum number of thinking tokens +allowed." + :type '(choice integer (const nil)) :group 'chatgpt-shell) (cl-defun chatgpt-shell-anthropic--make-model (&key version @@ -201,16 +203,16 @@ or (when (map-elt settings :system-prompt) `((system . ,(map-elt settings :system-prompt)))) (when chatgpt-shell-anthropic-thinking - (when (and (integerp chatgpt-shell-anthropic-thinking-budget-tokens) + (when (and chatgpt-shell-anthropic-thinking-budget-tokens (>= chatgpt-shell-anthropic-thinking-budget-tokens (map-elt model :max-tokens))) (error "chatgpt-shell-anthropic-thinking-budget-tokens must be smaller than %d" (map-elt model :max-tokens))) (let ((chatgpt-shell-anthropic-thinking-budget-tokens - (if (eq chatgpt-shell-anthropic-thinking-budget-tokens 'max) - (1- (map-elt model :max-tokens)) - chatgpt-shell-anthropic-thinking-budget-tokens))) + (if chatgpt-shell-anthropic-thinking-budget-tokens + chatgpt-shell-anthropic-thinking-budget-tokens + (1- (map-elt model :max-tokens))))) `((thinking . ((type . "enabled") - (budget_tokens . ,chatgpt-shell-anthropic-thinking-budget-tokens)))))) + (budget_tokens . ,chatgpt-shell-anthropic-thinking-budget-tokens)))))) `((max_tokens . ,(or (map-elt model :max-tokens) (error "Missing %s :max-tokens" (map-elt model :name)))) (model . ,(map-elt model :version))