ai-chat 0.3.2 → 0.5.0
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 +252 -194
- data/ai-chat.gemspec +4 -4
- data/lib/ai/amazing_print.rb +25 -26
- data/lib/ai/chat.rb +127 -169
- data/lib/ai/http.rb +1 -1
- data/lib/ai/items.rb +54 -0
- data/lib/ai/message.rb +23 -0
- data/lib/ai-chat.rb +11 -0
- metadata +6 -2
data/lib/ai/items.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "delegate"
|
|
4
|
+
|
|
5
|
+
module AI
|
|
6
|
+
class Items < SimpleDelegator
|
|
7
|
+
def initialize(response, conversation_id:)
|
|
8
|
+
super(response)
|
|
9
|
+
@conversation_id = conversation_id
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def to_html
|
|
13
|
+
AI.wrap_html(build_output(html: true))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def inspect
|
|
17
|
+
build_output(html: false, plain: !$stdout.tty?)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def pretty_inspect
|
|
21
|
+
"#{inspect}\n"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def pretty_print(q)
|
|
25
|
+
q.output << inspect
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def build_output(html: false, plain: false)
|
|
31
|
+
box = build_box
|
|
32
|
+
items_output = data.ai(html: html, plain: plain, limit: 100, indent: 2, index: true)
|
|
33
|
+
|
|
34
|
+
if html
|
|
35
|
+
"<pre>#{box}</pre>\n#{items_output}"
|
|
36
|
+
else
|
|
37
|
+
"#{box}\n#{items_output}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def build_box
|
|
42
|
+
box_width = 78
|
|
43
|
+
inner_width = box_width - 4
|
|
44
|
+
|
|
45
|
+
lines = []
|
|
46
|
+
lines << "┌#{"─" * (box_width - 2)}┐"
|
|
47
|
+
lines << "│ Conversation: #{@conversation_id.to_s.ljust(inner_width - 14)} │"
|
|
48
|
+
lines << "│ Items: #{data.length.to_s.ljust(inner_width - 7)} │"
|
|
49
|
+
lines << "└#{"─" * (box_width - 2)}┘"
|
|
50
|
+
|
|
51
|
+
lines.join("\n")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/ai/message.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AI
|
|
4
|
+
class Message < Hash
|
|
5
|
+
def inspect
|
|
6
|
+
ai(plain: !$stdout.tty?, index: false)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def pretty_inspect
|
|
10
|
+
"#{inspect}\n"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# IRB's ColorPrinter calls pretty_print and re-colorizes text,
|
|
14
|
+
# which escapes our ANSI codes. Write directly to output to bypass.
|
|
15
|
+
def pretty_print(q)
|
|
16
|
+
q.output << inspect
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_html
|
|
20
|
+
AI.wrap_html(ai(html: true, index: false))
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/ai-chat.rb
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
module AI
|
|
2
|
+
HTML_PRE_STYLE = "background-color: #1e1e1e; color: #d4d4d4; padding: 1em; white-space: pre-wrap; word-wrap: break-word;"
|
|
3
|
+
|
|
4
|
+
def self.wrap_html(html)
|
|
5
|
+
html = html.gsub("<pre>", "<pre style=\"#{HTML_PRE_STYLE}\">")
|
|
6
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require_relative "ai/message"
|
|
11
|
+
require_relative "ai/items"
|
|
1
12
|
require_relative "ai/chat"
|
|
2
13
|
|
|
3
14
|
# Load amazing_print extension if amazing_print is available
|
metadata
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ai-chat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Raghu Betina
|
|
8
|
+
- Jelani Woods
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
11
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
@@ -143,6 +144,7 @@ dependencies:
|
|
|
143
144
|
version: '11.1'
|
|
144
145
|
email:
|
|
145
146
|
- raghu@firstdraft.com
|
|
147
|
+
- jelani@firstdraft.com
|
|
146
148
|
executables: []
|
|
147
149
|
extensions: []
|
|
148
150
|
extra_rdoc_files:
|
|
@@ -156,6 +158,8 @@ files:
|
|
|
156
158
|
- lib/ai/amazing_print.rb
|
|
157
159
|
- lib/ai/chat.rb
|
|
158
160
|
- lib/ai/http.rb
|
|
161
|
+
- lib/ai/items.rb
|
|
162
|
+
- lib/ai/message.rb
|
|
159
163
|
- lib/prompts/schema_generator.md
|
|
160
164
|
homepage: https://github.com/firstdraft/ai-chat
|
|
161
165
|
licenses:
|
|
@@ -181,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
181
185
|
- !ruby/object:Gem::Version
|
|
182
186
|
version: '0'
|
|
183
187
|
requirements: []
|
|
184
|
-
rubygems_version:
|
|
188
|
+
rubygems_version: 4.0.1
|
|
185
189
|
specification_version: 4
|
|
186
190
|
summary: A beginner-friendly Ruby interface for OpenAI's API
|
|
187
191
|
test_files: []
|