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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a554ff0eded8ed64b9fd4d8fc07a5e5d0651dd35e111d6d80d724ed19651fca1
4
- data.tar.gz: a91315b4f63e50ada7a9d90b372364b0c8e9068ea06de0e46570e4ac29b1be67
3
+ metadata.gz: 594ce65bf8ef1e8ef1202b306b400a231bfd0977ca26677bbc2e4420fb8c8d72
4
+ data.tar.gz: 852da6bdffa4213f39eb830929377718b043d411a837cca4dc0fab134620ed0e
5
5
  SHA512:
6
- metadata.gz: 89b7a75816ea1ca6aea907013db339e3c192f24889011653829fb2d4937c5e33685efbf529c406b1ded3d3bdc3747e31e54d795286206712d642b02ff50ba9d7
7
- data.tar.gz: 38b38f93be8a80d2b2341d06c73d9e93726aab9fb0f3961f6afebba42a9dbc98a109a19177152cd7902268655b115526fb6d1ae0afe8355d17b41102ec225cf3
6
+ metadata.gz: 9496bd88696075720d6f1a79d7a15723f8eaa9663b8a629e74190248d6d4180ff8f51ff631bc66280acc74196ebaf305b087d49626a29c281a1e0449ec3515a9
7
+ data.tar.gz: 7aca0a20dd3bc82051aa2c101f2f4d407a108e55ad823aa893fe444b8ea140df579226c23b63b26b2a11b5ec795be76bc0cc8ba4a6b17854144be15f94db296a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openai_ruby (0.5.3)
4
+ openai_ruby (0.5.4)
5
5
  event_stream_parser (~> 1.0)
6
6
  faraday (~> 2.7)
7
7
  faraday-multipart (~> 1.1)
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
@@ -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
- Faraday.post(uri) do |req|
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
- Faraday.post(uri) do |req|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenAI
4
- VERSION = "0.5.3"
4
+ VERSION = "0.5.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openai_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renny Ren