SYNOPSIS

my $client = AI::Ollama::Client::Impl->new(
    schema_file => '...',
);

PROPERTIES

schema_file

The OpenAPI schema file we use for validation

schema

The OpenAPI schema data structure we use for validation. If not given, we will create one using the schema_file parameter.

openapi

The OpenAPI::Modern object we use for validation. If not given, we will create one using the schema parameter.

ua

The Mojo::UserAgent to use

server

The server to access

METHODS

build_checkBlob_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

checkBlob

my $res = $client->checkBlob(
    'digest' => '...',
)->get;

Check to see if a blob exists on the Ollama server which is useful when creating models.

Parameters

digest

the SHA256 digest of the blob

build_createBlob_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

createBlob

my $res = $client->createBlob(
    'digest' => '...',
)->get;

Create a blob from a file. Returns the server file path.

Parameters

digest

the SHA256 digest of the blob

build_generateChatCompletion_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

generateChatCompletion

use Future::Utils 'repeat';
my $response = $client->generateChatCompletion();
my $streamed = $response->get();
repeat {
    my ($res) = $streamed->shift;
    if( $res ) {
        my $str = $res->get;
        say $str;
    }

    Future::Mojo->done( defined $res );
} until => sub($done) { $done->get };

Generate the next message in a chat with a provided model.

This is a streaming endpoint, so there will be a series of responses. The final response object will include statistics and additional data from the request.

Options

format

The format to return a response in. Currently the only accepted value is json.

Enable JSON mode by setting the format parameter to json. This will structure the response as valid JSON.

Note: it's important to instruct the model to use JSON in the prompt. Otherwise, the model may generate large amounts whitespace.

keep_alive

How long (in minutes) to keep the model loaded in memory.

-

If set to a positive duration (e.g. 20), the model will stay loaded for the provided duration.

-

If set to a negative duration (e.g. -1), the model will stay loaded indefinitely.

-

If set to 0, the model will be unloaded immediately once finished.

-

If not set, the model will stay loaded for 5 minutes by default

messages

The messages of the chat, this can be used to keep a chat memory

model

The model name.

Model names follow a model:tag format. Some examples are orca-mini:3b-q4_1 and llama2:70b. The tag is optional and, if not provided, will default to latest. The tag is used to identify a specific version.

options

Additional model parameters listed in the documentation for the Modelfile such as temperature.

stream

If false the response will be returned as a single response object, otherwise the response will be streamed as a series of objects.

Returns a AI::Ollama::GenerateChatCompletionResponse on success.

build_copyModel_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

copyModel

my $res = $client->copyModel()->get;

Creates a model with another name from an existing model.

Options

destination

Name of the new model.

source

Name of the model to copy.

build_createModel_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

createModel

use Future::Utils 'repeat';
my $response = $client->createModel();
my $streamed = $response->get();
repeat {
    my ($res) = $streamed->shift;
    if( $res ) {
        my $str = $res->get;
        say $str;
    }

    Future::Mojo->done( defined $res );
} until => sub($done) { $done->get };

Create a model from a Modelfile.

It is recommended to set modelfile to the content of the Modelfile rather than just set path. This is a requirement for remote create. Remote model creation should also create any file blobs, fields such as FROM and ADAPTER, explicitly with the server using Create a Blob and the value to the path indicated in the response.

Options

modelfile

The contents of the Modelfile.

name

The model name.

Model names follow a model:tag format. Some examples are orca-mini:3b-q4_1 and llama2:70b. The tag is optional and, if not provided, will default to latest. The tag is used to identify a specific version.

stream

If false the response will be returned as a single response object, otherwise the response will be streamed as a series of objects.

Returns a AI::Ollama::CreateModelResponse on success.

build_deleteModel_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

deleteModel

my $res = $client->deleteModel()->get;

Delete a model and its data.

Options

name

The model name.

Model names follow a model:tag format. Some examples are orca-mini:3b-q4_1 and llama2:70b. The tag is optional and, if not provided, will default to latest. The tag is used to identify a specific version.

build_generateEmbedding_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

generateEmbedding

my $res = $client->generateEmbedding()->get;

Generate embeddings from a model.

Options

model

The model name.

Model names follow a model:tag format. Some examples are orca-mini:3b-q4_1 and llama2:70b. The tag is optional and, if not provided, will default to latest. The tag is used to identify a specific version.

options

Additional model parameters listed in the documentation for the Modelfile such as temperature.

prompt

Text to generate embeddings for.

Returns a AI::Ollama::GenerateEmbeddingResponse on success.

build_generateCompletion_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

generateCompletion

use Future::Utils 'repeat';
my $response = $client->generateCompletion();
my $streamed = $response->get();
repeat {
    my ($res) = $streamed->shift;
    if( $res ) {
        my $str = $res->get;
        say $str;
    }

    Future::Mojo->done( defined $res );
} until => sub($done) { $done->get };

Generate a response for a given prompt with a provided model.

The final response object will include statistics and additional data from the request.

Options

context

The context parameter returned from a previous request to [generateCompletion], this can be used to keep a short conversational memory.

format

The format to return a response in. Currently the only accepted value is json.

Enable JSON mode by setting the format parameter to json. This will structure the response as valid JSON.

Note: it's important to instruct the model to use JSON in the prompt. Otherwise, the model may generate large amounts whitespace.

images

(optional) a list of Base64-encoded images to include in the message (for multimodal models such as llava)

keep_alive

How long (in minutes) to keep the model loaded in memory.

-

If set to a positive duration (e.g. 20), the model will stay loaded for the provided duration.

-

If set to a negative duration (e.g. -1), the model will stay loaded indefinitely.

-

If set to 0, the model will be unloaded immediately once finished.

-

If not set, the model will stay loaded for 5 minutes by default

model

The model name.

Model names follow a model:tag format. Some examples are orca-mini:3b-q4_1 and llama2:70b. The tag is optional and, if not provided, will default to latest. The tag is used to identify a specific version.

options

Additional model parameters listed in the documentation for the Modelfile such as temperature.

prompt

The prompt to generate a response.

raw

If true no formatting will be applied to the prompt and no context will be returned.

You may choose to use the raw parameter if you are specifying a full templated prompt in your request to the API, and are managing history yourself.

stream

If false the response will be returned as a single response object, otherwise the response will be streamed as a series of objects.

system

The system prompt to (overrides what is defined in the Modelfile).

template

The full prompt or prompt template (overrides what is defined in the Modelfile).

Returns a AI::Ollama::GenerateCompletionResponse on success.

build_pullModel_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

pullModel

use Future::Utils 'repeat';
my $response = $client->pullModel();
my $streamed = $response->get();
repeat {
    my ($res) = $streamed->shift;
    if( $res ) {
        my $str = $res->get;
        say $str;
    }

    Future::Mojo->done( defined $res );
} until => sub($done) { $done->get };

Download a model from the ollama library.

Cancelled pulls are resumed from where they left off, and multiple calls will share the same download progress.

Options

insecure

Allow insecure connections to the library.

Only use this if you are pulling from your own library during development.

name

The model name.

Model names follow a model:tag format. Some examples are orca-mini:3b-q4_1 and llama2:70b. The tag is optional and, if not provided, will default to latest. The tag is used to identify a specific version.

stream

If false the response will be returned as a single response object, otherwise the response will be streamed as a series of objects.

Returns a AI::Ollama::PullModelResponse on success.

build_pushModel_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

pushModel

my $res = $client->pushModel()->get;

Upload a model to a model library.

Requires registering for ollama.ai and adding a public key first.

Options

insecure

Allow insecure connections to the library.

Only use this if you are pushing to your library during development.

name

The name of the model to push in the form of /:.

stream

If false the response will be returned as a single response object, otherwise the response will be streamed as a series of objects.

Returns a AI::Ollama::PushModelResponse on success.

build_showModelInfo_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

showModelInfo

my $res = $client->showModelInfo()->get;

Show details about a model including modelfile, template, parameters, license, and system prompt.

Options

name

The model name.

Model names follow a model:tag format. Some examples are orca-mini:3b-q4_1 and llama2:70b. The tag is optional and, if not provided, will default to latest. The tag is used to identify a specific version.

Returns a AI::Ollama::ModelInfo on success.

build_listModels_request

Build an HTTP request as Mojo::Request object. For the parameters see below.

listModels

my $res = $client->listModels()->get;

List models that are available locally.

Returns a AI::Ollama::ModelsResponse on success.