ollama-swift  by mattt

Swift client library for interacting with the Ollama API

created 1 year ago
414 stars

Top 71.8% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This Swift client library provides a robust interface for interacting with the Ollama API, enabling developers to integrate large language models into their macOS applications. It supports core LLM functionalities like text generation, chat, embeddings, and model management, with advanced features such as streaming responses, structured output generation via JSON schema, and tool use for complex task execution.

How It Works

The library leverages Swift's async/await for asynchronous operations, ensuring non-blocking API calls. It communicates with the Ollama server via HTTP requests, parsing JSON responses into strongly-typed Swift objects. Key features include streaming capabilities for real-time feedback and a flexible format parameter for structured data output, allowing users to specify JSON or custom JSON schemas for model responses. Tool use is implemented through a Tool struct that defines the tool's name, description, parameters, and an asynchronous execution closure.

Quick Start & Requirements

  • Installation: Swift Package Manager: https://github.com/loopwork-ai/ollama-swift.git
  • Prerequisites: Swift 5.7+, macOS 13+, Ollama server running locally or remotely.
  • Example Model: llama3.2 (download via ollama pull llama3.2)
  • Documentation: https://github.com/loopwork-ai/ollama-swift

Highlighted Details

  • Supports structured output generation using JSON or custom JSON schemas.
  • Enables tool use with models, including multi-turn conversations and tool call handling.
  • Provides streaming for both text generation and chat responses.
  • Includes functions for managing Ollama models (list, show, pull, push).
  • Offers embedding generation capabilities.

Maintenance & Community

The project is maintained by loopwork-ai. Further community engagement details are not specified in the README.

Licensing & Compatibility

The library is released under the MIT License, permitting commercial use and integration into closed-source projects.

Limitations & Caveats

The README notes that tool support requires a compatible model, such as llama3.2. The parameter format for tool definition was updated in v1.3.0, with the older format now deprecated but still supported.

Health Check
Last commit

1 week ago

Responsiveness

1+ week

Pull Requests (30d)
1
Issues (30d)
0
Star History
55 stars in the last 90 days

Explore Similar Projects

Starred by John Resig John Resig(Author of jQuery; Chief Software Architect at Khan Academy), Shawn Wang Shawn Wang(Editor of Latent Space), and
3 more.

ollama-js by ollama

0.4%
4k
JS SDK for Ollama
created 1 year ago
updated 3 weeks ago
Feedback? Help us improve.