openai_ruby 0.5.5 → 0.6.0
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/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +15 -0
- data/lib/openai_ruby/client.rb +36 -19
- 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: a95f09a2242c8a67613fb0589cc480d8fd36f17b4fbf42d52a4f7969626e0427
|
|
4
|
+
data.tar.gz: e8be0ae8f3cffc9e163f47768d6e70750972f38af1b1aaae08b0f518d0c7c52e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 29fb10ed072c4b71cc5cd159903fa2a17c1cff924327837a9aabdd3e59c7733c72c19383a4b5a1a91ce2ae1824abcfde98a2de1738ac633efdca5b6cbd9d8e37
|
|
7
|
+
data.tar.gz: 4e799005b2565d0c51795ae4e0fec54658df56b962d065200f33044a06f2f7e22bb90288e0544247e1c140a284bed60462b716ca65d01f240a1cdce6456eec74
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.6.0] - 2026-08-20
|
|
4
|
+
|
|
5
|
+
- Add non-streaming and SSE streaming support for the Responses API through `OpenAI::Client#create_response`.
|
|
6
|
+
|
|
7
|
+
## [0.5.6] - 2026-08-15
|
|
8
|
+
|
|
9
|
+
- Preserve complete error response bodies when streamed HTTP errors arrive in multiple chunks.
|
|
10
|
+
|
|
3
11
|
## [0.5.5] - 2026-08-03
|
|
4
12
|
|
|
5
13
|
- Avoid mutating request parameters in chat completion and speech requests, including frozen nested schemas.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -76,6 +76,21 @@ res = client.create_chat_completion(params) do |data|
|
|
|
76
76
|
end
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
### Responses
|
|
80
|
+
|
|
81
|
+
Use `create_response` for the Responses API. When `stream` is true, the block receives each parsed SSE event:
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
res = client.create_response(
|
|
85
|
+
model: "gpt-5.6-terra",
|
|
86
|
+
input: "Explain why the answer is correct.",
|
|
87
|
+
store: false,
|
|
88
|
+
stream: true
|
|
89
|
+
) do |event|
|
|
90
|
+
print event["delta"] if event["type"] == "response.output_text.delta"
|
|
91
|
+
end
|
|
92
|
+
```
|
|
93
|
+
|
|
79
94
|
### Edit
|
|
80
95
|
|
|
81
96
|
https://platform.openai.com/docs/api-reference/edits
|
data/lib/openai_ruby/client.rb
CHANGED
|
@@ -20,26 +20,16 @@ module OpenAI
|
|
|
20
20
|
)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def create_chat_completion(params = {})
|
|
24
|
-
|
|
23
|
+
def create_chat_completion(params = {}, &block)
|
|
24
|
+
return connection.post("/v1/chat/completions", params.to_json) unless streaming?(params)
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
parser.feed(chunk) do |_type, data|
|
|
36
|
-
yield(JSON.parse(data)) if block_given? && data != "[DONE]"
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
else
|
|
41
|
-
connection.post("/v1/chat/completions", params.to_json)
|
|
42
|
-
end
|
|
26
|
+
create_streaming_request("/v1/chat/completions", params, &block)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def create_response(params = {}, &block)
|
|
30
|
+
return connection.post("/v1/responses", params.to_json) unless streaming?(params)
|
|
31
|
+
|
|
32
|
+
create_streaming_request("/v1/responses", params, &block)
|
|
43
33
|
end
|
|
44
34
|
|
|
45
35
|
def create_edit(params = {})
|
|
@@ -100,6 +90,33 @@ module OpenAI
|
|
|
100
90
|
params[:stream] || params["stream"]
|
|
101
91
|
end
|
|
102
92
|
|
|
93
|
+
def create_streaming_request(path, params, &block)
|
|
94
|
+
parser = EventStreamParser::Parser.new
|
|
95
|
+
error_body = +""
|
|
96
|
+
response = connection.post(path) do |req|
|
|
97
|
+
req.body = params.to_json
|
|
98
|
+
req.options.on_data = proc do |chunk, _overall_received_bytes, env|
|
|
99
|
+
handle_streaming_chunk(parser, error_body, chunk, env, &block)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
raise_streaming_response_error(response, error_body) unless response.status == 200
|
|
104
|
+
response
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def handle_streaming_chunk(parser, error_body, chunk, env)
|
|
108
|
+
return error_body << chunk unless env&.status == 200
|
|
109
|
+
|
|
110
|
+
parser.feed(chunk) do |_type, data|
|
|
111
|
+
yield(JSON.parse(data)) if block_given? && data != "[DONE]"
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def raise_streaming_response_error(response, body)
|
|
116
|
+
error_env = response.env.merge(body: try_parse_json(body))
|
|
117
|
+
Faraday::Response::RaiseError.new.on_complete(error_env)
|
|
118
|
+
end
|
|
119
|
+
|
|
103
120
|
def build_multipart_body(sdp_offer, session)
|
|
104
121
|
boundary = "----RubyFormBoundary#{SecureRandom.hex(16)}"
|
|
105
122
|
parts = [
|
data/lib/openai_ruby/version.rb
CHANGED