openai_ruby 0.5.3 → 0.5.5

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: c428b915e1985b7478318b5eee0938934ca406fec796bddab9f7499bbdc5feb6
4
+ data.tar.gz: d3e648abff19cd4bd266f05353500a4f8bcc1d221b376bb23ddbbd82eecdada7
5
5
  SHA512:
6
- metadata.gz: 89b7a75816ea1ca6aea907013db339e3c192f24889011653829fb2d4937c5e33685efbf529c406b1ded3d3bdc3747e31e54d795286206712d642b02ff50ba9d7
7
- data.tar.gz: 38b38f93be8a80d2b2341d06c73d9e93726aab9fb0f3961f6afebba42a9dbc98a109a19177152cd7902268655b115526fb6d1ae0afe8355d17b41102ec225cf3
6
+ metadata.gz: 2b4eaf9d508d7e904a21bec16456dd0dec8a36b2bb18d88111a61af91fcef67eecc94979c857bac14bf6f8cde9154b55ffd62e877bd766023fe1585ca2af82cb
7
+ data.tar.gz: 9bd6e7d5a8933e78abb8282fbbea3fb850952392247bb3fed6fb30423d4072a42e20f8673d7ffec760a6061e5e46eef64e8c584b6414cc0610eab813a90306af
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.5] - 2026-08-03
4
+
5
+ - Avoid mutating request parameters in chat completion and speech requests, including frozen nested schemas.
6
+
3
7
  ## [0.1.0] - 2023-02-14
4
8
 
5
9
  - Initial release
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.5)
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
@@ -23,8 +23,7 @@ module OpenAI
23
23
  def create_chat_completion(params = {})
24
24
  parser = EventStreamParser::Parser.new
25
25
 
26
- params.deep_stringify_keys!
27
- if params["stream"]
26
+ if streaming?(params)
28
27
  connection.post("/v1/chat/completions") do |req|
29
28
  req.body = params.to_json
30
29
  req.options.on_data = proc do |chunk, _overall_received_bytes, env|
@@ -52,7 +51,6 @@ module OpenAI
52
51
  end
53
52
 
54
53
  def create_speech(params = {})
55
- params.deep_stringify_keys!
56
54
  connection.post("/v1/audio/speech", params.to_json)
57
55
  end
58
56
 
@@ -61,17 +59,15 @@ module OpenAI
61
59
  end
62
60
 
63
61
  def create_realtime_call(sdp_offer:, session: nil)
64
- uri = "#{base_uri}/v1/realtime/calls"
65
-
66
62
  if session
67
63
  boundary, body = build_multipart_body(sdp_offer, session)
68
- Faraday.post(uri) do |req|
64
+ connection.post("/v1/realtime/calls") do |req|
69
65
  req.headers["Authorization"] = "Bearer #{api_key}"
70
66
  req.headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
71
67
  req.body = body
72
68
  end
73
69
  else
74
- Faraday.post(uri) do |req|
70
+ connection.post("/v1/realtime/calls") do |req|
75
71
  req.headers["Content-Type"] = "application/sdp"
76
72
  req.headers["Authorization"] = "Bearer #{api_key}"
77
73
  req.body = sdp_offer
@@ -100,6 +96,10 @@ module OpenAI
100
96
  default_value || maybe_json
101
97
  end
102
98
 
99
+ def streaming?(params)
100
+ params[:stream] || params["stream"]
101
+ end
102
+
103
103
  def build_multipart_body(sdp_offer, session)
104
104
  boundary = "----RubyFormBoundary#{SecureRandom.hex(16)}"
105
105
  parts = [
@@ -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.5"
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renny Ren