« blib/lib/Langertha/Knarr/Handler/RequestLog.pm
↑ Summary
blib/lib/Langertha/Knarr/TokenStore/Memory.pm »
| 1 | package Langertha::Knarr::CLI; | ||||||||||||||||||||||
| 2 | # ABSTRACT: CLI entry point for Knarr LLM Proxy | ||||||||||||||||||||||
| 3 | 41 | ▶ | use Moo; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 41 | ▶ | use MooX::Cmd; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 41 | ▶ | use MooX::Options protect_argv => 0; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 41 | our $VERSION = '1.103'; | |||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | option config => ( | ||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||
| 12 | format => 's', | ||||||||||||||||||||||
| 13 | short => 'c', | ||||||||||||||||||||||
| 14 | doc => 'Config file path (default: ./knarr.yaml)', | ||||||||||||||||||||||
| 15 | 35 | ▶ | default => sub { './knarr.yaml' }, | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | 41 | ); | |||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | option verbose => ( | ||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||
| 21 | short => 'v', | ||||||||||||||||||||||
| 22 | doc => 'Enable verbose logging (or set KNARR_DEBUG=1)', | ||||||||||||||||||||||
| 23 | 36 | ▶ | default => sub { $ENV{KNARR_DEBUG} ? 1 : 0 }, | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||
| 24 | 41 | negativable => 1, | |||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | # MooX::Options maps a dashed long option (--log-file) to its underscore | ||||||||||||||||||||||
| 29 | # attribute (log_file), but its argv rewrite takes the token after a | ||||||||||||||||||||||
| 30 | # boolean flag as that flag's value and passes it through unmapped — so | ||||||||||||||||||||||
| 31 | # `--from-env --log-file X` reached Getopt::Long as `--log-file` and died | ||||||||||||||||||||||
| 32 | # with "Unknown option". Map every long option name up front; arguments | ||||||||||||||||||||||
| 33 | # not starting with `--` and everything after a bare `--` are left alone. | ||||||||||||||||||||||
| 34 | 40 | ▶ | around new_with_cmd => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 35 | 40 | my ( $orig, $class, @args ) = @_; | |||||||||||||||||||||
| 36 | 40 | local @ARGV = $class->normalize_argv(@ARGV); | |||||||||||||||||||||
| 37 | 40 | return $class->$orig(@args); | |||||||||||||||||||||
| 38 | 41 | }; | |||||||||||||||||||||
| 39 | |||||||||||||||||||||||
| 40 | 40 | ▶ | sub normalize_argv { | ||||||||||||||||||||
|
Subroutine
normalize_argv: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||
| 41 | 40 | my ( $class, @argv ) = @_; | |||||||||||||||||||||
| 42 | 40 | my @out; | |||||||||||||||||||||
| 43 | 40 | ▶ | while (@argv) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 44 | 117 | my $arg = shift @argv; | |||||||||||||||||||||
| 45 | 117 | ▶ | if ( $arg eq '--' ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 46 | 0 | push @out, $arg, @argv; | |||||||||||||||||||||
| 47 | 0 | last; | |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||
| 49 | 117 | ▶ | if ( my ( $neg, $name, $value ) = $arg =~ /\A--(no-)?([A-Za-z][A-Za-z0-9_-]*)(=.*)?\z/s ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 50 | 22 | $name =~ tr/-/_/; | |||||||||||||||||||||
| 51 | 22 | ▶ | $arg = '--'.( $neg // '' ).$name.( $value // '' ); | ||||||||||||||||||||
|
Condition100%4/4
$neg // ""
$value // ""
MC/DC100%1/1
$neg // ""
$neg
MC/DC100%1/1
$value // ""
$value
Truth table100%2/2
A
A= $neg
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | 117 | push @out, $arg; | |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||
| 55 | 40 | return @out; | |||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | |||||||||||||||||||||||
| 59 | 0 | ▶ | sub execute { | ||||||||||||||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 60 | 0 | my ($self) = @_; | |||||||||||||||||||||
| 61 | 0 | print _banner(); | |||||||||||||||||||||
| 62 | 0 | print "\n"; | |||||||||||||||||||||
| 63 | 0 | print "USAGE\n"; | |||||||||||||||||||||
| 64 | 0 | print " knarr <command> [options]\n\n"; | |||||||||||||||||||||
| 65 | 0 | print "COMMANDS\n"; | |||||||||||||||||||||
| 66 | 0 | print " start Start the proxy server\n"; | |||||||||||||||||||||
| 67 | 0 | print " init Scan environment and generate configuration\n"; | |||||||||||||||||||||
| 68 | 0 | print " models List configured models and their backends\n"; | |||||||||||||||||||||
| 69 | 0 | print " check Validate configuration file\n\n"; | |||||||||||||||||||||
| 70 | 0 | print "GLOBAL OPTIONS\n"; | |||||||||||||||||||||
| 71 | 0 | print " -c, --config <path> Config file (default: ./knarr.yaml)\n"; | |||||||||||||||||||||
| 72 | 0 | print " -v, --verbose Enable verbose logging\n\n"; | |||||||||||||||||||||
| 73 | 0 | print "QUICK START (Docker)\n"; | |||||||||||||||||||||
| 74 | 0 | print " docker run -e OPENAI_API_KEY=sk-... -p 8080:8080 raudssus/langertha-knarr\n\n"; | |||||||||||||||||||||
| 75 | 0 | print "QUICK START (Local)\n"; | |||||||||||||||||||||
| 76 | 0 | print " knarr init > knarr.yaml\n"; | |||||||||||||||||||||
| 77 | 0 | print " knarr start\n\n"; | |||||||||||||||||||||
| 78 | 0 | print "EXAMPLES\n"; | |||||||||||||||||||||
| 79 | 0 | print " knarr start # Start with ./knarr.yaml\n"; | |||||||||||||||||||||
| 80 | 0 | print " knarr start -c production.yaml -p 9090 # Custom config and port\n"; | |||||||||||||||||||||
| 81 | 0 | print " knarr start --from-env # Auto-detect from ENV\n"; | |||||||||||||||||||||
| 82 | 0 | print " knarr start --from-env -p 8080 -p 11434 # ENV config, custom ports\n"; | |||||||||||||||||||||
| 83 | 0 | print " knarr init > knarr.yaml # Generate config\n"; | |||||||||||||||||||||
| 84 | 0 | print " knarr models # List configured models\n"; | |||||||||||||||||||||
| 85 | 0 | print " knarr check # Validate config\n\n"; | |||||||||||||||||||||
| 86 | 0 | print "ENVIRONMENT\n"; | |||||||||||||||||||||
| 87 | 0 | print " OPENAI_API_KEY OpenAI API key\n"; | |||||||||||||||||||||
| 88 | 0 | print " ANTHROPIC_API_KEY Anthropic API key\n"; | |||||||||||||||||||||
| 89 | 0 | print " LANGFUSE_PUBLIC_KEY Langfuse public key (enables tracing)\n"; | |||||||||||||||||||||
| 90 | 0 | print " LANGFUSE_SECRET_KEY Langfuse secret key\n"; | |||||||||||||||||||||
| 91 | 0 | print " LANGFUSE_URL Langfuse URL (default: https://cloud.langfuse.com)\n"; | |||||||||||||||||||||
| 92 | 0 | print " KNARR_API_KEY Proxy authentication key (optional)\n\n"; | |||||||||||||||||||||
| 93 | 0 | print "Version $VERSION | https://github.com/Getty/langertha-knarr\n"; | |||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | 0 | ▶ | sub _banner { | ||||||||||||||||||||
|
Subroutine
_banner: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 97 | 0 | return <<'BANNER'; | |||||||||||||||||||||
| 98 | . * . | ||||||||||||||||||||||
| 99 | . _/|_ . KNARR | ||||||||||||||||||||||
| 100 | . /| |\ . Langertha LLM Proxy | ||||||||||||||||||||||
| 101 | ~~~~~|______|~~~~~ | ||||||||||||||||||||||
| 102 | ~~ ~~~~~~~~~~~~~ ~~ Cargo transport for your LLM calls | ||||||||||||||||||||||
| 103 | ~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||
| 104 | BANNER | ||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | 41 | 1; | |||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||