Repository navigation
MAINT: Make the chat completions usage helper keyword-only - #4826
Snehangshu Roy (alienxviking) wants to merge 1 commit into
Conversation
_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>
There was a problem hiding this comment.
🟢 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
Nonecounts.
| 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
|
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. |
@microsoft-github-policy-service agree |
|
Roman Lutz (@romanlutz) the CLA is accepted now, so this is ready for review whenever you have time. |
Description
Make
_add_extrainpyrit.prompt_target.common.chat_completions_response_parserkeyword-only, and drop it from the keyword-only baseline.targetis still the one positional parameter.nameandvaluecome after*, and the five calls intoken_usage_from_chat_completionpass them by name.build_scripts/keyword_only_baseline.txt.0count stays inTokenUsage.extra, and a missing orNonecount is left out.python -m build_scripts.check_keyword_only_paramspasses. The helper tests intest_chat_completions_helpers.pypass (95), as do the OpenAI chat, LiteLLM and tool-call-history target tests that go through this parser (391).ruffandtyare clean on the changed files.Relates to #4216
This change was developed with AI assistance (Claude Code).
🤖 Generated with Claude Code