Skip to content

Commit 89db725

Browse files
Merge pull request #141 from gsabran/lint
Add linter
2 parents 8545399 + 5233d63 commit 89db725

File tree

159 files changed

+18904
-17251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+18904
-17251
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will build a Swift project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift
3+
4+
name: CI tests
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build_and_test:
14+
runs-on: macos-latest
15+
steps:
16+
- uses: swift-actions/setup-swift@v2
17+
with:
18+
swift-version: "6.0.1"
19+
- name: Get swift version
20+
run: swift --version
21+
- uses: actions/checkout@v4
22+
- name: Build
23+
run: swift build -q
24+
- name: Run tests
25+
run: swift test -q
26+
27+
lint:
28+
runs-on: macos-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
- name: Set up Homebrew
32+
id: set-up-homebrew
33+
uses: Homebrew/actions/setup-homebrew@master
34+
- name: Install swiftformat
35+
run: brew install swiftformat
36+
- name: Run linter
37+
run: swiftformat --config rules.swiftformat .
38+
- name: Verify that `swiftformat --config rules.swiftformat .` did not change outputs (if it did, please re-run it and re-commit!)
39+
run: git diff --exit-code

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
### Linting:
3+
```bash
4+
brew install swiftformat
5+
swiftformat --config rules.swiftformat .
6+
```

Examples/SwiftOpenAIExample/SwiftOpenAIExample/AIProxyIntroView.swift

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,65 @@
55
// Created by Lou Zell on 3/27/24.
66
//
77

8-
import SwiftUI
98
import SwiftOpenAI
9+
import SwiftUI
1010

1111
struct AIProxyIntroView: View {
1212

13-
@State private var partialKey = ""
14-
@State private var serviceURL = ""
13+
var body: some View {
14+
NavigationStack {
15+
VStack {
16+
Spacer()
17+
VStack(spacing: 24) {
18+
TextField("Enter partial key", text: $partialKey)
19+
TextField("Enter your service's URL", text: $serviceURL)
20+
}
21+
.padding()
22+
.textFieldStyle(.roundedBorder)
1523

16-
private var canProceed: Bool {
17-
return !(self.partialKey.isEmpty || self.serviceURL.isEmpty)
18-
}
24+
Text("You receive a partial key and service URL when you configure an app in the AIProxy dashboard")
25+
.font(.caption)
1926

20-
var body: some View {
21-
NavigationStack {
22-
VStack {
23-
Spacer()
24-
VStack(spacing: 24) {
25-
TextField("Enter partial key", text: $partialKey)
26-
TextField("Enter your service's URL", text: $serviceURL)
27-
}
27+
NavigationLink(destination: OptionsListView(
28+
openAIService: aiproxyService,
29+
options: OptionsListView.APIOption.allCases.filter { $0 != .localChat }))
30+
{
31+
Text("Continue")
2832
.padding()
29-
.textFieldStyle(.roundedBorder)
33+
.padding(.horizontal, 48)
34+
.foregroundColor(.white)
35+
.background(
36+
Capsule()
37+
.foregroundColor(canProceed ? Color(red: 64 / 255, green: 195 / 255, blue: 125 / 255) : .gray.opacity(0.2)))
38+
}
39+
.disabled(!canProceed)
40+
Spacer()
41+
Group {
42+
Text(
43+
"AIProxy keeps your OpenAI API key secure. To configure AIProxy for your project, or to learn more about how it works, please see the docs at ") +
44+
Text("[this link](https://www.aiproxy.pro/docs).")
45+
}
46+
.font(.caption)
47+
}
48+
.padding()
49+
.navigationTitle("AIProxy Configuration")
50+
}
51+
}
3052

31-
Text("You receive a partial key and service URL when you configure an app in the AIProxy dashboard")
32-
.font(.caption)
53+
@State private var partialKey = ""
54+
@State private var serviceURL = ""
3355

34-
NavigationLink(destination: OptionsListView(openAIService: aiproxyService, options: OptionsListView.APIOption.allCases.filter({ $0 != .localChat }))) {
35-
Text("Continue")
36-
.padding()
37-
.padding(.horizontal, 48)
38-
.foregroundColor(.white)
39-
.background(
40-
Capsule()
41-
.foregroundColor(canProceed ? Color(red: 64/255, green: 195/255, blue: 125/255) : .gray.opacity(0.2)))
42-
}
43-
.disabled(!canProceed)
44-
Spacer()
45-
Group {
46-
Text("AIProxy keeps your OpenAI API key secure. To configure AIProxy for your project, or to learn more about how it works, please see the docs at ") + Text("[this link](https://www.aiproxy.pro/docs).")
47-
}
48-
.font(.caption)
49-
}
50-
.padding()
51-
.navigationTitle("AIProxy Configuration")
52-
}
53-
}
56+
private var canProceed: Bool {
57+
!(partialKey.isEmpty || serviceURL.isEmpty)
58+
}
5459

55-
private var aiproxyService: OpenAIService {
56-
OpenAIServiceFactory.service(
57-
aiproxyPartialKey: partialKey,
58-
aiproxyServiceURL: serviceURL != "" ? serviceURL : nil
59-
)
60-
}
60+
private var aiproxyService: OpenAIService {
61+
OpenAIServiceFactory.service(
62+
aiproxyPartialKey: partialKey,
63+
aiproxyServiceURL: serviceURL != "" ? serviceURL : nil)
64+
}
6165
}
6266

6367
#Preview {
64-
ApiKeyIntroView()
68+
ApiKeyIntroView()
6569
}

Examples/SwiftOpenAIExample/SwiftOpenAIExample/ApiKeyIntroView.swift

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,57 @@
55
// Created by James Rochabrun on 10/19/23.
66
//
77

8-
import SwiftUI
98
import SwiftOpenAI
9+
import SwiftUI
1010

1111
struct ApiKeyIntroView: View {
12-
13-
@State private var apiKey = ""
14-
@State private var organizationIdentifier = ""
15-
@State private var localOrganizationID: String? = nil
16-
17-
var body: some View {
18-
NavigationStack {
19-
VStack {
20-
Spacer()
21-
VStack(spacing: 24) {
22-
TextField("Enter API Key", text: $apiKey)
23-
TextField("Enter Organization ID (Optional)", text: $organizationIdentifier)
24-
.onChange(of: organizationIdentifier) { _, newValue in
25-
if !newValue.isEmpty {
26-
localOrganizationID = newValue
27-
}
28-
}
12+
13+
var body: some View {
14+
NavigationStack {
15+
VStack {
16+
Spacer()
17+
VStack(spacing: 24) {
18+
TextField("Enter API Key", text: $apiKey)
19+
TextField("Enter Organization ID (Optional)", text: $organizationIdentifier)
20+
.onChange(of: organizationIdentifier) { _, newValue in
21+
if !newValue.isEmpty {
22+
localOrganizationID = newValue
23+
}
2924
}
25+
}
26+
.padding()
27+
.textFieldStyle(.roundedBorder)
28+
NavigationLink(destination: OptionsListView(
29+
openAIService: OpenAIServiceFactory.service(apiKey: apiKey, organizationID: localOrganizationID, debugEnabled: true),
30+
options: OptionsListView.APIOption.allCases.filter { $0 != .localChat }))
31+
{
32+
Text("Continue")
3033
.padding()
31-
.textFieldStyle(.roundedBorder)
32-
NavigationLink(destination: OptionsListView(openAIService: OpenAIServiceFactory.service(apiKey: apiKey, organizationID: localOrganizationID, debugEnabled: true), options: OptionsListView.APIOption.allCases.filter({ $0 != .localChat }))) {
33-
Text("Continue")
34-
.padding()
35-
.padding(.horizontal, 48)
36-
.foregroundColor(.white)
37-
.background(
38-
Capsule()
39-
.foregroundColor(apiKey.isEmpty ? .gray.opacity(0.2) : Color(red: 64/255, green: 195/255, blue: 125/255)))
40-
}
41-
.disabled(apiKey.isEmpty)
42-
Spacer()
43-
Group {
44-
Text("If you don't have a valid API KEY yet, you can visit ") + Text("[this link](https://platform.openai.com/account/api-keys)") + Text(" to get started.")
45-
}
46-
.font(.caption)
47-
}
48-
.padding()
49-
.navigationTitle("Enter OpenAI API KEY")
34+
.padding(.horizontal, 48)
35+
.foregroundColor(.white)
36+
.background(
37+
Capsule()
38+
.foregroundColor(apiKey.isEmpty ? .gray.opacity(0.2) : Color(red: 64 / 255, green: 195 / 255, blue: 125 / 255)))
39+
}
40+
.disabled(apiKey.isEmpty)
41+
Spacer()
42+
Group {
43+
Text("If you don't have a valid API KEY yet, you can visit ") +
44+
Text("[this link](https://platform.openai.com/account/api-keys)") + Text(" to get started.")
45+
}
46+
.font(.caption)
5047
}
51-
}
48+
.padding()
49+
.navigationTitle("Enter OpenAI API KEY")
50+
}
51+
}
52+
53+
@State private var apiKey = ""
54+
@State private var organizationIdentifier = ""
55+
@State private var localOrganizationID: String? = nil
56+
5257
}
5358

5459
#Preview {
55-
ApiKeyIntroView()
60+
ApiKeyIntroView()
5661
}
57-
58-

0 commit comments

Comments
 (0)