swift-mistral

main

Swift client library for Mistral AI platform
jkrukowski/SwiftMistral

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

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Wed Apr 17 2024 17:57:18 GMT-0900 (Hawaii-Aleutian Daylight Time)