Ollama Local LLM

Run open-source large language models locally from your Delphi, C++ Builder and .NET applications. Inference stays private, offline and on-premise, executing on your own hardware with no cloud API required.

TsgcHTTP_API_Ollama

Ollama REST API client for local chat completions, embeddings and model management.

Component class

TsgcHTTP_API_Ollama

Protocol

Ollama REST API over HTTP

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Enterprise (AI add-on)

Drop the component, point it at localhost, go

Ollama runs locally and needs no API key. Set OllamaOptions.BaseUrl to your local server (default http://localhost:11434/api), then call _CreateMessage or build a TsgcOllamaClass_Request_ChatCompletion and call CreateMessage.

uses
  sgcHTTP_API_Ollama;

var
  Ollama: TsgcHTTP_API_Ollama;
begin
  Ollama := TsgcHTTP_API_Ollama.Create(nil);
  // Local server, no API key needed
  Ollama.OllamaOptions.BaseUrl := 'http://localhost:11434/api';

  // Simple one-shot message
  Memo1.Lines.Text := Ollama._CreateMessage(
    'llama3',
    'What are the benefits of WebSockets?');

  // Streaming — handle OnHTTPAPISSE per chunk
  Ollama.OnHTTPAPISSE := HandleSSE;
  Ollama._CreateMessageStream(
    'llama3',
    'Summarise RFC 6455');
end;

procedure TForm1.HandleSSE(Sender: TObject;
  const aEvent, aData: string;
  var Cancel: Boolean);
begin
  Memo1.Lines.Add(aEvent + ': ' + aData);
end;
// uses: sgcHTTP_API_Ollama
TsgcHTTP_API_Ollama *Ollama = new TsgcHTTP_API_Ollama(this);
// Local server, no API key needed
Ollama->OllamaOptions->BaseUrl = "http://localhost:11434/api";

// Simple one-shot message
Memo1->Lines->Text = Ollama->_CreateMessage(
  "llama3",
  "What are the benefits of WebSockets?");

// Streaming — OnHTTPAPISSE fires per chunk
Ollama->OnHTTPAPISSE = HandleSSE;
Ollama->_CreateMessageStream(
  "llama3",
  "Summarise RFC 6455");
using esegece.sgcWebSockets;

var ollama = new TsgcHTTPAPI_Ollama();
// Local server, no API key needed
ollama.OllamaOptions.BaseUrl = "http://localhost:11434/api";

// Simple one-shot message
Console.WriteLine(ollama._CreateMessage(
  "llama3",
  "What are the benefits of WebSockets?"));

// Streaming via Server-Sent Events
ollama.OnHTTPAPISSE += (sender, ev, data, cancel) => Console.Write(data);
ollama._CreateMessageStream(
  "llama3",
  "Summarise RFC 6455");

What's inside

Typed request / response classes for chat completions and embeddings, plus model management and streaming over Server-Sent Events.

Messages & chat

CreateMessage sends a typed TsgcOllamaClass_Request_ChatCompletion and returns a parsed response. _CreateMessage, _CreateMessageWithSystem and _CreateMessageStream are string shortcuts, with streaming deltas delivered through OnHTTPAPISSE.

Embeddings

CreateEmbeddings turns input text into a dense vector using a locally pulled embedding model such as nomic-embed-text or mxbai-embed-large, returning a TsgcOllamaClass_Response_Embeddings.

Models

Manage the models on your machine: _GetModels and _GetTags list what is available, _ShowModel reads model details, _PullModel downloads from the Ollama library and _DeleteModel removes a local model.

Local & private

Every request targets a local Ollama server (default http://localhost:11434/api) so no data leaves your network and no API key is required. Point OllamaOptions.BaseUrl at a remote or containerized instance when you need to.

Reliability & diagnostics

CircuitBreaker short-circuits requests when the server is unhealthy; ReadTimeout and TLSOptions tune the HTTP/HTTPS layer; OnHTTPAPIException surfaces failures; OnHTTPAPISSE streams server-sent events.

Specifications & references

Authoritative sources for the protocols this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — Ollama Full property, method and event reference for this component.
Demo Project — Demos\AI\Ollama Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Run Local LLMs with Ollama?

Download the free trial and start building in minutes.