Class: Omen::Answer

Inherits:
Object
  • Object
show all
Includes:
Revealed, Spoken
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

Revealed::CIPHERTEXT

Instance Method Summary collapse

Methods included from Revealed

#shown

Methods included from Spoken

#text

Instance Method Details

#answerHash

A reply cut short is not JSON at all, and reads as an answer with nothing in it.

Returns:

  • (Hash)

    the reply, parsed.



15
16
17
18
19
# File 'app/models/omen/answer.rb', line 15

def answer
  @answer ||= JSON.parse text
rescue JSON::ParserError
  @answer = {}
end

#combineArray<Hash>

Returns the columns Claude asked to be drawn as their parts joined.

Returns:

  • (Array<Hash>)

    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.

Returns:

  • (Boolean)

    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'

#noteString

Decoded here and never in #sql, where a \u may be a literal the statement means to carry.

Returns:

  • (String)

    what Claude said about the query, or the question it needs answered first.



29
# File 'app/models/omen/answer.rb', line 29

def note = answer['note'].to_s.gsub(UNICODE_ESCAPE) { $1.hex.chr Encoding::UTF_8 }

#roleString

Returns the side of the conversation this was said on, in the words the API uses.

Returns:

  • (String)

    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'

#sqlString

Returns the one SELECT Claude wrote, which is empty when it asked instead.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    whether the answer ran past what is shown.



36
# File 'app/models/omen/answer.rb', line 36

def truncated? = result.size > Omen.config.maximum_rows