| 1 | package Langertha::Content; | ||||||||||||||||||||
| 2 | # ABSTRACT: Base role for canonical multimodal content blocks with cross-provider serialization | ||||||||||||||||||||
| 3 | 17 | our $VERSION = '0.503'; | |||||||||||||||||||
| 4 | 17 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 17 | ▶ | use Carp qw( croak ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 17 | requires qw( to_openai to_anthropic to_gemini ); | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | # Serializers added after the role was public (karr k267) get croaking | ||||||||||||||||||||
| 11 | # defaults instead of joining `requires`, so an outside content class still | ||||||||||||||||||||
| 12 | # composes; it only fails when it is actually sent on such a wire. | ||||||||||||||||||||
| 13 | 3 | ▶ | sub _no_serializer { | ||||||||||||||||||
|
Subroutine
_no_serializer: called CC=2 SCAR=8.1
| |||||||||||||||||||||
| 14 | 3 | my ( $self, $fmt ) = @_; | |||||||||||||||||||
| 15 | 3 | ▶ | croak( ( ref $self || $self )." cannot be sent on the $fmt wire; implement to_$fmt" ); | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 16 | } | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | sub to_responses { $_[0]->_no_serializer('responses') } | ||||||||||||||||||
|
Subroutine
to_responses: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 19 | 1 | ▶ | sub to_ollama { $_[0]->_no_serializer('ollama') } | ||||||||||||||||||
|
Subroutine
to_ollama: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 20 | 1 | ▶ | sub to_lmstudio { $_[0]->_no_serializer('lmstudio') } | ||||||||||||||||||
|
Subroutine
to_lmstudio: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 17 | 1; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | __END__ | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =pod | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =encoding UTF-8 | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head1 NAME | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | Langertha::Content - Base role for canonical multimodal content blocks with cross-provider serialization | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =head1 VERSION | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | version 0.503 | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head1 SYNOPSIS | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | package Langertha::Content::Image; | ||||||||||||||||||||
| 43 | use Moose; | ||||||||||||||||||||
| 44 | with 'Langertha::Content'; | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | sub to_openai { ... } | ||||||||||||||||||||
| 47 | sub to_anthropic { ... } | ||||||||||||||||||||
| 48 | sub to_gemini { ... } | ||||||||||||||||||||
| 49 | sub to_responses { ... } | ||||||||||||||||||||
| 50 | sub to_ollama { ... } | ||||||||||||||||||||
| 51 | sub to_lmstudio { ... } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | Marker role for canonical content blocks that can be embedded inside the | ||||||||||||||||||||
| 56 | C<content> arrayref of a chat message and serialized to any provider wire | ||||||||||||||||||||
| 57 | format by L<Langertha::Role::Chat>. | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | Implementations must provide C<to_openai>, C<to_anthropic> and C<to_gemini>, | ||||||||||||||||||||
| 60 | and may provide C<to_responses>, C<to_ollama> and C<to_lmstudio> (one per | ||||||||||||||||||||
| 61 | L<Langertha::Role::Chat/content_format>). Each returns what its wire expects | ||||||||||||||||||||
| 62 | for the block: a HashRef for the message content / parts / input array, or | ||||||||||||||||||||
| 63 | (C<to_ollama>) the raw base64 string for the message C<images> array. The | ||||||||||||||||||||
| 64 | role's defaults for the last three croak with | ||||||||||||||||||||
| 65 | C<< "<class> cannot be sent on the <fmt> wire; implement to_<fmt>" >>. | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =head2 to_responses | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =head2 to_ollama | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =head2 to_lmstudio | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | Default serializers for the C<responses>, C<ollama> and C<lmstudio> | ||||||||||||||||||||
| 74 | L<Langertha::Role::Chat/content_format>s. They croak; a content class that | ||||||||||||||||||||
| 75 | can be sent on those wires overrides them (L<Langertha::Content::Image> does). | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =head1 SEE ALSO | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =over | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =item * L<Langertha::Content::Image> - Image (URL / base64 / local file) content block | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =item * L<Langertha::ToolChoice> - Sibling value object for tool_choice normalization | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =back | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =head1 SUPPORT | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =head2 Issues | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||
| 92 | L<https://github.com/Getty/langertha/issues>. | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =head2 IRC | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =head1 CONTRIBUTING | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =head1 AUTHOR | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>. | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 111 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||