Giter Club home page Giter Club logo

ai's Introduction

Important

This package is presently in its alpha stage of development

Swift

Supported Platforms

macos   macos   macos   macos   macos

AI

The definitive, open-source Swift framework for interfacing with generative AI.

Installation

Swift Package Manager

  1. Open your Swift project in Xcode.
  2. Go to File -> Add Package Dependency.
  3. In the search bar, enter this URL.
  4. Choose the version you'd like to install.
  5. Click Add Package.

Usage

Import the framework

+ import AI

Initialize a model

Initialize an instance of LLMRequestHandling with an API provider of your choice. Here's an example:

import AI
import OpenAI

let llm: any LLMRequestHandling = OpenAI.APIClient(apiKey: "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

You can now use llm as an interface to an LLM as provided by the underlying provider.

Chat completions

In the snippet earlier, we initialized an instance of LLMRequestHandling with OpenAI as the underlying provider.

OpenAI offers a number of chat models, like GPT-3.5 and GPT-4.

A chat model is a language model that can be given a set of messages and asked to generate a response that follows in turn.

You can use the LLMRequestHandling.complete(_:model:) function to generate a chat completion for a specific model of your choice. For example:

/// ...

let llm: any LLMRequestHandling = OpenAI.APIClient(apiKey: "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

let messages: [AbstractLLM.ChatMessage] = [
    AbstractLLM.ChatMessage(
        role: .system,
        body: "You are an extremely intelligent assistant."
    ),
    AbstractLLM.ChatMessage(
        role: .user,
        body: "Sup?"
    )
]

let result = try await llm.complete(
    messages,
    model: OpenAI.Model.chat(.gpt_4)
)

print(result) // "Hello! How can I assist you today?"

In this example we constructed an ordered array of chat messages, and used our llm instance to generate a completion using GPT-4.

Roadmap

  • OpenAI
  • Anthropic
  • Mistral
  • Ollama
  • Perplexity
  • Groq

Acknowledgements

License

This package is licensed under the MIT License.

ai's People

Contributors

vmanot avatar archetapp avatar pmanot avatar natashatherobot avatar

Stargazers

 avatar mdewar avatar  avatar Mason Dierkes avatar  avatar id-2 avatar Mayank Gupta avatar  avatar Ari S. avatar wangxuncai avatar Kami avatar  avatar batuhan avatar Nic Dedual avatar Jay avatar  avatar Winston Maragh avatar 佐毅 avatar grep avatar  avatar  avatar Nick Arner avatar

Watchers

 avatar  avatar Mayank Gupta avatar  avatar

Forkers

pmanot

ai's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.