Skip to content

Commit ca23a7e

Browse files
authored
Add serviceURL to AIProxy integration (#63)
1 parent 20aaf77 commit ca23a7e

File tree

5 files changed

+112
-80
lines changed

5 files changed

+112
-80
lines changed

Examples/SwiftOpenAIExample/SwiftOpenAIExample/AIProxyIntroView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ import SwiftOpenAI
1111
struct AIProxyIntroView: View {
1212

1313
@State private var partialKey = ""
14+
@State private var serviceURL = ""
1415

1516
var body: some View {
1617
NavigationStack {
1718
VStack {
1819
Spacer()
1920
VStack(spacing: 24) {
2021
TextField("Enter partial key", text: $partialKey)
22+
TextField("Enter your service's URL", text: $serviceURL)
2123
}
2224
.padding()
2325
.textFieldStyle(.roundedBorder)
2426

25-
Text("You receive a partial key when you configure an app in the AIProxy dashboard")
27+
Text("You receive a partial key and service URL when you configure an app in the AIProxy dashboard")
2628
.font(.caption)
2729

2830
NavigationLink(destination: OptionsListView(openAIService: aiproxyService, options: OptionsListView.APIOption.allCases.filter({ $0 != .localChat }))) {
@@ -47,7 +49,10 @@ struct AIProxyIntroView: View {
4749
}
4850

4951
private var aiproxyService: some OpenAIService {
50-
OpenAIServiceFactory.service(aiproxyPartialKey: partialKey)
52+
OpenAIServiceFactory.service(
53+
aiproxyPartialKey: partialKey,
54+
aiproxyServiceURL: serviceURL != "" ? serviceURL : nil
55+
)
5156
}
5257
}
5358

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,15 @@ To configure AIProxy, see the instructions [here](#aiproxy).
8888
1. Open your Swift project in Xcode.
8989
2. Go to `File` -> `Add Package Dependency`.
9090
3. In the search bar, enter [this URL](https://github.com/jamesrochabrun/SwiftOpenAI).
91-
4. Choose the version you'd like to install.
91+
4. Choose the version you'd like to install (see the note below).
9292
5. Click `Add Package`.
9393

94+
Note: Xcode has a quirk where it defaults an SPM package's upper limit to 2.0.0. This package is beyond that
95+
limit, so you should not accept the defaults that Xcode proposes. Instead, enter the lower bound of the
96+
[release version](https://github.com/jamesrochabrun/SwiftOpenAI/releases) that you'd like to support, and then
97+
tab out of the input box for Xcode to adjust the upper bound. Alternatively, you may select `branch` -> `main`
98+
to stay on the bleeding edge.
99+
94100
## Usage
95101

96102
To use SwiftOpenAI in your project, first import the package:
@@ -3022,10 +3028,11 @@ SwiftOpenAI supports proxying requests through AIProxy with two changes to your
30223028
Use:
30233029

30243030
let service = OpenAIServiceFactory.service(
3025-
aiproxyPartialKey: "hardcode_partial_key_here",
3031+
aiproxyPartialKey: "your_partial_key_goes_here",
3032+
aiproxyServiceURL: "your_service_url_goes_here"
30263033
)
30273034

3028-
The `aiproxyPartialKey` value is provided to you on the [AIProxy developer dashboard](https://developer.aiproxy.pro)
3035+
The `aiproxyPartialKey` and `aiproxyServiceURL` values are provided to you on the [AIProxy developer dashboard](https://developer.aiproxy.pro)
30293036

30303037
2. Add an `AIPROXY_DEVICE_CHECK_BYPASS' env variable to Xcode. This token is provided to you in the AIProxy
30313038
developer dashboard, and is necessary for the iOS simulator to communicate with the AIProxy backend.

0 commit comments

Comments
 (0)