Skip to content

Commit fbaafab

Browse files
committed
README update
1 parent 1c4aea8 commit fbaafab

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A lightweight Swift package for interacting with OpenAI's `gpt-image-1` model to
1414

1515
- iOS 15.0+ / macOS 12.0+
1616
- Swift 5.7+
17-
- Valid OpenAI API key
17+
- Valid OpenAI API key with account verification
1818
- Network permission enabled
1919

2020
## 📦 Installation
@@ -23,4 +23,49 @@ Add to your project via **Swift Package Manager**:
2323

2424
```swift
2525
.package(url: "https://github.com/darya-varabei/OpenAIImageClient.git", from: "1.0.0")
26+
```
2627

28+
## 💡 Usage
29+
30+
For image generation (generate image from prompt):
31+
32+
```swift
33+
private let client = OpenAIImageClient(apiKey: "sk-***") // recommended to NOT store in code for production apps
34+
35+
let prompt = "Generate an image of a spaceship"
36+
37+
do {
38+
let results = try await client.generateImage(prompt: prompt, size: .x1536x1024)
39+
if let data = results.first?.data {
40+
image = UIImage(data: data)
41+
}
42+
} catch {
43+
self.error = error.localizedDescription
44+
}
45+
```
46+
47+
48+
For image edit (edit provided images according to provided prompt):
49+
50+
```swift
51+
private let client = OpenAIImageClient(apiKey: "sk-***") // recommended to NOT store in code for production apps
52+
53+
let prompt = "Make the room look like a spaceship"
54+
55+
let images = [UIImage(named: "result")!.pngData()!]
56+
57+
do {
58+
let results = try await client.editImages(images: images, prompt: prompt)
59+
if let data = results.first {
60+
image = UIImage(data: data)
61+
}
62+
} catch {
63+
self.error = error.localizedDescription
64+
}
65+
```
66+
67+
## 🔮 To be added
68+
69+
- Test coverage
70+
- More OpenAI requst parameters
71+
- Anything else proposed by community :)

0 commit comments

Comments
 (0)