huggingface/AnyLanguageModel

An API-compatible, drop-in replacement for Apple's Foundation Models framework with support for custom language model providers.

What it solves

AnyLanguageModel is a Swift package that acts as a drop-in replacement for Apple's Foundation Models framework. It allows developers to use a wide variety of custom language model providers—both on-device and cloud-based—while maintaining a consistent API, reducing vendor lock-in and simplifying the integration of different LLM backends.

How it works

By replacing the import FoundationModels statement with import AnyLanguageModel, developers can access a variety of providers. The library uses Swift 6.1 traits to conditionally include heavy dependencies (like Core ML, MLX, or llama.cpp), ensuring that only the necessary backends are included in the final binary to keep build times and build sizes small.

Who it’s for

Swift developers building for iOS, macOS, visionOS, or Linux who want to integrate LLMs into their applications using a unified interface that supports both local on-device models and cloud APIs.

Highlights

  • Broad Provider Support: Supports Apple Foundation Models, Core ML, MLX, llama.cpp, Ollama, Anthropic, Google Gemini, and OpenAI.
  • Guided Generation: Enables strongly typed outputs using @Generable and @Guide to avoid manual string parsing.
  • Tool Calling: Comprehensive support for tool calling across all providers, including a delegate system to observe or control execution.
  • Multimodal Capabilities: Support for image inputs across various providers (where supported by the model).
  • Reasoning Support: Ability to capture and display reasoning segments separately from the final answer, specifically integrated with Anthropic's thinking models.
  • Token Tracking: Detailed tracking of input, output, cached, and reasoning tokens across different providers.

Related

  • Dispatch
  • Project
  • Project
  • Project
  • Project