Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

Lazarus-Free-Pascal-Local-LLM-wrapper

Native Lazarus (Free Pascal) Local LLM wrapper demo supporting Ollama and LM Studio.

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

Lazarus Local LLM Wrapper Demo

A lightweight Free Pascal / Lazarus demo showing how to connect a native desktop application to local Large Language Models (LLMs) such as Ollama and LM Studio.

This project demonstrates that modern AI integrations can be implemented entirely in Lazarus (Object Pascal) — without Python, Node.js, or external runtimes.


✨ Features

  • ✅ Native Lazarus / Free Pascal implementation
  • ✅ Supports Ollama (/api/chat)
  • ✅ Supports LM Studio (OpenAI-compatible API)
  • ✅ Background threading (non-blocking UI)
  • ✅ Multi-turn conversation history
  • ✅ Cancel request support (non-blocking)
  • ✅ Simple and clean demo UI

Screenshot

Demo

🧠 Supported Backends

1. Ollama

  • Endpoint: http://localhost:11434/api/chat
  • Model example: llama3.1, mistral, etc.

2. LM Studio

  • Endpoint: http://localhost:1234/v1/chat/completions
  • OpenAI-compatible API

🚀 Getting Started

1. Install Lazarus

Download and install:


2. Setup Ollama

Install Ollama:

Pull a model:

bash
ollama pull llama3.1

Start the server:

bash
ollama serve

Default API:

pascal
http://localhost:11434

3. Setup LM Studio (Optional)

Download:

Steps:

  1. Load any model
  2. Start local server
  3. Default endpoint:
pascal
http://localhost:1234

4. Open the Project

  1. Open Lazarus IDE
  2. Load project file (.lpr or .lpi)
  3. Build and Run

🖥️ Usage

  1. Select backend (Ollama / LM Studio)
  2. Enter model name
  3. Type a prompt
  4. Click Send
  5. View response in the memo panel

⚠️ Important Notes

Cancel Behavior

The Cancel button does NOT immediately abort the HTTP request.

Instead:

  • It marks the request as cancelled
  • The response is ignored when it returns

This is sufficient for demo purposes but not a full cancellation mechanism.


Not Production Ready

This project is a:

⚠️ Proof-of-Concept / Demo

It is not yet suitable for production use.

Missing features include:

  • Streaming responses
  • Robust cancellation (socket-level)
  • Advanced error handling
  • Context window management
  • Authentication / API key support

🧱 Architecture Overview

  • LocalLLM.pas → Core wrapper component
  • TLocalLLM → Handles API requests and history
  • TLocalLLMThread → Background execution
  • MainUnit.pas → Demo UI

💡 Purpose of This Project

This demo exists to show:

You can build modern AI-powered applications using Lazarus / Free Pascal

without relying on:

  • Python ecosystems
  • JavaScript frameworks
  • Cloud-based APIs

🛣️ Future Improvements

  • Streaming token support
  • Multi-model orchestration
  • Plugin/tool system
  • Better cancellation (interrupt HTTP)
  • History summarization
  • GPU/quantization controls

📄 License

MIT License (recommended) — feel free to modify.


🤝 Contributions

Contributions are welcome! Feel free to fork, improve, or extend this into a full local AI runtime.


⭐ If you find this useful

Give it a star on GitHub — it helps others discover Lazarus-based AI projects 👍