Skip to content

Conversation

@pragmatrix
Copy link
Owner

No description provided.

@pragmatrix pragmatrix requested a review from Copilot May 22, 2025 07:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds billing record support to the OpenAI dialog service by tracking token usage, introducing a scope field, and emitting structured billing events.

  • Propagates an optional scope through ServerEvent::BillingRecords and ConversationOutput::billing_records.
  • Defines helper methods on BillingRecord (count, duration, is_zero) and emits records based on usage in real-time server events.
  • Updates example client logging, bumps the openai-api-rs submodule, and extends the Duration wrapper.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/protocol.rs Added scope: Option<String> to ServerEvent::BillingRecords.
src/context_switch.rs Propagated scope in output_to_server_event.
services/openai-dialog/src/lib.rs Extended client API with billing_scope, real-time event handling, and billing emission logic.
external/openai-api-rs Updated submodule commit to pick up billing changes.
examples/openai-dialog.rs Logged billing records with their scope in the example.
core/src/protocol.rs Implemented BillingRecord helpers (count, duration, is_zero).
core/src/duration.rs Added Deref derive for Duration wrapper.
core/src/conversation.rs Added billing_records method to ConversationOutput and updated the Output enum.
Comments suppressed due to low confidence (5)

services/openai-dialog/src/lib.rs:409

  • [nitpick] Using str as a variable name shadows the primitive type; consider renaming it (e.g., payload or raw) to improve clarity.
Message::Text(str) => { 

core/src/protocol.rs:84

  • Add unit tests for BillingRecord::is_zero to verify both the Count and Duration variants behave as expected.
pub fn is_zero(&self) -> bool { 

core/src/conversation.rs:129

  • Consider adding tests for ConversationOutput::billing_records to ensure zero-value records are correctly filtered out before posting.
records.retain(|r| !r.is_zero()); 

core/src/duration.rs:9

  • The import path for derive_more macros appears incorrect; these macros are usually imported from the crate root (e.g., use derive_more::{Deref, From, Into};).
use derive_more::derive::{Deref, From, Into}; 

services/openai-dialog/src/lib.rs:91

  • This extra &params.model argument may not align with the expected signature of the Service::run method—please verify the method signature and adjust the argument or its position accordingly.
&params.model, 
@pragmatrix pragmatrix marked this pull request as ready for review May 22, 2025 07:21
@pragmatrix pragmatrix merged commit dc5df76 into master May 22, 2025
6 checks passed
@pragmatrix pragmatrix deleted the billing-events branch May 22, 2025 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants