Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ impl Task for TokenUsageTask {
fn apply(self: Box<Self>, ctx: &mut ReqRespCtx) -> TaskOutcome {

@adam-cattermole adam-cattermole Jul 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's worth noting this task is legacy and (very) soon to be removed in favour of the StoreTask

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nice! yup, I reckon this would be just for a PoC I'm working on... Do you reckon that the resulting config from a TokenRateLimit Policy will change the configuration that will result building the Pipeline with the StoreTask or would it be the same?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, so all the bits will be extracted from the responseBodyJson vars and added to a StoreTask. So any task leveraging them will wait Pending until the StoreTask resolves for them

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See #412

let mut task: TokenUsageTask = self.into();

// Exit if fields already in context response body.
if task
.expected_response_fields
.iter()
.all(|field| ctx.response_body.get_value(field).is_some())
{
return TaskOutcome::Done;
}

// No stored field info found, proceed with response body extraction
let mut strategy = match task.strategy.take() {
Some(s) => s,
None => {
Expand Down Expand Up @@ -219,7 +229,9 @@ mod tests {
let mut ctx = ReqRespCtx::new(Arc::new(mock_backend));
ctx.response_body.set_buffer_size(0, false);

let task = Box::new(TokenUsageTask::new());
let task = Box::new(TokenUsageTask::with_expected_response_fields(vec![
"/usage/total_tokens".to_string(),
]));

let outcome = task.apply(&mut ctx);
assert!(matches!(outcome, TaskOutcome::Requeued(_)));
Expand Down
Loading