Class: Omen::Answer
- Inherits:
-
Object
- Object
- Omen::Answer
- Defined in:
- app/models/omen/answer.rb
Overview
What Claude said back: the prose, the statement it wrote, and the rows that statement found.
Constant Summary collapse
- UNICODE_ESCAPE =
A \uXXXX escape that outlived JSON.parse, because Claude escaped the backslash of its own.
/\\u([0-9a-fA-F]{4})/
Constants included from Revealed
Instance Method Summary collapse
-
#answer ⇒ Hash
A reply cut short is not JSON at all, and reads as an answer with nothing in it.
-
#combine ⇒ Array<Hash>
The columns Claude asked to be drawn as their parts joined.
-
#cut_off? ⇒ Boolean
Whether the reply ran out of room, leaving JSON that will not parse.
-
#note ⇒ String
Decoded here and never in #sql, where a \u may be a literal the statement means to carry.
-
#role ⇒ String
The side of the conversation this was said on, in the words the API uses.
-
#sql ⇒ String
The one SELECT Claude wrote, which is empty when it asked instead.
-
#truncated? ⇒ Boolean
The query asks for one row past the cap, so the page can say there are more without counting.
Methods included from Revealed
Methods included from Spoken
Instance Method Details
#answer ⇒ Hash
A reply cut short is not JSON at all, and reads as an answer with nothing in it.
15 16 17 18 19 |
# File 'app/models/omen/answer.rb', line 15 def answer @answer ||= JSON.parse text rescue JSON::ParserError @answer = {} end |
#combine ⇒ Array<Hash>
Returns the columns Claude asked to be drawn as their parts joined.
32 |
# File 'app/models/omen/answer.rb', line 32 def combine = Array answer['combine'] |
#cut_off? ⇒ Boolean
Returns whether the reply ran out of room, leaving JSON that will not parse.
22 |
# File 'app/models/omen/answer.rb', line 22 def cut_off? = stop_reason == 'max_tokens' |
#note ⇒ String
Decoded here and never in #sql, where a \u may be a literal the statement means to carry.
29 |
# File 'app/models/omen/answer.rb', line 29 def note = answer['note'].to_s.gsub(UNICODE_ESCAPE) { $1.hex.chr Encoding::UTF_8 } |
#role ⇒ String
Returns the side of the conversation this was said on, in the words the API uses.
11 |
# File 'app/models/omen/answer.rb', line 11 def role = 'assistant' |
#sql ⇒ String
Returns the one SELECT Claude wrote, which is empty when it asked instead.
25 |
# File 'app/models/omen/answer.rb', line 25 def sql = answer['sql'].to_s |
#truncated? ⇒ Boolean
The query asks for one row past the cap, so the page can say there are more without counting.
36 |
# File 'app/models/omen/answer.rb', line 36 def truncated? = result.size > Omen.config.maximum_rows |