ai-chat 0.5.1 → 0.5.3

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: 77efcbc43e3402b184ce49ff870671796904a0935a37d55dd9eeaaea93572b53
4
- data.tar.gz: 8996a14db31e7455815d10acac9827658fcbaf5358e1a461d2b83a946b8f3cc9
3
+ metadata.gz: 1693a4828234dc84df802bd990518caf2bb235ce71753b471216b143aa90eff0
4
+ data.tar.gz: 574821abde32e11bd88a2651d4e0b1ed88a1fc6f76703024f2bbde4622b6306a
5
5
  SHA512:
6
- metadata.gz: b1993b6e812a75387b53ade7f29785a80aa0c70c7b6aa97d5ac9eed7e73fc27a87f1a76676e9878416849af3c9ae3967d6b78838be0c681f077fa63c81e32993
7
- data.tar.gz: 0f463e8beef43965db7b85b94335624322f46bc39cc4dd2c1a02ad44993ae972bdbfb4a670890b3f55ddf9ce5ebf57fd8b2e92f85fd3340a2be1d7aa6d1ca549
6
+ metadata.gz: 6046630107863b4f79b17b1c95384af5335a3769800fe8dfa8dbb5a5a28dea4ed3797b1d40e391f79c4567fb83eaef18eba3cbb3ef4f5bab796a0cda2af3d393
7
+ data.tar.gz: f8836dfc5b2c50c2682a865f97e52f5f5e6f6569a1b1a4de09619f3d9a12ee9184c8e9fd06f5004c5f3d62171adef1aaa8fa929336e5c335c29ffe72e25648d2
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.1"
5
+ spec.version = "0.5.3"
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"
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  "source_code_uri" => "https://github.com/firstdraft/ai-chat"
19
19
  }
20
20
 
21
- spec.required_ruby_version = "~> 3.2"
21
+ spec.required_ruby_version = ">= 3.2"
22
22
  spec.add_runtime_dependency "openai", "~> 0.34"
23
23
  spec.add_runtime_dependency "marcel", "~> 1.0"
24
24
  spec.add_runtime_dependency "base64", "~> 0.1", "> 0.1.1"
data/lib/ai/chat.rb CHANGED
@@ -208,8 +208,8 @@ module AI
208
208
  attrs << [:@conversation_id, @conversation_id]
209
209
  attrs << [:@last_response_id, @last_response_id] if @last_response_id
210
210
 
211
- # 3. Messages (the main content, without response details)
212
- display_messages = @messages.map { |msg| msg.except(:response) }
211
+ # 3. Messages (the main content, without response details, with truncated data URIs)
212
+ display_messages = @messages.map { |msg| AI.truncate_data_uris(msg.except(:response)) }
213
213
  attrs << [:@messages, display_messages]
214
214
 
215
215
  # 4. Optional features (only if enabled/changed from default)
@@ -228,11 +228,11 @@ module AI
228
228
  end
229
229
 
230
230
  def inspect
231
- ai(plain: !$stdout.tty?, multiline: true)
231
+ AI.amazing_print(self, plain: !$stdout.tty?, multiline: true)
232
232
  end
233
233
 
234
234
  def to_html
235
- AI.wrap_html(ai(html: true, multiline: true))
235
+ AI.wrap_html(AI.amazing_print(self, html: true, multiline: true))
236
236
  end
237
237
 
238
238
  def pretty_inspect
data/lib/ai/items.rb CHANGED
@@ -29,7 +29,7 @@ module AI
29
29
 
30
30
  def build_output(html: false, plain: false)
31
31
  box = build_box
32
- items_output = data.ai(html: html, plain: plain, limit: 100, indent: 2, index: true)
32
+ items_output = AI.amazing_print(data, html: html, plain: plain, limit: 100, indent: 2, index: true)
33
33
 
34
34
  if html
35
35
  "<pre>#{box}</pre>\n#{items_output}"
data/lib/ai/message.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module AI
4
4
  class Message < Hash
5
5
  def inspect
6
- ai(plain: !$stdout.tty?, index: false)
6
+ AI.amazing_print(display_hash, plain: !$stdout.tty?, index: false)
7
7
  end
8
8
 
9
9
  def pretty_inspect
@@ -17,7 +17,13 @@ module AI
17
17
  end
18
18
 
19
19
  def to_html
20
- AI.wrap_html(ai(html: true, index: false))
20
+ AI.wrap_html(AI.amazing_print(display_hash, html: true, index: false))
21
+ end
22
+
23
+ private
24
+
25
+ def display_hash
26
+ AI.truncate_data_uris(to_h)
21
27
  end
22
28
  end
23
29
  end
data/lib/ai-chat.rb CHANGED
@@ -1,10 +1,43 @@
1
1
  module AI
2
- HTML_PRE_STYLE = "background-color: #1e1e1e; color: #d4d4d4; padding: 1em; white-space: pre-wrap; word-wrap: break-word;"
2
+ HTML_PRE_STYLE = "background-color: #1e1e1e; color: #d4d4d4; padding: 1em; " \
3
+ "border-radius: 4px; overflow-x: auto; " \
4
+ "white-space: pre-wrap; word-wrap: break-word;"
3
5
 
4
- def self.wrap_html(html)
5
- html = html.gsub("<pre>", "<pre style=\"#{HTML_PRE_STYLE}\">")
6
+ def self.wrap_html(content)
7
+ html = "<pre style=\"#{HTML_PRE_STYLE}\">#{content}</pre>"
6
8
  html.respond_to?(:html_safe) ? html.html_safe : html
7
9
  end
10
+
11
+ # Use AmazingPrint::Inspector directly to avoid conflicts with awesome_print gem
12
+ # which also defines an `ai` method on Object
13
+ def self.amazing_print(object, **options)
14
+ AmazingPrint::Inspector.new(**options).awesome(object)
15
+ end
16
+
17
+ # Recursively truncate base64 data URIs in nested structures for cleaner output
18
+ def self.truncate_data_uris(obj)
19
+ case obj
20
+ when Hash
21
+ obj.transform_values { |v| truncate_data_uris(v) }
22
+ when Array
23
+ obj.map { |v| truncate_data_uris(v) }
24
+ when String
25
+ truncate_data_uri(obj)
26
+ else
27
+ obj
28
+ end
29
+ end
30
+
31
+ def self.truncate_data_uri(str)
32
+ return str unless str.is_a?(String) && str.start_with?("data:") && str.include?(";base64,")
33
+
34
+ match = str.match(/\A(data:[^;]+;base64,)(.+)\z/)
35
+ return str unless match
36
+
37
+ prefix = match[1]
38
+ data = match[2]
39
+ "#{prefix}#{data[0, 20]}... (#{data.length} chars)"
40
+ end
8
41
  end
9
42
 
10
43
  require_relative "ai/message"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai-chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raghu Betina
8
8
  - Jelani Woods
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-29 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openai
@@ -148,8 +148,8 @@ email:
148
148
  executables: []
149
149
  extensions: []
150
150
  extra_rdoc_files:
151
- - README.md
152
151
  - LICENSE
152
+ - README.md
153
153
  files:
154
154
  - LICENSE
155
155
  - README.md
@@ -175,7 +175,7 @@ require_paths:
175
175
  - lib
176
176
  required_ruby_version: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - "~>"
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '3.2'
181
181
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  - !ruby/object:Gem::Version
185
185
  version: '0'
186
186
  requirements: []
187
- rubygems_version: 3.6.2
187
+ rubygems_version: 4.0.3
188
188
  specification_version: 4
189
189
  summary: A beginner-friendly Ruby interface for OpenAI's API
190
190
  test_files: []