Client
Object Hierarchy:
Description:
public class Client : Object
Main client class for interacting with Ollama API and OpenAI-compatible REST interfaces.
Provides methods for chat, model management, and tool integration. Handles HTTP requests, streaming responses, and function calling.
Manages tool registration and execution with permission checking.
Basic Usage
var connection = new Settings.Connection() {
url = "http://127.0.0.1:11434/api"
};
var client = new Client(connection);
var chat = new Call.Chat(client, "llama3.2") {
stream = true
};
chat.messages.add(new Message(chat, "user", "Hello!"));
var response = yield chat.send(chat.messages);
Tool Integration
// Add tools to Chat before chatting
var read_file = new Tools.ReadFile(client);
var chat = new Call.Chat(client, "llama3.2");
chat.add_tool(read_file);
// Tools are automatically called when the model requests them
chat.messages.add(new Message(chat, "user", "Read README.md"));
var response = yield chat.send(chat.messages);
Streaming
var chat = new Call.Chat(client, "llama3.2") {
stream = true
};
chat.message_created.connect((msg, content) => {
if (msg.is_content && msg.is_stream) {
// Process incremental content
print(content.chat_content);
}
});
Content:
Properties:
Creation methods:
Methods:
- public async Chat chat (string model, string text, Options? options = null, Cancellable? cancellable = null) throws Error
Legacy chat method for backward compatibility.
- public async Chat chat_execute (Chat call) throws Error
Executes a pre-prepared Chat object.
- public async Embed embed (string model, string input, int dimensions = -1, bool truncate = false, Options? options = null, Cancellable? cancellable = null) throws Error
Generates embeddings for the input text.
- public async Embed embed_array (string model, ArrayList<string> input_array, int dimensions = -1, bool truncate = false, Options? options = null, Cancellable? cancellable = null) throws Error
Generates embeddings for an array of input texts.
- public async Generate generate (string model, string prompt, string system = "", Options? options = null, Cancellable? cancellable = null) throws Error
Generates a response for the provided prompt.
- public async ArrayList<Model> models () throws Error
Lists all available models (OpenAI-compatible).
- public async ArrayList<Model> ps () throws Error
Lists currently running models on the Ollama server.
- public async Model show_model (string model_name) throws Error
Gets detailed information about a specific model including
capabilities.
- public async string version (Cancellable? cancellable = null) throws Error
Gets the version of the Ollama server.
Inherited Members:
All known members inherited from class GLib.Object
- @get
- @new
- @ref
- @set
- add_toggle_ref
- add_weak_pointer
- bind_property
- connect
- constructed
- disconnect
- dispose
- dup_data
- dup_qdata
- force_floating
- freeze_notify
- get_class
- get_data
- get_property
- get_qdata
- get_type
- getv
- interface_find_property
- interface_install_property
- interface_list_properties
- is_floating
- new_valist
- new_with_properties
- newv
- notify
- notify_property
- ref_count
- ref_sink
- remove_toggle_ref
- remove_weak_pointer
- replace_data
- replace_qdata
- set_data
- set_data_full
- set_property
- set_qdata
- set_qdata_full
- set_valist
- setv
- steal_data
- steal_qdata
- thaw_notify
- unref
- watch_closure
- weak_ref
- weak_unref