openai_ruby 0.5.4 → 0.5.6

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: 594ce65bf8ef1e8ef1202b306b400a231bfd0977ca26677bbc2e4420fb8c8d72
4
- data.tar.gz: 852da6bdffa4213f39eb830929377718b043d411a837cca4dc0fab134620ed0e
3
+ metadata.gz: 84416f248ba1af3cd564bdf72b9b125fe5995a10fea0c3b273115ed42123d1dd
4
+ data.tar.gz: 77228baf14fd26b1f85f843ea25da388d2d0d20e4f65ff53541f543fb9f6e30f
5
5
  SHA512:
6
- metadata.gz: 9496bd88696075720d6f1a79d7a15723f8eaa9663b8a629e74190248d6d4180ff8f51ff631bc66280acc74196ebaf305b087d49626a29c281a1e0449ec3515a9
7
- data.tar.gz: 7aca0a20dd3bc82051aa2c101f2f4d407a108e55ad823aa893fe444b8ea140df579226c23b63b26b2a11b5ec795be76bc0cc8ba4a6b17854144be15f94db296a
6
+ metadata.gz: 1c9a04302598fcb7926064079cca7b95517c07c46de1c0c29b23c132ac44f5cb36689add98691e2921f7adcc21039e9310772f7f1f273c1dc2c61fa78ef0f6f6
7
+ data.tar.gz: 34964a45e000c84fe68b3ad03a4ab49419cf49bfc39c8bff344c1a83a76bceac8c0cee3168691d94b52c38a1ff7630f539c09bb2fdbee8c4470041e37bf913a8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.6] - 2026-08-15
4
+
5
+ - Preserve complete error response bodies when streamed HTTP errors arrive in multiple chunks.
6
+
7
+ ## [0.5.5] - 2026-08-03
8
+
9
+ - Avoid mutating request parameters in chat completion and speech requests, including frozen nested schemas.
10
+
3
11
  ## [0.1.0] - 2023-02-14
4
12
 
5
13
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openai_ruby (0.5.4)
4
+ openai_ruby (0.5.6)
5
5
  event_stream_parser (~> 1.0)
6
6
  faraday (~> 2.7)
7
7
  faraday-multipart (~> 1.1)
@@ -20,27 +20,10 @@ module OpenAI
20
20
  )
21
21
  end
22
22
 
23
- def create_chat_completion(params = {})
24
- parser = EventStreamParser::Parser.new
23
+ def create_chat_completion(params = {}, &block)
24
+ return connection.post("/v1/chat/completions", params.to_json) unless streaming?(params)
25
25
 
26
- params.deep_stringify_keys!
27
- if params["stream"]
28
- connection.post("/v1/chat/completions") do |req|
29
- req.body = params.to_json
30
- req.options.on_data = proc do |chunk, _overall_received_bytes, env|
31
- if env && env.status != 200
32
- raise_error = Faraday::Response::RaiseError.new
33
- raise_error.on_complete(env.merge(body: try_parse_json(chunk)))
34
- end
35
-
36
- parser.feed(chunk) do |_type, data|
37
- yield(JSON.parse(data)) if block_given? && data != "[DONE]"
38
- end
39
- end
40
- end
41
- else
42
- connection.post("/v1/chat/completions", params.to_json)
43
- end
26
+ create_streaming_chat_completion(params, &block)
44
27
  end
45
28
 
46
29
  def create_edit(params = {})
@@ -52,7 +35,6 @@ module OpenAI
52
35
  end
53
36
 
54
37
  def create_speech(params = {})
55
- params.deep_stringify_keys!
56
38
  connection.post("/v1/audio/speech", params.to_json)
57
39
  end
58
40
 
@@ -98,6 +80,37 @@ module OpenAI
98
80
  default_value || maybe_json
99
81
  end
100
82
 
83
+ def streaming?(params)
84
+ params[:stream] || params["stream"]
85
+ end
86
+
87
+ def create_streaming_chat_completion(params, &block)
88
+ parser = EventStreamParser::Parser.new
89
+ error_body = +""
90
+ response = connection.post("/v1/chat/completions") do |req|
91
+ req.body = params.to_json
92
+ req.options.on_data = proc do |chunk, _overall_received_bytes, env|
93
+ handle_streaming_chunk(parser, error_body, chunk, env, &block)
94
+ end
95
+ end
96
+
97
+ raise_streaming_response_error(response, error_body) unless response.status == 200
98
+ response
99
+ end
100
+
101
+ def handle_streaming_chunk(parser, error_body, chunk, env)
102
+ return error_body << chunk unless env&.status == 200
103
+
104
+ parser.feed(chunk) do |_type, data|
105
+ yield(JSON.parse(data)) if block_given? && data != "[DONE]"
106
+ end
107
+ end
108
+
109
+ def raise_streaming_response_error(response, body)
110
+ error_env = response.env.merge(body: try_parse_json(body))
111
+ Faraday::Response::RaiseError.new.on_complete(error_env)
112
+ end
113
+
101
114
  def build_multipart_body(sdp_offer, session)
102
115
  boundary = "----RubyFormBoundary#{SecureRandom.hex(16)}"
103
116
  parts = [
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenAI
4
- VERSION = "0.5.4"
4
+ VERSION = "0.5.6"
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.4
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renny Ren