Skip to content

MAINT: Make the chat completions usage helper keyword-only - #4826

Open
Snehangshu Roy (alienxviking) wants to merge 1 commit into
microsoft:mainfrom
alienxviking:maint/kw-only-chat-completions-parser
Open

Snehangshu Roy (alienxviking) wants to merge 1 commit into
microsoft:mainfrom
alienxviking:maint/kw-only-chat-completions-parser

Conversation

@alienxviking

Copy link
Copy Markdown

Description

Make _add_extra in pyrit.prompt_target.common.chat_completions_response_parser keyword-only, and drop it from the keyword-only baseline.

  • target is still the one positional parameter. name and value come after *, and the five calls in token_usage_from_chat_completion pass them by name.
  • Remove the entry from build_scripts/keyword_only_baseline.txt.
  • No change in behavior. The helper is private to the module, and nothing outside this file calls it.
  • A new test pins what the helper does: a 0 count stays in TokenUsage.extra, and a missing or None count is left out.

python -m build_scripts.check_keyword_only_params passes. The helper tests in test_chat_completions_helpers.py pass (95), as do the OpenAI chat, LiteLLM and tool-call-history target tests that go through this parser (391). ruff and ty are clean on the changed files.

Relates to #4216

This change was developed with AI assistance (Claude Code).
🤖 Generated with Claude Code

_add_extra keeps target as its one positional parameter; name and
value are keyword-only, and the five calls in
token_usage_from_chat_completion pass them by name. Drop its
keyword-only baseline entry and pin that a zero count stays in
TokenUsage.extra while a missing one is left out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 23:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The keyword-only helper cleanup has no active review issues.

No open issues 🎉

What changed in this PR

Continues #4216’s private-helper cleanup by making _add_extra’s name and value parameters keyword-only without changing behavior.

Changes:

  • Updates all five callers to use named arguments.
  • Removes the helper’s keyword-only baseline entry.
  • Adds coverage for retaining zero counts and omitting missing or None counts.
File Description
tests/​unit/​prompt_target/​target/​test_chat_completions_helpers.py Tests zero and absent extra token counts.
pyrit/​prompt_target/​common/​chat_completions_response_parser.py Updates the helper signature and callers.
build_scripts/​keyword_only_baseline.txt Removes the migrated helper’s entry.

Review effort: Balanced

@romanlutz

Copy link
Copy Markdown
Contributor

Snehangshu Roy (@alienxviking) please consider accepting the CLA by replying to the policy-service bot's comment above as it describes. We can't review or merge the PR without it. I'll leave this open until 2026-12-08; if the CLA is not accepted by then I'll close the PR, and it can be reopened once it is.

@alienxviking

Copy link
Copy Markdown
Author

Snehangshu Roy (@alienxviking) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@alienxviking

Copy link
Copy Markdown
Author

Roman Lutz (@romanlutz) the CLA is accepted now, so this is ready for review whenever you have time.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants