ai-lite 0.1.0 → 0.1.1

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: f6f864c2c29ee79c0aa144c940fa34a3a4b84189239436cab38fcd1862401726
4
- data.tar.gz: 293507b5e1af278ab17658f81f63dc257a7d6ce2b00c79b77d64c6ba1e9fb434
3
+ metadata.gz: 3b1ae1b32c854b4f99a6fd8275a375c3d1870c93e5507756c9e6c3089ee220ea
4
+ data.tar.gz: fafd0e42607277bead469d0628d106af48cf7334ebecb100ca60b5ae5074b47a
5
5
  SHA512:
6
- metadata.gz: 77bf79ade3eec73d1cbd06b269dd0d4566d4b06f96d7919dfa74a6f514572ff24fe36a93e65e9e43aa4a369e7c9a3db2e771e5c4419c8e22fc8f19d6f63db1af
7
- data.tar.gz: 2033b7e8215841e2b57eb46355cef483e5badc30d56affffd1cd47b7e245442612fee91ec0918fda4828064fca7a7dc62e2268b329730ae0534e8ec07ed16aee
6
+ metadata.gz: eae14b861938c6a351a1b0430eb8ec03569a41fec7896af012addfb2fb5e4f60d6a28345c2cde6c1b82270ccd40cda21da9db470fa7694a2368930ab3e1f1072
7
+ data.tar.gz: a31f91cf5db94e669f992b03added0312d287aeb991b327adc3f7703d8cc582e460d26d3e7e2c4692a3a29693f2de6cf9998b4e59be593e7a64569b6fb66758d
data/README.md CHANGED
@@ -91,6 +91,23 @@ The default model is `gpt-5.5`.
91
91
 
92
92
  The OpenAI API URL is fixed to `https://api.openai.com/v1/responses`.
93
93
 
94
+ ## Multi-Turn Chat
95
+
96
+ Responses include a `response_id` that can be passed back through `options` as `previous_response_id`:
97
+
98
+ ```ruby
99
+ first = ai.chat("Tell me a short joke.")
100
+
101
+ follow_up = ai.chat(
102
+ "Explain why that is funny.",
103
+ options: {
104
+ previous_response_id: first["response_id"]
105
+ }
106
+ )
107
+
108
+ puts follow_up["content"]
109
+ ```
110
+
94
111
  ## Return Shape
95
112
 
96
113
  `chat` always returns a hash envelope.
@@ -100,6 +117,7 @@ Text output:
100
117
  ```ruby
101
118
  {
102
119
  "content" => "Hello!",
120
+ "response_id" => "resp_...",
103
121
  "status" => 200,
104
122
  "error" => nil,
105
123
  "raw" => nil
@@ -111,6 +129,7 @@ JSON-looking model output:
111
129
  ```ruby
112
130
  {
113
131
  "content" => { "valid" => true },
132
+ "response_id" => "resp_...",
114
133
  "status" => 200,
115
134
  "error" => nil,
116
135
  "raw" => nil
@@ -122,6 +141,7 @@ Failure:
122
141
  ```ruby
123
142
  {
124
143
  "content" => nil,
144
+ "response_id" => nil,
125
145
  "status" => 401,
126
146
  "error" => "Invalid API key",
127
147
  "raw" => nil
@@ -135,6 +155,7 @@ result = ai.chat("Say hello", debug: true)
135
155
 
136
156
  {
137
157
  "content" => "Hello!",
158
+ "response_id" => "resp_...",
138
159
  "status" => 200,
139
160
  "error" => nil,
140
161
  "raw" => { ... }
@@ -1,3 +1,3 @@
1
1
  class AiLite
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.1".freeze
3
3
  end
data/lib/ai_lite.rb CHANGED
@@ -106,12 +106,24 @@ class AiLite
106
106
  parsed_response = JSON.parse(response.body)
107
107
 
108
108
  unless success_status?(status)
109
- return prettify_data(status: status, error: error_message(parsed_response), raw: parsed_response, debug: debug)
109
+ return prettify_data(
110
+ status: status,
111
+ error: error_message(parsed_response),
112
+ response_id: parsed_response["id"],
113
+ raw: parsed_response,
114
+ debug: debug
115
+ )
110
116
  end
111
117
 
112
118
  raw_content = extract_output_text(parsed_response)
113
119
  content = parse_content(raw_content)
114
- prettify_data(status: status, content: content, raw: parsed_response, debug: debug)
120
+ prettify_data(
121
+ status: status,
122
+ content: content,
123
+ response_id: parsed_response["id"],
124
+ raw: parsed_response,
125
+ debug: debug
126
+ )
115
127
  rescue JSON::ParserError => e
116
128
  prettify_data(status: response_status(response), error: e.message, raw: response&.body, debug: debug)
117
129
  rescue => e
@@ -154,9 +166,10 @@ class AiLite
154
166
  response&.code&.to_i || "unknown"
155
167
  end
156
168
 
157
- def prettify_data(status:, content: nil, error: nil, raw:, debug: false)
169
+ def prettify_data(status:, content: nil, error: nil, response_id: nil, raw:, debug: false)
158
170
  {
159
171
  "content" => content,
172
+ "response_id" => response_id,
160
173
  "status" => status,
161
174
  "error" => error,
162
175
  "raw" => debug ? raw : nil
data/test/ai_lite_test.rb CHANGED
@@ -130,6 +130,7 @@ class AiLiteTest < Minitest::Test
130
130
  payload = JSON.parse(request.body)
131
131
 
132
132
  assert_equal "Hello!", result["content"]
133
+ assert_equal "resp_test_123", result["response_id"]
133
134
  assert_equal 200, result["status"]
134
135
  assert_nil result["error"]
135
136
  assert_nil result["raw"]
@@ -196,9 +197,28 @@ class AiLiteTest < Minitest::Test
196
197
  end
197
198
  end
198
199
 
200
+ def test_chat_supports_previous_response_id_through_options
201
+ client = AiLite.new(api_key: "token-abc")
202
+
203
+ with_stubbed_http(success_response("Follow-up")) do |captured, _response|
204
+ result = client.chat(
205
+ "Explain why that is funny",
206
+ options: {
207
+ previous_response_id: "resp_previous_123"
208
+ }
209
+ )
210
+ payload = JSON.parse(captured[:http].last_request.body)
211
+
212
+ assert_equal "resp_previous_123", payload["previous_response_id"]
213
+ assert_equal "Follow-up", result["content"]
214
+ assert_equal "resp_test_123", result["response_id"]
215
+ end
216
+ end
217
+
199
218
  def test_extracts_text_from_nested_output_text_items
200
219
  client = AiLite.new(api_key: "token-abc")
201
220
  body = JSON.generate(
221
+ "id" => "resp_nested_123",
202
222
  "output" => [
203
223
  { "type" => "reasoning", "content" => [] },
204
224
  {
@@ -215,6 +235,7 @@ class AiLiteTest < Minitest::Test
215
235
  result = client.chat("Say hello")
216
236
 
217
237
  assert_equal "Hello world", result["content"]
238
+ assert_equal "resp_nested_123", result["response_id"]
218
239
  assert_equal 200, result["status"]
219
240
  assert_nil result["error"]
220
241
  end
@@ -264,6 +285,7 @@ class AiLiteTest < Minitest::Test
264
285
  result = client.chat("Say hello")
265
286
 
266
287
  assert_nil result["content"]
288
+ assert_nil result["response_id"]
267
289
  assert_equal 401, result["status"]
268
290
  assert_equal "Invalid API key", result["error"]
269
291
  assert_nil result["raw"]
@@ -291,6 +313,7 @@ class AiLiteTest < Minitest::Test
291
313
  result = client.chat("Say hello")
292
314
 
293
315
  assert_nil result["content"]
316
+ assert_nil result["response_id"]
294
317
  assert_equal 200, result["status"]
295
318
  assert_match(/unexpected token|unexpected character|parse/i, result["error"])
296
319
  assert_nil result["raw"]
@@ -321,6 +344,7 @@ class AiLiteTest < Minitest::Test
321
344
  result = client.chat("Say hello")
322
345
 
323
346
  assert_nil result["content"]
347
+ assert_nil result["response_id"]
324
348
  assert_equal "unknown", result["status"]
325
349
  assert_equal "connection failed", result["error"]
326
350
  assert_nil result["raw"]
@@ -332,6 +356,7 @@ class AiLiteTest < Minitest::Test
332
356
 
333
357
  def success_response(content)
334
358
  body = JSON.generate(
359
+ "id" => "resp_test_123",
335
360
  "output" => [
336
361
  {
337
362
  "type" => "message",
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Basmayor
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-13 00:00:00.000000000 Z
11
+ date: 2026-05-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: AI Lite is a dependency-light Ruby client for Rails apps and plain Ruby
14
14
  projects that need simple OpenAI Responses API calls.
15
- email:
15
+ email:
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
@@ -27,7 +27,7 @@ homepage: https://github.com/wbasmayor/ai-lite
27
27
  licenses:
28
28
  - MIT
29
29
  metadata: {}
30
- post_install_message:
30
+ post_install_message:
31
31
  rdoc_options: []
32
32
  require_paths:
33
33
  - lib
@@ -42,8 +42,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
44
  requirements: []
45
- rubygems_version: 3.5.22
46
- signing_key:
45
+ rubygems_version: 3.0.3.1
46
+ signing_key:
47
47
  specification_version: 4
48
48
  summary: Minimal Ruby client for simple AI chat calls through the OpenAI Responses
49
49
  API.