| 1 | package Langertha::Input::Tools; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | our $VERSION = '0.505'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Backwards-compat facade over Langertha::Tool / Langertha::ToolChoice | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Langertha::Tool; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Langertha::ToolChoice; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | Carp::carp( | |||||||||||||||||||||||||||||||||||||||||
| 12 | "Langertha::Input::Tools is a backwards-compatibility facade. New code should use " | ||||||||||||||||||||||||||||||||||||||||||
| 13 | . "Langertha::Tool / Langertha::ToolChoice directly." | ||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | # All methods here are kept for backwards compatibility with Skeid/Knarr | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # and other existing consumers. New code should use Langertha::Tool and | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # Langertha::ToolChoice directly. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub normalize_tools { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_tools: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my ($class, $tools) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | return [ map { $_->to_hash } @{ Langertha::Tool->from_list($tools) } ]; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | sub to_openai_tools { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_openai_tools: called CC=7 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my ($class, $canonical_tools) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | for my $hash ( @{ $canonical_tools || [] } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$canonical_tools || []
MC/DC0%0/1
$canonical_tools || []
$canonical_tools
Truth table50%1/2
A
A= $canonical_tools
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | next unless ref($hash) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | my $name = $hash->{name} // 'tool'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$hash{"name"} // "tool"
MC/DC0%0/1
$$hash{"name"} // "tool"
$$hash{"name"}
Truth table50%1/2
A
A= $$hash{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | push @out, Langertha::Tool->new( | ||||||||||||||||||||||||||||||||||||||||||
| 32 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | description => ( $hash->{description} // '' ), | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | input_schema => ( $hash->{input_schema} || { type => 'object', properties => {} } ), | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$$hash{"description"} // ""
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
MC/DC0%0/1
$$hash{"description"} // ""
$$hash{"description"}
MC/DC0%0/1
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
$$hash{'input_schema'}
Truth table50%1/2
A
A= $$hash{"description"}
Truth table50%1/2
A
A= $$hash{'input_schema'}
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | )->to_openai; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | return \@out; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | sub to_anthropic_tools { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_anthropic_tools: called CC=7 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | my ($class, $canonical_tools) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | for my $hash ( @{ $canonical_tools || [] } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$canonical_tools || []
MC/DC0%0/1
$canonical_tools || []
$canonical_tools
Truth table50%1/2
A
A= $canonical_tools
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | ▶ | next unless ref($hash) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | my $name = $hash->{name} // 'tool'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$hash{"name"} // "tool"
MC/DC0%0/1
$$hash{"name"} // "tool"
$$hash{"name"}
Truth table50%1/2
A
A= $$hash{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | push @out, Langertha::Tool->new( | ||||||||||||||||||||||||||||||||||||||||||
| 47 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | description => ( $hash->{description} // '' ), | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | input_schema => ( $hash->{input_schema} || { type => 'object', properties => {} } ), | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$$hash{"description"} // ""
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
MC/DC0%0/1
$$hash{"description"} // ""
$$hash{"description"}
MC/DC0%0/1
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
$$hash{'input_schema'}
Truth table50%1/2
A
A= $$hash{"description"}
Truth table50%1/2
A
A= $$hash{'input_schema'}
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | )->to_anthropic; | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | return \@out; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | ▶ | sub normalize_tool_choice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_tool_choice: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | my ($class, $tool_choice) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | my $tc = Langertha::ToolChoice->from_hash($tool_choice); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | return $tc ? $tc->to_hash : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | sub to_openai_tool_choice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_openai_tool_choice: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | my ($class, $canonical_tool_choice) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | return undef unless ref($canonical_tool_choice) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
MC/DC0%0/3
ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
ref $canonical_tool_choice eq "HASH"
builtin::blessed($canonical_tool_choice)
$canonical_tool_choice->isa("Langertha::ToolChoice")
Truth table50%2/4
A or B and C
A= ref $canonical_tool_choice eq "HASH"B= builtin::blessed($canonical_tool_choice)C= $canonical_tool_choice->isa("Langertha::ToolChoice")
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | || ( blessed($canonical_tool_choice) && $canonical_tool_choice->isa('Langertha::ToolChoice') ); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | my $tc = Langertha::ToolChoice->from_hash($canonical_tool_choice); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | return $tc ? $tc->to_openai : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | sub to_anthropic_tool_choice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_anthropic_tool_choice: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | my ($class, $canonical_tool_choice) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | return undef unless ref($canonical_tool_choice) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
MC/DC0%0/3
ref $canonical_tool_choice eq "HASH" or builtin::blessed($canonical_tool_choice) and $canonical_tool_choice->isa("Langertha::ToolChoice")
ref $canonical_tool_choice eq "HASH"
builtin::blessed($canonical_tool_choice)
$canonical_tool_choice->isa("Langertha::ToolChoice")
Truth table50%2/4
A or B and C
A= ref $canonical_tool_choice eq "HASH"B= builtin::blessed($canonical_tool_choice)C= $canonical_tool_choice->isa("Langertha::ToolChoice")
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | || ( blessed($canonical_tool_choice) && $canonical_tool_choice->isa('Langertha::ToolChoice') ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | my $tc = Langertha::ToolChoice->from_hash($canonical_tool_choice); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | return $tc ? $tc->to_anthropic : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||||||||||||