feat(demo): provider picker for OpenAI-compatible hosts#429
Open
tsushanth wants to merge 1 commit into
Open
Conversation
Closes MacPaw#308. Adds an `APIProvider` enum and a SwiftUI picker in `APIKeyModalView` so the Demo can talk to any OpenAI-compatible endpoint without code changes. Selecting `Gemini`, `Groq`, or `OpenRouter` auto-populates host + basePath; selecting `Custom…` makes both fields editable. Provider, host, base path, and API key are all persisted via `@AppStorage`, so they survive relaunches. `APIProvidedView` now builds the `OpenAI.Configuration` from these stored values and rewires the stores on any change.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a provider picker and persistent host/basePath configuration to the Demo app so it can target OpenAI-compatible endpoints without editing source (closes #308).
Changes:
- Introduces
APIProviderwith predefined host/basePath defaults plus aCustom…option. - Extends
APIKeyModalViewUI to select provider and edit host/basePath when custom, persisting values via@AppStorage. - Updates
APIProvidedViewto buildOpenAI.Configurationfrom stored host/basePath and rewire clients when those values change.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Demo/Demo.xcodeproj/project.pbxproj | Adds APIProvider.swift to the Demo target. |
| Demo/App/DemoApp.swift | Persists provider/host/basePath and wires bindings into the root views. |
| Demo/App/APIProvider.swift | Defines provider presets (host + basePath) and display names. |
| Demo/App/APIProvidedView.swift | Builds OpenAI.Configuration from persisted values and rewires stores on change. |
| Demo/App/APIKeyModalView.swift | Adds provider picker + host/basePath controls and commits config to storage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+123
to
127
| private static func makeConfiguration(apiKey: String, host: String, basePath: String) -> OpenAI.Configuration { | ||
| let resolvedHost = host.isEmpty ? "api.openai.com" : host | ||
| let resolvedBasePath = basePath.isEmpty ? "/v1" : basePath | ||
| return OpenAI.Configuration(token: apiKey, host: resolvedHost, basePath: resolvedBasePath) | ||
| } |
| imageStore.openAIClient = client | ||
| assistantStore.openAIClient = client | ||
| miscStore.openAIClient = client | ||
| responsesStore.client = client.responses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Closes #308.
The Demo is hardcoded to `api.openai.com`, so testing against any other OpenAI-compatible endpoint (Gemini's compat layer, Groq, OpenRouter, a local server, etc.) requires editing source. The issue specifically asks for a predefined provider picker that auto-populates host/basePath, with a "Custom…" escape hatch for everything else, and persistence across launches.
What
Screenshots / behaviour
Build
`xcodebuild -project Demo/Demo.xcodeproj -scheme Demo -destination 'generic/platform=iOS Simulator' build` → `** BUILD SUCCEEDED **`.
Scope
SDK code is untouched — this is purely a Demo improvement, as the issue requested. Happy to follow up with a similar picker in the iOS example or take docs PRs separately.