Skip to content

modelrunner/modelrunner-swift

Repository files navigation

The modelrunner.ai Swift Client

About the Project

The ModelrunerClient is a robust and user-friendly Swift package designed for seamless integration of modelrunner AI models into Swift projects. This library, developed in pure Swift, provides developers with simple APIs to interact with AI models, suitable for both iOS and macOS platforms.

Getting Started

The ModelrunerClient library serves as a client for modelrunner AI models. Before using this library, ensure you've set up your models as per the quickstart guide.

Client Library

This Swift client library is crafted as a lightweight layer atop Swift's networking standards like URLSession. It ensures hassle-free integration into your existing Swift codebase. The library is designed to address the nuances of Swift and Apple's ecosystem, ensuring smooth operation across different Apple platforms.

Note: Make sure to review the modelrunner getting started guide to acquire your credentials and register your functions.

  1. Add ModelrunerClient as a dependency in your Swift Package Manager.

  2. Set up the client instance:

    import ModelrunerClient
    let modelrunner = ModelrunerClient.withCredentials(.keyPair("MODELRUNNER_KEY"))
    
    // You can also use a proxy to protect your credentials
    // let modelrunner = ModelrunerClient.withProxy("http://localhost:3333/api/modelrunner/proxy")
  3. Use modelrunner.subscribe to dispatch requests to the model API:

    let result = try await modelrunner.subscribe(to: "text-to-image",
        input: [
            "prompt": "a cute shih-tzu puppy",
            "model_name": "stabilityai/stable-diffusion-xl-base-1.0",
            "image_size": "square_hd"
        ]) { update in
            print(update)
        }

Notes:

  • Replace text-to-image with a valid model id. Check modelrunner.ai/models for all available models.
  • It fully relies on async/await for asynchronous programming.
  • The result type in Swift will be a [String: Any] and the entries depend on the API output schema.
  • The Swift client also supports typed inputs and outputs through Codable.

Sample apps

Check the Sources/Samples folder for a handful of sample applications using the ModelrunerClient.

Open them with xed to quickly start playing with

xed Sources/Samples/ModelrunnerSampleApp

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make to the Swift version of the client are greatly appreciated.

License

Distributed under the MIT License. See LICENSE for more information.

About

Use AI models with an easy API using modelrunner.ai Swift Client

Resources

License

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages