feat(python-sdk): budget_check() + BudgetResult model — GOV-38#5
Closed
Shaivpidadi wants to merge 1 commit intomainfrom
Closed
feat(python-sdk): budget_check() + BudgetResult model — GOV-38#5Shaivpidadi wants to merge 1 commit intomainfrom
Shaivpidadi wants to merge 1 commit intomainfrom
Conversation
- Add BudgetResult model with allowed, remaining_tokens, limit, warning_threshold_hit (auto-set when < 10% budget remains) - Add budget_check(org_id, user_id, estimated_tokens) and async variant on GovernsAIClient - Add async_record_usage() alias - Fix missing Optional/Dict/Any imports in exceptions/precheck.py - 12 unit tests covering allowed/denied/warning/async variants Refs: GOV-38
Member
Author
|
Closing: duplicate of PR #7 which implements both record_usage() and budget_check() with a superset of this work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BudgetResultmodel withallowed,remaining_tokens,limit,warning_threshold_hit(auto-computed True when < 10% budget remains)budget_check(org_id, user_id, estimated_tokens) → BudgetResultonGovernsAIClientplusasync_budget_checkaliasasync_record_usagealias forrecord_usageOptional/Dict/Anyimports inexceptions/precheck.pyGovernsAI issue
GOV-38
Test plan
BudgetResult.from_dict— allowed=True, no warningBudgetResult.from_dict— allowed=False when budget exceededBudgetResult.from_dict—warning_threshold_hit=Truewhen remaining < 10%BudgetResult.from_dict— warning_threshold_hit=False at exactly 10%BudgetResult.from_dict— camelCase keys normalisedbudget_check()— correct params sent to/api/v1/budget/contextbudget_check()— returns denied result with reasonbudget_check()— warning threshold propagatedasync_budget_check— is aliasrecord_usage()— UsageRecord passed throughrecord_usage()— dict converted to UsageRecordasync_record_usage— is alias