Skip to content

Commit 03337b4

Browse files
committed
Initial commit
0 parents  commit 03337b4

21 files changed

+786
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Xcode
2+
#
3+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4+
5+
## User settings
6+
xcuserdata/
7+
8+
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
9+
*.xcscmblueprint
10+
*.xccheckout
11+
12+
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
13+
build/
14+
DerivedData/
15+
*.moved-aside
16+
*.pbxuser
17+
!default.pbxuser
18+
*.mode1v3
19+
!default.mode1v3
20+
*.mode2v3
21+
!default.mode2v3
22+
*.perspectivev3
23+
!default.perspectivev3
24+
25+
## Obj-C/Swift specific
26+
*.hmap
27+
28+
## App packaging
29+
*.ipa
30+
*.dSYM.zip
31+
*.dSYM
32+
33+
## Playgrounds
34+
timeline.xctimeline
35+
playground.xcworkspace
36+
37+
# Swift Package Manager
38+
#
39+
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
40+
# Packages/
41+
# Package.pins
42+
# Package.resolved
43+
# *.xcodeproj
44+
#
45+
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
46+
# hence it is not needed unless you have added a package configuration file to your project
47+
# .swiftpm
48+
49+
.build/
50+
51+
# CocoaPods
52+
#
53+
# We recommend against adding the Pods directory to your .gitignore. However
54+
# you should judge for yourself, the pros and cons are mentioned at:
55+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
56+
#
57+
# Pods/
58+
#
59+
# Add this line if you want to avoid checking in source code from the Xcode workspace
60+
# *.xcworkspace
61+
62+
# Carthage
63+
#
64+
# Add this line if you want to avoid checking in source code from Carthage dependencies.
65+
# Carthage/Checkouts
66+
67+
Carthage/Build/
68+
69+
# Accio dependency management
70+
Dependencies/
71+
.accio/
72+
73+
# fastlane
74+
#
75+
# It is recommended to not store the screenshots in the git repo.
76+
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
77+
# For more information about the recommended setup visit:
78+
# https://docs.fastlane.tools/best-practices/source-control/#source-control
79+
80+
fastlane/report.xml
81+
fastlane/Preview.html
82+
fastlane/screenshots/**/*.png
83+
fastlane/test_output
84+
85+
# Code Injection
86+
#
87+
# After new code Injection tools there's a generated folder /iOSInjectionProject
88+
# https://github.com/johnno1962/injectionforxcode
89+
90+
iOSInjectionProject/

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Igor
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.swift

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// swift-tools-version: 5.7
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "openai-async-image-swiftui",
8+
platforms: [.iOS(.v15), .macOS(.v12), .watchOS(.v8), .tvOS(.v15)],
9+
products: [
10+
// Products define the executables and libraries a package produces, and make them visible to other packages.
11+
.library(
12+
name: "openai-async-image-swiftui",
13+
targets: ["openai-async-image-swiftui"]),
14+
],
15+
dependencies: [
16+
// Dependencies declare other packages that this package depends on.
17+
.package(url: "https://github.com/The-Igor/async-http-client.git", branch: "main")
18+
],
19+
targets: [
20+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
21+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
22+
.target(
23+
name: "openai-async-image-swiftui",
24+
dependencies: ["async-http-client"]),
25+
.testTarget(
26+
name: "openai-async-image-swiftuiTests",
27+
dependencies: ["openai-async-image-swiftui"]),
28+
]
29+
)

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# OpenAI AsyncImage SwiftUI
2+
3+
SwiftUI view that asynchronously loads and displays an OpenAI image from open API
4+
5+
## Features
6+
- [x] Multiplatform
7+
- [x] Customizable in term of SwiftUI Image specs [renderingMode, resizable, antialiased...]
8+
- [x] Based on interfaces not implementations
9+
10+
![The concept](https://github.com/The-Igor/async-http-client/blob/main/img/concept.png)
11+
12+
## How to use
13+
14+
### 1. Get your API key from OpenAI
15+
[Where do I find my Secret API Key?](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key)
16+
17+
18+
### 2. Override default loader at Environment with you apiKey
19+
```swift
20+
@Environment(\.openAIDefaultLoader) var loader : OpenAIDefaultLoader
21+
22+
let apiKey = "*******************"
23+
let endpoint = OpenAIImageEndpoint.get(with: apiKey)
24+
let loader = OpenAIDefaultLoader(endpoint: endpoint)
25+
26+
ContentView()
27+
.environment(\.openAIDefaultLoader, loader)
28+
```
29+
30+
### 3. Add **OpenAIAsyncImage** to your code
31+
32+
```swift
33+
OpenAIAsyncImage(prompt: .constant("sun"))
34+
.frame(width: 125, height: 125)
35+
```
36+
or with custom **ViewBuilder**
37+
38+
```swift
39+
OpenAIAsyncImage(prompt: $imageText, size: .dpi1024){ state in
40+
switch state{
41+
case .loaded(let image) :
42+
image
43+
.resizable()
44+
.scaledToFill()
45+
case .loadError(let error) : Text(error.localizedDescription)
46+
case .loading : ProgressView()
47+
}
48+
}
49+
```
50+
51+
| Param | Description |
52+
| --- | --- |
53+
| prompt | A text description of the desired image(s). The maximum length is 1000 characters |
54+
| size | The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 |
55+
| tpl | Custom view builder tpl |
56+
| loader | Custom loader if you need something specific|
57+
58+
59+
## Documentation(API)
60+
- You need to have Xcode 13 installed in order to have access to Documentation Compiler (DocC)
61+
- Go to Product > Build Documentation or **⌃⇧⌘ D**
62+
63+
## SwiftUI example for the package
64+
65+
[OpenAI AsyncImage SwiftUI example](https://github.com/The-Igor/openai-async-image-swiftui-example)

0 commit comments

Comments
 (0)