Ollama local LLM client. Runs models (Llama, Mistral, Phi, Qwen, etc.) locally via the Ollama server. Supports text generation, chat sessions with tool calling, structured (JSON schema) output, thinking models, images, batch embeddings and model management. Every request completes before returning -- responses are not streamed, so a long generation produces nothing until it finishes. Compile with -lib ollama.
Model
Ollama model operations: listing, details, pull, copy, delete, create and embeddings
Example
models := Model->List();
if(models <> Nil) {
each(m in models) {
m->GetPulled()->GetName()->PrintLine();
};
};Operations
- BuildEmbedRequest
- Copy
- Create
- Delete
- Embed
- Embeddings
- GetDetails
- GetInfo
- GetPulled
- List
- ParseEmbedResponse
- ParseModelList
- ParseShowResponse
- ParseStatusResponse
- ParseVersionResponse
- Pull
- Running
- Show
- ToString
- Version
BuildEmbedRequest # function
Builds the /api/embed request body.
function : BuildEmbedRequest(model:String, inputs:String[], truncate:Bool, dimensions:Int, options:Options) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| model | String | embedding model name |
| inputs | String | texts to embed |
| truncate | Bool | true to truncate inputs that exceed the context; false makes the server return an error instead |
| dimensions | Int | embedding size for models that support it, or 0 for the model's own |
| options | Options | options and request settings (e.g. keep_alive), or Nil |
Return
| Type | Description |
|---|---|
| JsonElement | request body |
Copy # function
Copy a model
function : Copy(src:String, dest:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| src | String | source name of the model to copy |
| dest | String | destination name of the model to copy |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise (see EndPoint->GetLastError) |
Example
if(Model->Copy("llama3", "llama3-backup")) {
"Model copied."->PrintLine();
};Create # function
Create a model from an existing one with a new system prompt
function : Create(name:String, base:String, system:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | name of the model to create |
| base | String | name of the model to start from |
| system | String | system prompt, or Nil |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise (see EndPoint->GetLastError) |
Example
if(Model->Create("my-assistant", "llama3", "You are a helpful assistant.")) {
"Custom model created."->PrintLine();
};Create # function
Create a model from a Modelfile description. Only servers older than Ollama 0.5.5 accept a Modelfile; newer ones reject the request (see EndPoint->GetLastError), so use Create(name, from, system) with them.
function : Create(name:String, modelfile:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | name of the model to create |
| modelfile | String | contents of the Modelfile |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Delete # function
Delete a model and its data.
function : Delete(name:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | name of the model to delete |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise (see EndPoint->GetLastError) |
Example
if(Model->Delete("llama3")) {
"Model deleted."->PrintLine();
};Embed # function
Embeds one text with /api/embed
function : Embed(model:String, input:String) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| model | String | embedding model name |
| input | String | text to embed |
Return
| Type | Description |
|---|---|
| Float | embedding vector, or Nil with the last error set |
Example
vector := Model->Embed("nomic-embed-text", "The sky is blue.");
if(vector <> Nil) {
"Dimensions: {$vector->Size()}"->PrintLine();
};Embed # function
Embeds a batch of texts with /api/embed in one request
function : Embed(model:String, inputs:String[]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| model | String | embedding model name |
| inputs | String | texts to embed |
Return
| Type | Description |
|---|---|
| Float | one row per input, or Nil with the last error set |
Embed # function
Embeds a batch of texts with /api/embed in one request
function : Embed(model:String, inputs:String[], truncate:Bool, dimensions:Int, options:Options) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| model | String | embedding model name |
| inputs | String | texts to embed |
| truncate | Bool | true to truncate inputs that exceed the context; false makes the server return an error instead |
| dimensions | Int | embedding size for models that support it, or 0 for the model's own |
| options | Options | options and request settings (e.g. keep_alive), or Nil |
Return
| Type | Description |
|---|---|
| Float | one row per input, or Nil with the last error set |
Example
texts := ["The sky is blue.", "Grass is green."];
embeddings := Model->Embed("nomic-embed-text", texts, true, 0, Nil);
if(embeddings <> Nil) {
dims := embeddings->Size();
"{$dims[0]} vectors of {$dims[1]}"->PrintLine();
};Embeddings # function
Generate embeddings from a model with the older /api/embeddings endpoint (superseded by Embed)
function : Embeddings(model:String, prompt:String) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| model | String | name of model to generate embeddings from |
| prompt | String | text to generate embeddings for |
Return
| Type | Description |
|---|---|
| Float | embedding vector as Float array, or Nil with the last error set |
Example
embeddings := Model->Embeddings("nomic-embed-text", "The sky is blue.");
if(embeddings <> Nil) {
"Dimensions: {$embeddings->Size()}"->PrintLine();
};GetDetails #
Get the model details
method : public : GetDetails() ~ ModelDetailsReturn
| Type | Description |
|---|---|
| ModelDetails | model details, or Nil |
GetInfo #
Get the model information (Model->Show)
method : public : GetInfo() ~ ModelInfoReturn
| Type | Description |
|---|---|
| ModelInfo | model information, or Nil |
GetPulled #
Get the listing entry (Model->List and Model->Running)
method : public : GetPulled() ~ ModelPulledReturn
| Type | Description |
|---|---|
| ModelPulled | listing entry, or Nil |
List # function
List the models available locally
function : List() ~ Vector<Model>Return
| Type | Description |
|---|---|
| Vector<Model> | list of models, or Nil with the last error set |
Example
models := Model->List();
if(models <> Nil) {
each(m in models) {
m->GetPulled()->GetName()->PrintLine();
};
};ParseEmbedResponse # function
Parses a /api/embed response body.
function : ParseEmbedResponse(body:String) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| body | String | response text |
Return
| Type | Description |
|---|---|
| Float | one row per input, or Nil with the last error set |
ParseModelList # function
Parses a /api/tags or /api/ps response body.
function : ParseModelList(body:String) ~ Vector<Model>Parameters
| Name | Type | Description |
|---|---|---|
| body | String | response text |
Return
| Type | Description |
|---|---|
| Vector<Model> | models, or Nil with the last error set |
ParseShowResponse # function
Parses a /api/show response body.
function : ParseShowResponse(body:String) ~ ModelParameters
| Name | Type | Description |
|---|---|---|
| body | String | response text |
Return
| Type | Description |
|---|---|
| Model | model, or Nil with the last error set |
ParseStatusResponse # function
Parses a {"status": ...} response body (pull, create).
function : ParseStatusResponse(body:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| body | String | response text |
Return
| Type | Description |
|---|---|
| Bool | true if the status is "success"; otherwise false with the last error set |
ParseVersionResponse # function
Parses a /api/version response body.
function : ParseVersionResponse(body:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| body | String | response text |
Return
| Type | Description |
|---|---|
| String | version, or Nil with the last error set |
Pull # function
Download a model from the ollama library. Waits for the download to finish; no progress is reported.
function : Pull(name:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | name of the model to pull |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise (see EndPoint->GetLastError) |
Example
if(Model->Pull("llama3")) {
"Model downloaded successfully."->PrintLine();
};Running # function
List the models currently loaded in memory
function : Running() ~ Vector<Model>Return
| Type | Description |
|---|---|
| Vector<Model> | list of models (see ModelPulled->GetSizeVram and GetExpiresAt), or Nil with the last error set |
Example
running := Model->Running();
if(running <> Nil) {
each(m in running) {
pulled := m->GetPulled();
name := pulled->GetName(); vram := pulled->GetSizeVram();
"{$name}: {$vram} bytes VRAM"->PrintLine();
};
};Show # function
Show information about a model
function : Show(name:String) ~ ModelParameters
| Name | Type | Description |
|---|---|---|
| name | String | name of the model to show |
Return
| Type | Description |
|---|---|
| Model | model (see GetInfo and GetDetails), or Nil with the last error set |
Example
model := Model->Show("llama3");
if(model <> Nil) {
model->GetDetails()->GetParameterSize()->PrintLine();
model->GetInfo()->HasCapability("tools")->PrintLine();
};