| 1 | package Langertha::Pricing; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Model→price catalog producing Langertha::Cost from Langertha::Usage | ||||||||||||||||||||||||||||
| 3 | 3 | our $VERSION = '0.502'; | |||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Langertha::Cost; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # Map of model id → { input_per_million => N, output_per_million => N }. | ||||||||||||||||||||||||||||
| 8 | # Both keys are USD per 1,000,000 tokens. | ||||||||||||||||||||||||||||
| 9 | has rules => ( | ||||||||||||||||||||||||||||
| 10 | is => 'ro', | ||||||||||||||||||||||||||||
| 11 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 12 | 5 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # Optional fallback rule applied when a model id is unknown. | ||||||||||||||||||||||||||||
| 16 | has default_rule => ( | ||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||
| 18 | isa => 'Maybe[HashRef]', | ||||||||||||||||||||||||||||
| 19 | 2 | ▶ | default => sub { undef }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 3 | ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub rule_for { | ||||||||||||||||||||||||||||
| 23 | 6 | ▶ | my ($self, $model) = @_; | ||||||||||||||||||||||||||
|
Subroutine
rule_for: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 6 | ▶ | return $self->rules->{$model} if defined $model && exists $self->rules->{$model}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $model and exists $self->rules->{$model}
MC/DC100%2/2
defined $model and exists $self->rules->{$model}
defined $model
exists $self->rules->{$model}
Truth table100%3/3
A and B
A= defined $modelB= exists $self->rules->{$model}
| |||||||||||||||||||||||||||||
| 25 | 5 | return $self->default_rule; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub cost_for { | ||||||||||||||||||||||||||||
| 29 | 6 | ▶ | my ($self, $usage, $model) = @_; | ||||||||||||||||||||||||||
|
Subroutine
cost_for: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 6 | ▶ | my $rule = $self->rule_for($model) || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->rule_for($model) || {}
MC/DC100%1/1
$self->rule_for($model) || {}
$self->rule_for($model)
Truth table100%2/2
A
A= $self->rule_for($model)
| |||||||||||||||||||||||||||||
| 31 | 6 | ▶ | my $ipm = 0 + ( $rule->{input_per_million} // 0 ); | ||||||||||||||||||||||||||
|
Condition100%2/2
$$rule{"input_per_million"} // 0
MC/DC100%1/1
$$rule{"input_per_million"} // 0
$$rule{"input_per_million"}
Truth table100%2/2
A
A= $$rule{"input_per_million"}
| |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | my $opm = 0 + ( $rule->{output_per_million} // 0 ); | ||||||||||||||||||||||||||
|
Condition100%2/2
$$rule{"output_per_million"} // 0
MC/DC100%1/1
$$rule{"output_per_million"} // 0
$$rule{"output_per_million"}
Truth table100%2/2
A
A= $$rule{"output_per_million"}
| |||||||||||||||||||||||||||||
| 33 | 6 | my $input_usd = ( $usage->input_tokens / 1_000_000 ) * $ipm; | |||||||||||||||||||||||||||
| 34 | 6 | my $output_usd = ( $usage->output_tokens / 1_000_000 ) * $opm; | |||||||||||||||||||||||||||
| 35 | 6 | return Langertha::Cost->new( | |||||||||||||||||||||||||||
| 36 | input_usd => $input_usd, | ||||||||||||||||||||||||||||
| 37 | output_usd => $output_usd, | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 42 | 3 | 1; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | __END__ | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =pod | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 NAME | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Langertha::Pricing - Model→price catalog producing Langertha::Cost from Langertha::Usage | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head1 VERSION | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | version 0.502 | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head2 Issues | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||
| 63 | L<https://github.com/Getty/langertha/issues>. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head2 IRC | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 82 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||||||||||