| 1 | package Langertha::Cost; | ||
| 2 | # ABSTRACT: Immutable value object for the monetary cost of a single LLM call | ||
| 3 | 10 | our $VERSION = '0.505'; | |
| 4 | 10 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 10 | has input_usd => ( is => 'ro', isa => 'Num', default => 0 ); | |
| 7 | 10 | has output_usd => ( is => 'ro', isa => 'Num', default => 0 ); | |
| 8 | 10 | has cache_read_usd => ( is => 'ro', isa => 'Num', default => 0 ); | |
| 9 | 10 | has cache_write_usd => ( is => 'ro', isa => 'Num', default => 0 ); | |
| 10 | 10 | has total_usd => ( is => 'ro', isa => 'Num', lazy => 1, builder => '_build_total_usd' ); | |
| 11 | 10 | has currency => ( is => 'ro', isa => 'Str', default => 'USD' ); | |
| 12 | |||
| 13 | 43 | ▶ | sub _build_total_usd { |
|
Subroutine
_build_total_usd: called CC=1 SCAR=0.0
| |||
| 14 | 43 | my ($self) = @_; | |
| 15 | 43 | return $self->input_usd + $self->output_usd + $self->cache_read_usd + $self->cache_write_usd; | |
| 16 | } | ||
| 17 | |||
| 18 | 4 | ▶ | sub to_hash { |
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
documented
| |||
| 19 | 4 | my ($self) = @_; | |
| 20 | return { | ||
| 21 | 4 | input_cost_usd => $self->input_usd + 0, | |
| 22 | output_cost_usd => $self->output_usd + 0, | ||
| 23 | cache_read_cost_usd => $self->cache_read_usd + 0, | ||
| 24 | cache_write_cost_usd => $self->cache_write_usd + 0, | ||
| 25 | total_cost_usd => $self->total_usd + 0, | ||
| 26 | currency => $self->currency, | ||
| 27 | }; | ||
| 28 | } | ||
| 29 | |||
| 30 | # Make the object transparent to any JSON encoder configured with | ||
| 31 | # convert_blessed => 1 (the house default, see Langertha::Plugin::Langfuse). | ||
| 32 | # to_hash is the complete canonical representation, so this is a plain | ||
| 33 | # delegator — nothing is dropped. | ||
| 34 | 1 | ▶ | sub TO_JSON { shift->to_hash } |
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 35 | |||
| 36 | |||
| 37 | 10 | __PACKAGE__->meta->make_immutable; | |
| 38 | 10 | 1; | |
| 39 | |||
| 40 | __END__ | ||