Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
A Swift client library for interacting with Ollama. Supports structured outputs, tool use, and vision models.
| Date | Stars |
|---|---|
| 2026-07-31 | 453 |
| 2026-08-01 | 453 |
| 2026-08-02 | 453 |
| 2026-08-06 | 453 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# Ollama Swift Client
A Swift client library for interacting with the
[Ollama API](https://github.com/ollama/ollama/blob/main/docs/api.md).
## Requirements
- Swift 5.7+
- macOS 13+
- [Ollama](https://ollama.com)
## Installation
### Swift Package Manager
Add the following to your `Package.swift` file:
```swift
.package(url: "https://github.com/mattt/ollama-swift.git", from: "1.8.0")
```
## Usage
> [!NOTE]
> The tests and example code for this library use the
> [llama3.2](https://ollama.com/library/llama3.2) model.
> Run the following command to download the model to run them yourself:
>
> ```
> ollama pull llama3.2
> ```
### Initializing the client
```swift
import Ollama
// Use the default client (http://localhost:11434)
let client = Client.default
// Or create a custom client
let customClient = Client(host: URL(string: "http://your-ollama-host:11434")!, userAgent: "MyApp/1.0")
```
### Generating text
Generate text using a specified model:
```swift
do {
let response = try await client.generate(
model: "llama3.2",
prompt: "Tell me a joke about Swift programming.",
options: [
"temperature": 0.7,
"max_tokens": 100
],
keepAlive: .minutes(10) // Keep model loaded for 10 minutes
)
print(response.response)
} catch {
print("Error: \(error)")
}
```
#### Streaming text generation
Generate text in a streaming fashion to receive responses in real-time:
```swift
do {
let stream = try await client.generateStream(
model: "llama3.2",
prompt: "Tell me a joke about Swift programming.",
options: [
"temperature": 0.7,
"max_tokens": 100
]
)
var fullResponse = ""
for try await chunk in stream {
// Process each chunk of the response as it arrives
print(chunk.response, terminator: "")
fullResponse += chunk.response
}
print("\nFull response: \(fullResponse)")
} catch {
print("Error: \(error)")
}
```
### Chatting with a model
Generate a chat completion:
```swift
do {
let response = try await client.chat(
model: "llama3.2",
messages: [
.system("You are a helpful assistant."),
.user("In which city is Apple Inc. located?")
],
keepAlive: .minutes(10) // Keep model loaded for 10 minutes
)
print(response.message.content)
} catch {
print("Error: \(error)")
}
```
#### Streaming chat responses
Stream chat responses to get real-time partial completions:
```swift
do {
let stream = try await client.chatStream(
model: "llama3.2",
messages: [
.system("You are a helpful assistant."),
.user("Write a short poem about Swift programming.")
]
)
var fullContent = ""
for try await chunk in stream {
// Process each chunk of the message as it arrives
if let content = chunk.message.content {
print(content, terminator: "")
fullContent += content
}
}
print("\nComplete poem: \(fullContent)")
} catch {
print("Error: \(error)")
}
```
You can also stream chat responses when using tools:
```swift
do {
let stream = try await client.chatStream(
model: "llama3.2",
messages: [
.system("You are a helpful assistant that can check the weather."),
.user("What's the weather like in Portland?")
],
tools: [weatherTool]
)
for try await chunk in stream {
// Check if the model is making tool calls
if let toolCalls = chunk.message.toolCalls, !toolCalls.isEmpty {
print("Model is requesting tool: \(toolCalls[0].function.name)")
}
// Print content from the message as it streams
if let content = chunk.message.content {
print(content, terminator: "")
}
// Check if this is the final chunk
if chunk.done {
print("\nResponse completeExcerpt of 14,877 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:4e2f9f47d3232853, llm:description: 'A Swift client library for interacting with Ollama. Supports structured outputs, tool use, and vision models.' topics: ['ollama','swift']
matched fp:4e2f9f47d3232853, llm:description: 'A Swift client library for interacting with Ollama. Supports structured outputs, tool use, and vision models.' topics: ['ollama','swift']
matched fp:4e2f9f47d3232853, llm:description: 'A Swift client library for interacting with Ollama. Supports structured outputs, tool use, and vision models.' topics: ['ollama','swift']