Langertha/Stream/Chunk.pm

filter: Statementstmt 100% 16 / 16 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 100% 18 / 18 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Langertha/Role/Temperature.pm ↑ Summary LangerthaX.pm »
1 package Langertha::Stream::Chunk;
2 # ABSTRACT: Represents a single chunk from a streaming response
3 35 our $VERSION = '0.502';
4 35 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use Langertha::ToolCall;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 35 has content => (
9 is => 'ro',
10 isa => 'Str',
11 required => 1,
12 );
13  
14  
15 35 has raw => (
16 is => 'ro',
17 isa => 'HashRef',
18 predicate => 'has_raw',
19 );
20  
21  
22 35 has is_final => (
23 is => 'ro',
24 isa => 'Bool',
25 default => 0,
26 );
27  
28  
29 35 has model => (
30 is => 'ro',
31 isa => 'Str',
32 predicate => 'has_model',
33 );
34  
35  
36 35 has finish_reason => (
37 is => 'ro',
38 isa => 'Maybe[Str]',
39 predicate => 'has_finish_reason',
40 );
41  
42  
43 35 has usage => (
44 is => 'ro',
45 isa => 'Maybe[HashRef]',
46 predicate => 'has_usage',
47 );
48  
49 35 has tool_calls => (
50 is => 'ro',
51 isa => 'Maybe[ArrayRef[Langertha::ToolCall]]',
52 predicate => 'has_tool_calls',
53 );
54  
55  
56  
57  
58 35 __PACKAGE__->meta->make_immutable;
59  
60 35 1;
61  
62 __END__
63  
64 =pod
65  
66 =encoding UTF-8
67  
68 =head1 NAME
69  
70 Langertha::Stream::Chunk - Represents a single chunk from a streaming response
71  
72 =head1 VERSION
73  
74 version 0.502
75  
76 =head1 SYNOPSIS
77  
78 my $stream = $engine->simple_chat_stream_iterator('Tell me a story');
79  
80 while (my $chunk = $stream->next) {
81 print $chunk->content;
82  
83 if ($chunk->is_final) {
84 say "\nModel: ", $chunk->model if $chunk->has_model;
85 say "Finish: ", $chunk->finish_reason if $chunk->has_finish_reason;
86 }
87 }
88  
89 =head1 DESCRIPTION
90  
91 A single text chunk delivered during a streaming LLM response. Each chunk
92 carries incremental content text and optional metadata. Chunks are collected
93 into a L<Langertha::Stream> iterator by
94 L<Langertha::Role::Chat/simple_chat_stream_iterator>.
95  
96 =head2 content
97  
98 The incremental text content delivered in this chunk. Required. For most
99 chunks this is a word or partial word; the final chunk may be an empty
100 string.
101  
102 =head2 raw
103  
104 The raw parsed API response data for this chunk as a HashRef. Use
105 C<has_raw> to check whether it was provided.
106  
107 =head2 is_final
108  
109 Boolean flag set to C<1> on the last chunk of a stream. Defaults to C<0>.
110  
111 =head2 model
112  
113 The model identifier returned by the provider, if present. Use C<has_model>
114 to check availability.
115  
116 =head2 finish_reason
117  
118 The reason the stream ended: C<stop>, C<length>, C<tool_calls>, etc.
119 Provider-specific values are preserved as-is. C<undef> on non-final chunks.
120 Use C<has_finish_reason> to check availability.
121  
122 =head2 tool_calls
123  
124 Optional ArrayRef of L<Langertha::ToolCall> objects associated with
125 this chunk. Populated when the engine emits tool-call information
126 mid-stream (e.g. Anthropic's C<content_block_stop> for a C<tool_use>
127 block, or the final OpenAI delta carrying assembled tool_calls). Most
128 chunks have no tool calls — use C<has_tool_calls> to check.
129  
130 =head2 usage
131  
132 Token usage counts as a HashRef, if provided by the engine on the final
133 chunk. Keys vary by provider. Use C<has_usage> to check availability.
134  
135 =head1 SEE ALSO
136  
137 =over
138  
139 =item * L<Langertha::Stream> - Iterator that holds chunks
140  
141 =item * L<Langertha::Response> - Non-streaming response object
142  
143 =item * L<Langertha::Role::Chat> - Chat role that produces streams
144  
145 =back
146  
147 =head1 SUPPORT
148  
149 =head2 Issues
150  
151 Please report bugs and feature requests on GitHub at
152 L<https://github.com/Getty/langertha/issues>.
153  
154 =head2 IRC
155  
156 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
157  
158 =head1 CONTRIBUTING
159  
160 Contributions are welcome! Please fork the repository and submit a pull request.
161  
162 =head1 AUTHOR
163  
164 Torsten Raudssus <getty@cpan.org>
165  
166 =head1 COPYRIGHT AND LICENSE
167  
168 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
169  
170 This is free software; you can redistribute it and/or modify it under
171 the same terms as the Perl 5 programming language system itself.
172  
173 =cut
« Langertha/Role/Temperature.pm ↑ Summary LangerthaX.pm »