https://github.com/nathanborror/swift-mistral
An easy way to use the Mistral platform in Swift.
https://github.com/nathanborror/swift-mistral
llm mistral mixtral swift
Last synced: 6 months ago
JSON representation
An easy way to use the Mistral platform in Swift.
- Host: GitHub
- URL: https://github.com/nathanborror/swift-mistral
- Owner: nathanborror
- License: mit
- Created: 2024-01-03T21:07:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-02T16:58:58.000Z (about 1 year ago)
- Last Synced: 2025-05-02T17:23:28.505Z (about 1 year ago)
- Topics: llm, mistral, mixtral, swift
- Language: Swift
- Homepage:
- Size: 2.76 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Swift Mistral
An unofficial Swift client library for interacting with the [Mistral API](https://docs.mistral.ai).
## Requirements
- Swift 5.9+
- iOS 16+
- macOS 13+
- watchOS 9+
- tvOS 16+
## Installation
Add the following to your `Package.swift` file:
```swift
Package(
dependencies: [
.package(url: "https://github.com/nathanborror/swift-mistral", branch: "main"),
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "Mistral", package: "swift-mistra"),
]
),
]
)
```
## Usage
### Chat Completion
```swift
import Mistral
let client = Client(apiKey: MISTRAL_API_KEY)
let request = ChatRequest(
model: "mistral-large-latest",
messages: [
.init(role: .system, content: [.init(text: "You are a helpful assistant.")]),
.init(role: .user, content: [.init(text: "Hello, Mistral!")])
]
)
do {
let response = try await client.chatCompletions(request)
print(response.completion_message.content.text)
} catch {
print(error)
}
```
### List Models
```swift
import Mistral
let client = Client(apiKey: MISTRAL_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
$ ./mistral
OVERVIEW: A utility for interacting with the Mistral API.
USAGE: mistral
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
models Returns available models.
chat-completion Completes a chat request.
See 'cli help ' for detailed help.
```