Build AI Studio for macOS

Add branded startup, Ollama and MLX inference, persistent chat and document retrieval, confirmed MCP tools, and reproducible build and test scripts.
This commit is contained in:
Mark Gregory
2026-11-16 13:14:00 +00:00
parent 4196ab0594
commit 2238df4631
22 changed files with 3004 additions and 18 deletions
+22 -18
View File
@@ -1,33 +1,37 @@
# AI Studio
AI Studio is a native SwiftUI chat app for Apple silicon Macs running macOS 14 or later. Open `AIStudio.xcodeproj`, select the shared **AIStudio** scheme, and run it on **My Mac**. Xcode resolves the pinned Swift packages on the first build. The command-line equivalents are `./build.sh Debug` and `./test.sh`.
Native SwiftUI chat for Apple silicon Macs running macOS 14 or later. Open `AIStudio.xcodeproj` and run the shared **AIStudio** scheme on **My Mac**. Xcode resolves the pinned Swift packages on the first build.
## Set up inference
## 1. Set up a model
1. Open **AI Studio → Settings**. The default server is `http://127.0.0.1:11434`. Start Ollama, refresh installed models, and select a tag, or enter the tag directly. Pull, inspect, and delete models on the configured server from the same pane.
2. To use a remote Ollama server, enter its HTTP or HTTPS base URL. The server receives your prompt and the selected conversation context. Use HTTPS with a trusted server for remote inference. The client rejects redirects and currently has no custom authentication headers.
3. For native inference, choose a local MLX-compatible model folder containing configuration, tokenizer files, and safetensors weights. Use **MLX only** to force local generation, or keep **Prefer Ollama** to enable automatic MLX failover once a folder is configured. **Unload Model** releases the cached model.
4. Choose **Thinking** in the chat composer. The app passes Boolean or named effort settings to Ollama and displays separately reported reasoning in an expandable section. Use **Default** when a model does not support the selected mode. Native MLX currently uses the model's template defaults and presents emitted text as answer text.
- **Ollama:** In **Settings → Models**, refresh the installed list and select a tag. The default server is `http://127.0.0.1:11434`. Use the same pane to pull, inspect, and delete models. Enter a remote HTTP or HTTPS base URL to use another server. The optional bearer token stays in memory and requires HTTPS for remote servers.
- **MLX:** In **Settings → MLX Catalog**, download and select a pinned SmolLM2 or Qwen3 model. **Settings → Models** also accepts a local model folder with configuration, tokenizer files, and safetensors weights. **Use Model** selects on-device inference. **Prefer Ollama** can fall back to the configured MLX folder when Ollama fails before emitting output.
- **Thinking:** The composer sends Boolean or named effort settings to Ollama. Supported MLX templates expose Default, Off, and On. Reported reasoning appears in an expandable section. If an Ollama request is interrupted after emitting text, reasoning, or a tool call, the router keeps that backend. **Stop** cancels generation and retains any partial output.
The router stays on the original backend after it receives answer text, thinking text, or a tool call. Stop cancels the request and saves partial output with an interrupted label. The fallback is always on this Mac. There is no automatic retry against a second remote server.
## 2. Chat with documents
## Chat and memory
Use **Documents** in the conversation toolbar to import PDF, UTF-8 text, Markdown, or CSV. Turn on document excerpts in the composer to include up to four matched passages with numbered source titles. Retrieval combines SQLite full-text ranking and on-device Apple sentence embeddings where available. Scanned PDFs require a text layer. When Ollama is selected, document opt-in sends the chosen excerpts to the configured server.
Chats live in `~/Library/Application Support/AIStudio/studio.sqlite`. Backend settings are stored in macOS preferences. Each request includes up to 32 recent messages. Optional memory recalls up to four older user messages in the same conversation through SQLite keyword matching. It can be switched off in Settings. Deleting a conversation removes its messages and recall candidates together.
Chat history, older-message recall, and document indexes live in `~/Library/Application Support/AIStudio/studio.sqlite`. Documents are scoped to the selected conversation. Deleting a document removes its index and deleting a conversation removes its messages and documents. The app stores extracted excerpts and vectors locally. It leaves the original files in place.
## Code and verification
## 3. Run a tool
- `Inference.swift` defines streaming events, the routing policy and the MCP tool-client interface.
- `Ollama.swift` implements HTTP model management and NDJSON chat streaming. `MLXProvider.swift` loads a local checkpoint and streams generated tokens through MLX Swift LM.
- `Store.swift` owns SQLite operations. `StudioModel.swift` coordinates settings, routing and streaming state for SwiftUI.
- `./test.sh` runs the XCTest suite. Set the following environment variables to include local or remote Ollama and native MLX smoke tests. The models must already exist.
Open **Settings → MCP Tools**, enter an MCP HTTP endpoint, and choose **Discover Tools**. Select a tool, review the schema, enter its JSON arguments, and confirm the invocation. You can attach up to 8,000 characters of the result to the next message in the active conversation. The composer shows the attachment before it is sent.
The client supports Streamable HTTP with current stateless discovery and legacy initialization, session headers, and JSON or server-sent event responses. Remote MCP endpoints require HTTPS. Optional bearer tokens stay in memory. Tool calls require explicit confirmation and are sent once. Stdio, OAuth sign-in, and server-requested follow-up interactions are outside the supported MCP scope.
## Build and test
Use `./Scripts/build.sh Debug` or `./Scripts/build.sh Release`. Run `./Tests/test.sh` for XCTest, including the local MCP and Ollama management fixture. It requires Python 3 for the fixture and keeps its logs and results in the temporary build directory.
For opt-in live provider checks, use installed models or select a catalog download:
```sh
TEST_RUNNER_AISTUDIO_TEST_OLLAMA_URL=http://127.0.0.1:11434 \
TEST_RUNNER_AISTUDIO_TEST_OLLAMA_MODEL=your-installed-tag \
TEST_RUNNER_AISTUDIO_TEST_MLX_PATH=/path/to/local-model ./test.sh
TEST_RUNNER_AISTUDIO_TEST_MLX_PATH=/path/to/local-model \
TEST_RUNNER_AISTUDIO_TEST_MODEL_DOWNLOAD=qwen3-0.6b-4bit \
./Tests/test.sh
```
MCP readiness currently consists of the tool-client interface and a routing commitment event. MCP transport, server discovery, tool approval UI and dispatch remain future work. The app also lacks an MLX download catalog and semantic or document retrieval.
API references: [Ollama chat API](https://docs.ollama.com/api/chat), [MLX Swift LM](https://github.com/ml-explore/mlx-swift-lm/tree/2.29.3).
See `Docs/RELEASE.md` for packaging, signing, and notarization.