mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
persisting credits if new snapshot does not contain credit info (#7490)
in response to incoming changes to responses headers where the header may sometimes not contain credits info (no longer forcing a credit check)
This commit is contained in:
committed by
GitHub
Unverified
parent
f6a7da4ac3
commit
5ebdc9af1b
@@ -62,7 +62,10 @@ impl SessionState {
|
||||
}
|
||||
|
||||
pub(crate) fn set_rate_limits(&mut self, snapshot: RateLimitSnapshot) {
|
||||
self.latest_rate_limits = Some(snapshot);
|
||||
self.latest_rate_limits = Some(merge_rate_limit_credits(
|
||||
self.latest_rate_limits.as_ref(),
|
||||
snapshot,
|
||||
));
|
||||
}
|
||||
|
||||
pub(crate) fn token_info_and_rate_limits(
|
||||
@@ -79,3 +82,14 @@ impl SessionState {
|
||||
self.history.get_total_token_usage()
|
||||
}
|
||||
}
|
||||
|
||||
// Sometimes new snapshots don't include credits
|
||||
fn merge_rate_limit_credits(
|
||||
previous: Option<&RateLimitSnapshot>,
|
||||
mut snapshot: RateLimitSnapshot,
|
||||
) -> RateLimitSnapshot {
|
||||
if snapshot.credits.is_none() {
|
||||
snapshot.credits = previous.and_then(|prior| prior.credits.clone());
|
||||
}
|
||||
snapshot
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user