Skip to content

jkrukowski/SwiftMistral

Repository files navigation

Mistral Swift Client

Use the Mistral Swift client to interact with the Mistral AI API.

Usage

Command line demo

$ swift run swift-mistral --api-key "<API_KEY>" --input "Hello, how are you?"

Command line help

$ swift run swift-mistral --help

In your own code

import SwiftMistral

let client = try MistralClient(apiKey: "<API_KEY>")
let chatCompletion = try await client.createChatCompletion(
    model: "<MODEL_ID>", 
    messages: [.init(role: .user, content: "<YOUR_MESSAGE>")]
)
for try await chat in chatCompletion {
    for choice in chat.choices {
        if let delta = choice.delta, let content = delta.content {
            // Do something with the response
        }
    }
}

Format code

$ swift package plugin --allow-writing-to-package-directory swiftformat

Tests

$ swift test

About

Swift client library for Mistral AI platform

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages