NAME

WebService::Ollama::Async - Async Ollama client

VERSION

Version 0.08

SYNOPSIS

# Object-oriented interface
use WebService::Ollama::Async;
use IO::Async::Loop;

my $loop = IO::Async::Loop->new;

my $ollama = WebService::Ollama::Async->new(
    base_url => 'http://localhost:11434',
    model    => 'llama3.2',
    loop     => $loop,
);

# Simple chat - returns Future
my $future = $ollama->chat(
    messages => [
        { role => 'user', content => 'Hello!' }
    ],
);

$future->then(sub {
    my ($response) = @_;
    print $response->message->{content}, "\n";
})->get;

# Functional interface
use WebService::Ollama::Async qw(ollama);

ollama({ base_url => 'http://localhost:11434', model => 'llama3.2' });

my $future = ollama('chat', messages => [{ role => 'user', content => 'Hi' }]);
my $response = $future->get;

# With tools
$ollama->register_tool(
    name        => 'get_weather',
    description => 'Get current weather',
    parameters  => {
        type       => 'object',
        properties => {
            location => { type => 'string' },
        },
        required => ['location'],
    },
    handler => sub {
        my ($args) = @_;
        return { temp => 72, location => $args->{location} };
    },
);

$ollama->chat_with_tools(
    messages => [
        { role => 'user', content => 'What is the weather in Seattle?' }
    ],
)->then(sub {
    my ($response) = @_;
    print $response->message->{content}, "\n";
})->get;

DESCRIPTION

Async version of WebService::Ollama using IO::Async and Net::Async::HTTP. All methods return Future objects instead of blocking.

METHODS

All methods mirror WebService::Ollama but return Futures:

version

available_models

running_models

create_model

copy_model

delete_model

load_completion_model

unload_completion_model

completion

load_chat_model

unload_chat_model

chat

embed

register_tool

Register a tool for function calling.

$ollama->register_tool(
    name        => 'tool_name',
    description => 'What the tool does',
    parameters  => { ... },  # JSON Schema
    handler     => sub { my ($args) = @_; ... },
);

chat_with_tools

Chat with automatic tool execution loop.

my $future = $ollama->chat_with_tools(
    messages       => \@messages,
    max_iterations => 10,  # optional, default 10
);

AUTHOR

LNATION, <email at lnation.org>

LICENSE

This software is Copyright (c) 2026 by LNATION. This is free software, licensed under The Artistic License 2.0.