openai_ruby 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +49 -0
- data/lib/openai_ruby/client.rb +2 -4
- data/lib/openai_ruby/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 594ce65bf8ef1e8ef1202b306b400a231bfd0977ca26677bbc2e4420fb8c8d72
|
|
4
|
+
data.tar.gz: 852da6bdffa4213f39eb830929377718b043d411a837cca4dc0fab134620ed0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9496bd88696075720d6f1a79d7a15723f8eaa9663b8a629e74190248d6d4180ff8f51ff631bc66280acc74196ebaf305b087d49626a29c281a1e0449ec3515a9
|
|
7
|
+
data.tar.gz: 7aca0a20dd3bc82051aa2c101f2f4d407a108e55ad823aa893fe444b8ea140df579226c23b63b26b2a11b5ec795be76bc0cc8ba4a6b17854144be15f94db296a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -92,8 +92,57 @@ p response.dig("choices", 0, "text") # "What is the date today?\n"
|
|
|
92
92
|
|
|
93
93
|
### Image
|
|
94
94
|
|
|
95
|
+
https://platform.openai.com/docs/api-reference/images
|
|
96
|
+
|
|
97
|
+
Generate an image:
|
|
98
|
+
|
|
95
99
|
```ruby
|
|
100
|
+
require "base64"
|
|
101
|
+
|
|
102
|
+
res = client.images.generate(
|
|
103
|
+
model: "gpt-image-2",
|
|
104
|
+
prompt: "A watercolor painting of a ruby gem on a desk",
|
|
105
|
+
size: "1024x1024"
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
response = JSON.parse(res.body)
|
|
109
|
+
image_data = response.dig("data", 0, "b64_json")
|
|
110
|
+
|
|
111
|
+
File.binwrite("ruby-gem.png", Base64.decode64(image_data)) if image_data
|
|
112
|
+
```
|
|
96
113
|
|
|
114
|
+
Edit one or more images:
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
require "base64"
|
|
118
|
+
|
|
119
|
+
File.open("ruby-gem.png", "rb") do |image|
|
|
120
|
+
res = client.images.edit(
|
|
121
|
+
model: "gpt-image-2",
|
|
122
|
+
image: image,
|
|
123
|
+
prompt: "Add a small OpenAI logo sticker to the desk",
|
|
124
|
+
size: "1024x1024"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
response = JSON.parse(res.body)
|
|
128
|
+
image_data = response.dig("data", 0, "b64_json")
|
|
129
|
+
|
|
130
|
+
File.binwrite("ruby-gem-edited.png", Base64.decode64(image_data)) if image_data
|
|
131
|
+
end
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
You can also pass multiple images when editing:
|
|
135
|
+
|
|
136
|
+
```ruby
|
|
137
|
+
File.open("image-1.png", "rb") do |image_1|
|
|
138
|
+
File.open("image-2.png", "rb") do |image_2|
|
|
139
|
+
client.images.edit(
|
|
140
|
+
model: "gpt-image-2",
|
|
141
|
+
image: [image_1, image_2],
|
|
142
|
+
prompt: "Combine these images into one cohesive scene"
|
|
143
|
+
)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
97
146
|
```
|
|
98
147
|
|
|
99
148
|
## Development
|
data/lib/openai_ruby/client.rb
CHANGED
|
@@ -61,17 +61,15 @@ module OpenAI
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def create_realtime_call(sdp_offer:, session: nil)
|
|
64
|
-
uri = "#{base_uri}/v1/realtime/calls"
|
|
65
|
-
|
|
66
64
|
if session
|
|
67
65
|
boundary, body = build_multipart_body(sdp_offer, session)
|
|
68
|
-
|
|
66
|
+
connection.post("/v1/realtime/calls") do |req|
|
|
69
67
|
req.headers["Authorization"] = "Bearer #{api_key}"
|
|
70
68
|
req.headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
|
|
71
69
|
req.body = body
|
|
72
70
|
end
|
|
73
71
|
else
|
|
74
|
-
|
|
72
|
+
connection.post("/v1/realtime/calls") do |req|
|
|
75
73
|
req.headers["Content-Type"] = "application/sdp"
|
|
76
74
|
req.headers["Authorization"] = "Bearer #{api_key}"
|
|
77
75
|
req.body = sdp_offer
|
data/lib/openai_ruby/version.rb
CHANGED