Skip to content

nathanborror/swift-llama

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Llama

An unofficial Swift client library for interacting with Meta's Llama API.

Requirements

  • Swift 5.9+
  • iOS 16+
  • macOS 13+
  • watchOS 9+
  • tvOS 16+

Installation

Add the following to your Package.swift file:

Package(
    dependencies: [
        .package(url: "https://github.com/nathanborror/swift-llama", branch: "main"),
    ],
    targets: [
        .target(
            name: "YourApp",
            dependencies: [
                .product(name: "Llama", package: "swift-llama"),
            ]
        ),
    ]
)

Usage

Chat Completion

import Llama

let client = Client(apiKey: LLAMA_API_KEY)

let request = ChatRequest(
    model: "Llama-4-Scout-17B-16E-Instruct-FP8",
    messages: [
        .init(role: .system, content: [.init(text: "You are a helpful llama.")]),
        .init(role: .user, content: [.init(text: "Hello, Llama!")])
    ]
)

do {
    let response = try await client.chatCompletions(request)
    print(response.completion_message.content.text)
} catch {
    print(error)
}

List Models

import Llama

let client = Client(apiKey: LLAMA_API_KEY)

do {
    let response = try await client.models()
    print(response.data.map { $0.id }.joined(separator: "\n"))
} catch {
    print(error)
}

Command Line Interface

$ make
$ ./llama
OVERVIEW: A utility for interacting with Meta's Llama API.

USAGE: llama <subcommand>

OPTIONS:
  --version               Show the version.
  -h, --help              Show help information.

SUBCOMMANDS:
  models                  Returns available models.
  chat                    Completes a chat request.
  chat-stream             Completes a chat streaming request.

  See 'cli help <subcommand>' for detailed help.

About

A Swift client library for interacting with Meta's Llama API.

Topics

Resources

License

Stars

Watchers

Forks