ai-chat 0.5.4 → 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 +4 -4
- data/README.md +9 -0
- data/ai-chat.gemspec +1 -1
- data/lib/ai/chat.rb +12 -1
- data/lib/ai/items.rb +28 -4
- 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: e997805c08f99471c8ebb6ed5fe4ebaf1662f2934e3831e0c263dc8190803e95
|
|
4
|
+
data.tar.gz: faed24eeb06233ac4ad19c3f3300858e39a6fff938cee15ec69d3466acf0aa4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 15dfedd0a5e5fec19d76acd155e4384cbbc5c7aa46fc88cf706cfb4ed5184e94ae1886afcc29c44bf6bb7f01ccb227f7e77cc1735b753226a9bb455968ff522f
|
|
7
|
+
data.tar.gz: 35dea135530c56c31da1e24265feb31f303402068f67b83f0badfc0b30a3ba571eff7b0644e71fa87727d6e864e2df90b6e00bae9d0c94a383f93e713175d3b5
|
data/README.md
CHANGED
|
@@ -671,6 +671,15 @@ The `reasoning_effort` parameter guides the model on how many reasoning tokens t
|
|
|
671
671
|
|
|
672
672
|
By default, `reasoning_effort` is `nil`, which means no reasoning parameter is sent to the API. For `gpt-5.2` (the default model), this is equivalent to `"none"` reasoning.
|
|
673
673
|
|
|
674
|
+
## Verbosity
|
|
675
|
+
|
|
676
|
+
Verbosity determines how many output tokens are generated. Lowering the number of tokens reduces overall latency. While the model's reasoning approach stays mostly the same, the model finds ways to answer more concisely—which can either improve or diminish answer quality, depending on your use case. Here are some scenarios for both ends of the verbosity spectrum:
|
|
677
|
+
|
|
678
|
+
- High verbosity: Use when you need the model to provide thorough explanations of documents or perform extensive code refactoring.
|
|
679
|
+
- Low verbosity: Best for situations where you want concise answers or simple code generation, such as SQL queries.
|
|
680
|
+
|
|
681
|
+
The supported values are `:high`, `:medium`, or `:low`. The default value is `:medium` for `gpt-5.2`. **Older models (like `gpt-4.1-nano`) only support `:medium`**.
|
|
682
|
+
|
|
674
683
|
## Advanced: Response Details
|
|
675
684
|
|
|
676
685
|
When you call `generate!` (or later call `get_response` in background mode), the gem stores additional information about the API response:
|
data/ai-chat.gemspec
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = "ai-chat"
|
|
5
|
-
spec.version = "0.5.
|
|
5
|
+
spec.version = "0.5.5"
|
|
6
6
|
spec.authors = ["Raghu Betina", "Jelani Woods"]
|
|
7
7
|
spec.email = ["raghu@firstdraft.com", "jelani@firstdraft.com"]
|
|
8
8
|
spec.homepage = "https://github.com/firstdraft/ai-chat"
|
data/lib/ai/chat.rb
CHANGED
|
@@ -19,7 +19,7 @@ module AI
|
|
|
19
19
|
class Chat
|
|
20
20
|
# :reek:Attribute
|
|
21
21
|
attr_accessor :background, :code_interpreter, :conversation_id, :image_generation, :image_folder, :messages, :model, :reasoning_effort, :web_search
|
|
22
|
-
attr_reader :client, :last_response_id, :proxy, :schema, :schema_file
|
|
22
|
+
attr_reader :client, :last_response_id, :proxy, :schema, :schema_file, :verbosity
|
|
23
23
|
|
|
24
24
|
BASE_PROXY_URL = "https://prepend.me/api.openai.com/v1"
|
|
25
25
|
|
|
@@ -34,6 +34,7 @@ module AI
|
|
|
34
34
|
@image_generation = false
|
|
35
35
|
@image_folder = "./images"
|
|
36
36
|
@api_key_validated = false
|
|
37
|
+
@verbosity = :medium
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def self.generate_schema!(description, location: "schema.json", api_key: nil, api_key_env_var: "OPENAI_API_KEY", proxy: false)
|
|
@@ -183,6 +184,14 @@ module AI
|
|
|
183
184
|
self.schema = content
|
|
184
185
|
end
|
|
185
186
|
|
|
187
|
+
def verbosity=(value)
|
|
188
|
+
if ["low", "medium", "high"].include?(value.to_s)
|
|
189
|
+
@verbosity = value.to_sym
|
|
190
|
+
else
|
|
191
|
+
raise ArgumentError, "Invalid verbosity value:'#{value}'. Must be one of :low, :medium, :high."
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
186
195
|
def last
|
|
187
196
|
messages.last
|
|
188
197
|
end
|
|
@@ -221,6 +230,7 @@ module AI
|
|
|
221
230
|
attrs << [:@web_search, @web_search] if @web_search
|
|
222
231
|
attrs << [:@schema, @schema] if @schema
|
|
223
232
|
attrs << [:@schema_file, @schema_file] if @schema_file
|
|
233
|
+
attrs << [:@verbosity, verbosity] if verbosity
|
|
224
234
|
|
|
225
235
|
attrs
|
|
226
236
|
end
|
|
@@ -274,6 +284,7 @@ module AI
|
|
|
274
284
|
|
|
275
285
|
create_conversation unless conversation_id
|
|
276
286
|
parameters[:conversation] = conversation_id
|
|
287
|
+
parameters[:text] = (parameters[:text] || {}).merge(verbosity: verbosity) if verbosity
|
|
277
288
|
|
|
278
289
|
messages_to_send = prepare_messages_for_api
|
|
279
290
|
parameters[:input] = strip_responses(messages_to_send) unless messages_to_send.empty?
|
data/lib/ai/items.rb
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "delegate"
|
|
4
|
-
|
|
5
3
|
module AI
|
|
6
|
-
|
|
4
|
+
# NOTE: This is intentionally *not* a SimpleDelegator.
|
|
5
|
+
#
|
|
6
|
+
# IRB's default inspector uses PP, and PP has special handling for Delegator
|
|
7
|
+
# instances that unwraps them (via __getobj__) before printing. That causes
|
|
8
|
+
# IRB to display the underlying OpenAI cursor page instead of our custom
|
|
9
|
+
# formatted output.
|
|
10
|
+
#
|
|
11
|
+
# By using a plain wrapper + method_missing delegation, `chat.get_items`
|
|
12
|
+
# displays nicely in IRB/Rails console while still forwarding API helpers
|
|
13
|
+
# like `.data`, `.has_more`, etc.
|
|
14
|
+
class Items
|
|
7
15
|
def initialize(response, conversation_id:)
|
|
8
|
-
|
|
16
|
+
@response = response
|
|
9
17
|
@conversation_id = conversation_id
|
|
10
18
|
end
|
|
11
19
|
|
|
20
|
+
attr_reader :response
|
|
21
|
+
|
|
22
|
+
def data
|
|
23
|
+
response.data
|
|
24
|
+
end
|
|
25
|
+
|
|
12
26
|
def to_html
|
|
13
27
|
AI.wrap_html(build_output(html: true))
|
|
14
28
|
end
|
|
@@ -25,6 +39,16 @@ module AI
|
|
|
25
39
|
q.output << inspect
|
|
26
40
|
end
|
|
27
41
|
|
|
42
|
+
def method_missing(method_name, *args, &block)
|
|
43
|
+
return super unless response.respond_to?(method_name)
|
|
44
|
+
|
|
45
|
+
response.public_send(method_name, *args, &block)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
49
|
+
response.respond_to?(method_name, include_private) || super
|
|
50
|
+
end
|
|
51
|
+
|
|
28
52
|
private
|
|
29
53
|
|
|
30
54
|
def build_output(html: false, plain: false)
|