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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9012bf87a54da64ccab695a2d440249cf691f2f5943272c918065b24137fa6fb
4
- data.tar.gz: 9d3931249dc62145f8eb3cc3fc44382a038c901b8bfc4a2ccda0d01d8653489d
3
+ metadata.gz: e997805c08f99471c8ebb6ed5fe4ebaf1662f2934e3831e0c263dc8190803e95
4
+ data.tar.gz: faed24eeb06233ac4ad19c3f3300858e39a6fff938cee15ec69d3466acf0aa4f
5
5
  SHA512:
6
- metadata.gz: d9447afcbff626605c7b865675cd28d598e2c3cee19010aa86a9955b5a3cf109ea68ea40765bfe9aa92f43d823710eb91f7d4b3cfd92d4105c02f6ad9e45bdc9
7
- data.tar.gz: 5ae2565d62ae358f62938a5b888e55d73bc581449e0f0e1c4de836f713832c1bf19fe0e9ba6d8ae0c4b108323532ab5e905dc22079e0aa4ecc833b6a9b884386
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.4"
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
- class Items < SimpleDelegator
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
- super(response)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai-chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raghu Betina