Skip to content

Allow the maximum number of thinking tokens to be allowed for Claude #368

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

Merged
merged 2 commits into from
Jun 19, 2025
Merged
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
19 changes: 13 additions & 6 deletions chatgpt-shell-anthropic.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 32000
(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 'integer
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
Expand Down Expand Up @@ -201,11 +203,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 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 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))))))
`((max_tokens . ,(or (map-elt model :max-tokens)
(error "Missing %s :max-tokens" (map-elt model :name))))
(model . ,(map-elt model :version))
Expand Down