refactor: extract GrpcUsage::into_api_usage to DRY up h2_handler
This commit is contained in:
@@ -72,6 +72,29 @@ pub struct GrpcUsage {
|
||||
pub response_id: Option<String>,
|
||||
}
|
||||
|
||||
impl GrpcUsage {
|
||||
/// Convert to a full `ApiUsage` record, attaching the gRPC method path.
|
||||
pub fn into_api_usage(self, grpc_method: String) -> super::store::ApiUsage {
|
||||
super::store::ApiUsage {
|
||||
input_tokens: self.input_tokens,
|
||||
output_tokens: self.output_tokens,
|
||||
thinking_output_tokens: self.thinking_output_tokens,
|
||||
response_output_tokens: self.response_output_tokens,
|
||||
cache_creation_input_tokens: self.cache_write_tokens,
|
||||
cache_read_input_tokens: self.cache_read_tokens,
|
||||
model: self.model,
|
||||
api_provider: self.api_provider,
|
||||
grpc_method: Some(grpc_method),
|
||||
stop_reason: None,
|
||||
total_cost_usd: None,
|
||||
captured_at: std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract gRPC message frames from a buffer.
|
||||
///
|
||||
/// A gRPC message is:
|
||||
|
||||
Reference in New Issue
Block a user