| 1 | package Langertha::Holmgang::Runner; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: The model loop of one case over a Langertha engine: turns, turn limit, tokens per turn, lint mock runs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 36 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 36 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 36 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 36 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 36 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 36 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 36 | ▶ | use Langertha::Engine::Virtual; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 36 | ▶ | use Langertha::Holmgang::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 36 | ▶ | use Langertha::Holmgang::Grader; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 36 | ▶ | use Langertha::Holmgang::Target; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 36 | ▶ | use Langertha::Virtual::Rules qw( answer tool ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 36 | ▶ | use Moose::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 36 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 36 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 36 | our $VERSION = '0.002'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 36 | my $JSON = JSON::MaybeXS->new( utf8 => 0, canonical => 1, allow_nonref => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 36 | has target => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | isa => 'Langertha::Holmgang::Target', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | predicate => 'has_target', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 36 | has grader => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | builder => '_build_grader', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 36 | has sandbox => ( is => 'ro', predicate => 'has_sandbox' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 228 | ▶ | sub _build_grader { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_grader: called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_grader: not called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return Langertha::Holmgang::Grader->new unless $self->has_sandbox && $self->sandbox; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$self->has_sandbox and $self->sandbox
$self->has_sandbox and $self->sandbox
MC/DC50%1/2
$self->has_sandbox and $self->sandbox
$self->has_sandbox
$self->sandbox
MC/DC0%0/2
$self->has_sandbox and $self->sandbox
$self->has_sandbox
$self->sandbox
Truth table66%2/3
A and B
A= $self->has_sandboxB= $self->sandbox
Truth table0%0/3
A and B
A= $self->has_sandboxB= $self->sandbox
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | require Langertha::Holmgang::Simulators; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return Langertha::Holmgang::Grader->new( simulators => Langertha::Holmgang::Simulators->new( sandbox => $self->sandbox ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2005 | ▶ | sub _ms { int( 1000 * $_[0] + 0.5 ) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ms: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # a deep copy as plain data (wire bodies may carry JSON booleans and shared refs) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3667 | ▶ | sub _plain { $JSON->decode( $JSON->encode( $_[0] ) ) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_plain: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1163 | ▶ | async sub run_case_f { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_case_f: called CC=42 SCAR=37.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1163 | my ( $self, $case, %o ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1163 | ▶ | croak __PACKAGE__.'->run_case needs a target' unless $self->has_target; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1163 | my $target = $self->target; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1163 | my $engine = $target->engine; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1163 | ▶ | croak __PACKAGE__.': the engine '.ref($engine).' has no format_tool_results (Langertha::Role::Tools)' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | unless $engine->can('format_tool_results'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # Langertha prepends an engine's own system_prompt as a second system message (k37) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1163 | ▶ | croak __PACKAGE__.': the engine '.ref($engine).' has a system_prompt of its own; the case\'s system prompt is the only one' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$engine->can("system_prompt") and defined $engine->system_prompt
MC/DC50%1/2
$engine->can("system_prompt") and defined $engine->system_prompt
$engine->can("system_prompt")
defined $engine->system_prompt
Truth table66%2/3
A and B
A= $engine->can("system_prompt")B= defined $engine->system_prompt
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | if $engine->can('system_prompt') && defined $engine->system_prompt; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1162 | ▶ | my $world = $self->grader->world_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$case->observe // []
MC/DC100%1/1
$case->observe // []
$case->observe
Truth table100%2/2
A
A= $case->observe
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | state => $case->initial_state, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | tools => $case->tools, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | observe => $case->observe // [], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | simulators => $self->grader->simulators, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1162 | my $offer = $world->offer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1162 | my $system = $case->effective('system'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | my @conversation = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ( defined $system && length $system ? ( { role => 'system', content => $system } ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1162 | ▶ | @{ _plain( $case->prompt_messages ) }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $system and length $system
MC/DC50%1/2
defined $system and length $system
defined $system
length $system
Truth table66%2/3
A and B
A= defined $systemB= length $system
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1162 | my %controls = ( max_tokens => $case->effective('max_tokens') ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1162 | ▶ | $controls{temperature} = $case->effective('temperature') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $engine->can("supports") or $engine->supports("temperature")
MC/DC50%1/2
not $engine->can("supports") or $engine->supports("temperature")
not $engine->can("supports")
$engine->supports("temperature")
Truth table66%2/3
not(A) or B
A= not $engine->can("supports")B= $engine->supports("temperature")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | if !$engine->can('supports') || $engine->supports('temperature'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1162 | ▶ | $controls{seed} = 0 + $o{seed} if defined $o{seed}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1162 | ▶ | $controls{tools} = $offer if @$offer; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1162 | my $max_turns = $case->effective('max_turns'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1162 | my ( @turns, @calls, $error, $error_class, $turn_limit, $answer ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # the vision pre-check found the target blind (k27): no request for a case with images | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1162 | ▶ | if ( $case->has_images && defined $o{no_vision} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$case->has_images and defined $o{"no_vision"}
MC/DC100%2/2
$case->has_images and defined $o{"no_vision"}
$case->has_images
defined $o{"no_vision"}
Truth table100%3/3
A and B
A= $case->has_imagesB= defined $o{"no_vision"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ( $error, $error_class ) = ( $o{no_vision}, 'no_vision' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1162 | ▶ | while ( !defined $error_class ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2010 | ▶ | if ( @turns >= $max_turns ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | $turn_limit = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2006 | my $t0 = Time::HiRes::time(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2006 | my $turn = await $target->chat_turn_f( messages => $self->_wire_messages( $case, \@conversation ), %controls ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2005 | my $ms = _ms( Time::HiRes::time() - $t0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2005 | my $response = $turn->{response}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 2005 | ▶ | my $usage = $response && $response->has_usage ? $response->usage : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$response and $response->has_usage
MC/DC100%2/2
$response and $response->has_usage
$response
$response->has_usage
Truth table100%3/3
A and B
A= $responseB= $response->has_usage
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2005 | ▶ | my @tc = $response && $response->has_tool_calls ? @{ $response->tool_calls } : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$response and $response->has_tool_calls
MC/DC100%2/2
$response and $response->has_tool_calls
$response
$response->has_tool_calls
Truth table100%3/3
A and B
A= $responseB= $response->has_tool_calls
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2005 | ▶ | push @turns, { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | input_tokens => $usage ? $usage->input_tokens : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | output_tokens => $usage ? $usage->output_tokens : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | reasoning_tokens => $usage ? $usage->reasoning_tokens : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | duration_ms => $ms, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | finish_reason => $response ? $response->finish_reason : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | calls => scalar @tc, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 2005 | ▶ | if ( defined $turn->{error_class} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 28 | ( $error, $error_class ) = @{$turn}{qw( error error_class )}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 28 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1977 | ▶ | unless ( @tc ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # without a tool call the case is over; the text is never graded | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1123 | ▶ | $answer = $response->content // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$response->content // ""
MC/DC0%0/1
$response->content // ""
$response->content
Truth table50%1/2
A
A= $response->content
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1123 | push @conversation, { role => 'assistant', content => $answer }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1123 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 854 | my @results; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 854 | for my $tc ( @tc ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 855 | my ( $out, $args, $ok, $gap ) = $world->call( $tc->name, $self->_call_arguments($tc) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 855 | ▶ | my @real = $self->has_sandbox && $self->sandbox && $self->sandbox->can('take_log') ? $self->sandbox->take_log : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->has_sandbox and $self->sandbox and $self->sandbox->can("take_log")
$self->has_sandbox and $self->sandbox
MC/DC33%1/3
$self->has_sandbox and $self->sandbox and $self->sandbox->can("take_log")
$self->has_sandbox
$self->sandbox
$self->sandbox->can("take_log")
Truth table50%2/4
A and B and C
A= $self->has_sandboxB= $self->sandboxC= $self->sandbox->can("take_log")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 855 | ▶ | push @calls, { tool => $tc->name, args => _plain($args), succeeded => $ok ? 1 : 0, sim_gap => $gap, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ( @real ? ( sandbox => scalar @real ) : () ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 855 | ▶ | push @results, { tool_call => $tc, result => { content => [ { type => 'text', text => $out // '' } ] } }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$out // ""
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 854 | push @conversation, @{ _plain( [ $engine->format_tool_results( $response->raw, \@results ) ] ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1157 | ▶ | my $g = $self->grader->grade( $case, { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | state => $world->state, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | calls => \@calls, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ( defined $error ? ( error => $error, error_class => $error_class ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ( $turn_limit ? ( turn_limit => 1 ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # programs a rule of the grader ran for real belong to no call | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1157 | ▶ | $self->sandbox->take_log if $self->has_sandbox && $self->sandbox && $self->sandbox->can('take_log'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->has_sandbox and $self->sandbox and $self->sandbox->can("take_log")
$self->has_sandbox and $self->sandbox
MC/DC33%1/3
$self->has_sandbox and $self->sandbox and $self->sandbox->can("take_log")
$self->has_sandbox
$self->sandbox
$self->sandbox->can("take_log")
Truth table50%2/4
A and B and C
A= $self->has_sandboxB= $self->sandboxC= $self->sandbox->can("take_log")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | case_id => $case->id, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | repetition => $o{repetition} // 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | seed => defined $o{seed} ? 0 + $o{seed} : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 9256 | ( map { $_ => $g->{$_} } qw( status score error rules diff sim_gaps forbidden_calls injection_held ) ), | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | turns => \@turns, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | calls => \@calls, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1157 | ▶ | transcript => [ grep { ( $_->{role} // '' ) ne 'system' } @conversation ], | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$o{"repetition"} // 1
$$_{"role"} // ""
MC/DC100%1/1
$o{"repetition"} // 1
$o{"repetition"}
MC/DC0%0/1
$$_{"role"} // ""
$$_{"role"}
Truth table100%2/2
A
A= $o{"repetition"}
Truth table50%1/2
A
A= $$_{"role"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | answer => $answer, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | state => $world->state, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 36 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # the conversation as it goes out: each image placeholder { image, sha256, bytes } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # of a message becomes the case's Langertha::Content::Image, which the engine | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # turns into its own image part; the conversation itself keeps the placeholder | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2006 | ▶ | sub _wire_messages { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wire_messages: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2006 | my ( $self, $case, $conversation ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | return [ map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2006 | my $m = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 5148 | ▶ | my $images = ref $m->{content} eq 'ARRAY' && grep { ref $_ eq 'HASH' && exists $_->{image} } @{ $m->{content} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
ref $$m{'content'} eq 'ARRAY' && grep({ref $_ eq 'HASH' and exists $$_{'image'};} @{$$m{'content'};})
ref $_ eq 'HASH' && exists $$_{'image'}
MC/DC50%1/2
ref $$m{'content'} eq 'ARRAY' && grep({ref $_ eq 'HASH' and exists $$_{'image'};} @{$$m{'content'};})
ref $$m{'content'} eq 'ARRAY'
grep({ref $_ eq 'HASH' and exists $$_{'image'};} @{$$m{'content'};})
MC/DC50%1/2
ref $_ eq 'HASH' && exists $$_{'image'}
ref $_ eq 'HASH'
exists $$_{'image'}
Truth table66%2/3
A && B
A= ref $$m{'content'} eq 'ARRAY'B= grep({ref $_ eq 'HASH' and exists $$_{'image'};} @{$$m{'content'};})
Truth table66%2/3
A && B
A= ref $_ eq 'HASH'B= exists $$_{'image'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | $images | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 5148 | ▶ | ? +{ %$m, content => [ map { ref $_ eq 'HASH' && exists $_->{image} ? $case->image_content( $_->{image} ) : $_ } @{ $m->{content} } ] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
ref $_ eq "HASH" and exists $$_{"image"}
MC/DC50%1/2
ref $_ eq "HASH" and exists $$_{"image"}
ref $_ eq "HASH"
exists $$_{"image"}
Truth table66%2/3
A and B
A= ref $_ eq "HASH"B= exists $$_{"image"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | : $m; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } @$conversation ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1004 | ▶ | sub run_case { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_case: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1004 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1004 | return $self->run_case_f(@args)->get; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # what the world gets for a call: the decoded hash; for arguments that did not | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # decode (Langertha keeps no raw text, only {} and the flag) a text that is no | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # JSON object, so the world answers with its own refusal, as cai-platform's did | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # for the model's raw string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 855 | ▶ | sub _call_arguments { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_call_arguments: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 855 | my ( $self, $tc ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 855 | ▶ | return $tc->arguments_undecodable ? '{' : $tc->arguments; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | #### Lint's mock runs | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1097 | ▶ | sub mock_engine { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mock_engine: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1097 | my ( $class, $case, $mode ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1097 | ▶ | $mode //= 'solution'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$mode //= "solution"
MC/DC100%1/1
$mode //= "solution"
$mode
Truth table100%2/2
A
A= $mode
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1097 | ▶ | croak __PACKAGE__.'->mock_engine: mode is solution or text' unless $mode eq 'solution' || $mode eq 'text'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$mode eq "solution" or $mode eq "text"
MC/DC100%2/2
$mode eq "solution" or $mode eq "text"
$mode eq "solution"
$mode eq "text"
Truth table100%3/3
A or B
A= $mode eq "solution"B= $mode eq "text"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | my @script = $mode eq 'solution' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1096 | ▶ | ? ( ( map { tool( $_->{tool} => _plain( $_->{args} // {} ) ) } @{ $case->solution || [] } ), answer('Done.') ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$$_{"args"} // {}
$case->solution || []
MC/DC0%0/1
$$_{"args"} // {}
$$_{"args"}
MC/DC0%0/1
$case->solution || []
$case->solution
Truth table50%1/2
A
A= $$_{"args"}
Truth table50%1/2
A
A= $case->solution
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | : ( answer('I would do it like this ... (text only)') ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # the mock sees what it is sent: a case with images gets a mock that claims | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # image_input, so the vision pre-check does not stop it at the wire, and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # answers the sight test's requests once its script is done (k27) -- a case | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # ends with the script's last answer, so a case never reaches the fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1096 | my $images = $case->has_images; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1096 | ▶ | my $engine = Langertha::Engine::Virtual->new( script => \@script, ( $images ? ( fallback => answer('OK') ) : () ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1096 | ▶ | Moose::Util::apply_all_roles( $engine, 'Langertha::Role::ImageInput' ) if $images; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1096 | return $engine; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # the parts of two results that must be identical (all but wall time) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 622 | ▶ | sub _comparable { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_comparable: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 622 | my ( $r ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 622 | my %c = map { $_ => $r->{$_} } qw( status score error rules diff calls sim_gaps forbidden_calls injection_held transcript state ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 622 | $c{turns} = [ map { my %t = %$_; delete $t{duration_ms}; \%t } @{ $r->{turns} } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 622 | return $JSON->encode( \%c ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 55 | ▶ | sub lint_mock_runs { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lint_mock_runs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 55 | my ( $class ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 312 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 312 | my ( $lint, $case, $field ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 934 | ▶ | my $run = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 934 | my ( $mode ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 934 | my $runner = $class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | grader => $lint->grader, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | target => Langertha::Holmgang::Target->new( engine => $class->mock_engine( $case, $mode ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 934 | return $runner->run_case($case); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 312 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 312 | ▶ | my $refuse = sub { Langertha::Holmgang::Error->throw( $field.': '.$_[0], $_[1] ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 312 | my @replay = map { $run->('solution') } 1 .. 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | $refuse->( 'solution', 'mock run replaying the reference solution is '.$replay[0]{status} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | .( defined $replay[0]{error} ? ': '.$replay[0]{error} : '' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 312 | ▶ | unless $replay[0]{status} eq 'passed'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 311 | ▶ | $refuse->( 'solution', 'mock run replaying the reference solution gives a different result the second time' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | unless _comparable( $replay[0] ) eq _comparable( $replay[1] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 310 | my $text = $run->('text'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 310 | ▶ | if ( $case->no_tool ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | $refuse->( 'solution', 'mock run answering text only is '.$text->{status}.' -- in the "no tool" family it must pass' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | ▶ | unless $text->{status} eq 'passed'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | $refuse->( 'rules', 'mock run answering text only passes -- the rules check no change' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 307 | ▶ | if $text->{status} eq 'passed'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 309 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 55 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 36 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 36 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||