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 +4 -4
- data/README.md +21 -0
- data/lib/ai_lite/version.rb +1 -1
- data/lib/ai_lite.rb +16 -3
- data/test/ai_lite_test.rb +25 -0
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b1ae1b32c854b4f99a6fd8275a375c3d1870c93e5507756c9e6c3089ee220ea
|
|
4
|
+
data.tar.gz: fafd0e42607277bead469d0628d106af48cf7334ebecb100ca60b5ae5074b47a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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" => { ... }
|
data/lib/ai_lite/version.rb
CHANGED
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(
|
|
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(
|
|
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.
|
|
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-
|
|
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.
|
|
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.
|