Langertha/Engine/OllamaOpenAI.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 50.0% 1 / 2 totaltotal 77.2% 17 / 22 CC 1 SCAR 3.4
CC
1
Cov
87%
default_model
2.0
default_embedding_model
2.0
BEGIN
1.0
CRAP 1.4
« Langertha/Engine/LMStudioOpenAI.pm ↑ Summary Langertha/Engine/NousResearch.pm »
1 package Langertha::Engine::OllamaOpenAI;
2 # ABSTRACT: Ollama via OpenAI-compatible API
3 12 our $VERSION = '0.502';
4 12 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 extends 'Langertha::Engine::OpenAIBase';
8  
9 12 with 'Langertha::Role::Embedding', 'Langertha::Role::Tools';
10  
11  
12 12 has '+url' => (
13 required => 1,
14 );
15  
16 0 ▶sub default_model { croak "".(ref $_[0])." requires model to be set" }
Subroutine default_model: not called CC=1 SCAR=6.9
Pod documented
17 0 ▶sub default_embedding_model { 'mxbai-embed-large' }
Subroutine default_embedding_model: not called CC=1 SCAR=6.9
Pod undocumented
18  
19 3 ▶sub _build_supported_operations {[qw( createChatCompletion createEmbedding )]}
Subroutine _build_supported_operations: called CC=1 SCAR=0.0
20  
21 12 __PACKAGE__->meta->make_immutable;
22  
23  
24 12 1;
25  
26 __END__
27  
28 =pod
29  
30 =encoding UTF-8
31  
32 =head1 NAME
33  
34 Langertha::Engine::OllamaOpenAI - Ollama via OpenAI-compatible API
35  
36 =head1 VERSION
37  
38 version 0.502
39  
40 =head1 SYNOPSIS
41  
42 use Langertha::Engine::OllamaOpenAI;
43  
44 # Direct construction (url with /v1 suffix is required)
45 my $ollama_oai = Langertha::Engine::OllamaOpenAI->new(
46 url => 'http://localhost:11434/v1',
47 model => 'llama3.3',
48 );
49  
50 print $ollama_oai->simple_chat('Hello!');
51  
52 # Streaming
53 $ollama_oai->simple_chat_stream(sub {
54 print shift->content;
55 }, 'Tell me about Perl');
56  
57 # Preferred: create via Ollama's openai() method (appends /v1 automatically)
58 use Langertha::Engine::Ollama;
59  
60 my $ollama = Langertha::Engine::Ollama->new(
61 url => 'http://localhost:11434',
62 model => 'llama3.3',
63 );
64 my $oai = $ollama->openai;
65 print $oai->simple_chat('Hello via OpenAI format!');
66  
67 =head1 DESCRIPTION
68  
69 Provides access to Ollama's OpenAI-compatible C</v1> API endpoint. Composes
70 L<Langertha::Role::OpenAICompatible> for the standard OpenAI format.
71  
72 C<url> is required and must include the C</v1> path prefix (e.g.,
73 C<http://localhost:11434/v1>). When using L<Langertha::Engine::Ollama/openai>,
74 the C</v1> suffix is appended automatically. The API key defaults to
75 C<'ollama'> since Ollama does not require authentication.
76  
77 Supports chat completions (SSE streaming), embeddings (default:
78 C<mxbai-embed-large>), MCP tool calling, and dynamic model listing.
79 Transcription is not supported.
80  
81 For the native Ollama API with C<keep_alive>, C<seed>, C<context_size>,
82 NDJSON streaming, and Hermes tool calling, use L<Langertha::Engine::Ollama>.
83  
84 B<THIS API IS WORK IN PROGRESS>
85  
86 =head1 SEE ALSO
87  
88 =over
89  
90 =item * L<Langertha::Engine::Ollama> - Native Ollama API (with keep_alive, seed, context_size)
91  
92 =item * L<Langertha::Role::OpenAICompatible> - OpenAI API format role composed by this engine
93  
94 =item * L<https://github.com/ollama/ollama> - Ollama project
95  
96 =back
97  
98 =head1 SUPPORT
99  
100 =head2 Issues
101  
102 Please report bugs and feature requests on GitHub at
103 L<https://github.com/Getty/langertha/issues>.
104  
105 =head2 IRC
106  
107 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
108  
109 =head1 CONTRIBUTING
110  
111 Contributions are welcome! Please fork the repository and submit a pull request.
112  
113 =head1 AUTHOR
114  
115 Torsten Raudssus <getty@cpan.org>
116  
117 =head1 COPYRIGHT AND LICENSE
118  
119 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
120  
121 This is free software; you can redistribute it and/or modify it under
122 the same terms as the Perl 5 programming language system itself.
123  
124 =cut
« Langertha/Engine/LMStudioOpenAI.pm ↑ Summary Langertha/Engine/NousResearch.pm »