Class: Omen::Instructions

Inherits:
Object
  • Object
show all
Defined in:
app/models/omen/instructions.rb

Overview

Everything Claude is told before a question: the prose, and the schema it may write against.

Constant Summary collapse

PROSE =

The prose, kept beside this class so it reads as prose rather than as a string.

File.expand_path 'instructions.md', __dir__
TIME_ZONE =

The database function a stored timestamp is read through, created by the gem's rake task. Every one of these is prefixed, since today especially is a name a host may want itself.

'omen_time_zone'
TODAY =

The database function that answers what day it is where the company works.

'omen_today'
MILES =

The database function a distance in miles is measured with, created by the same task.

'omen_miles_between'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reading) ⇒ Instructions

Returns a new instance of Instructions.

Parameters:

  • reading (Omen::Reading) —

    the one being answered, which says what it may read.



24
25
26
# File 'app/models/omen/instructions.rb', line 24

def initialize(reading)
  @reading = reading
end

Class Method Details

.block(reading) ⇒ Array<Hash>

Cached for an hour: the schema is thousands of tokens, and refining sends it again.

Parameters:

  • reading (Omen::Reading) —

    the one being answered, which says what it may read.

Returns:

  • (Array<Hash>) —

    the one system block of a request.



19
20
21
# File 'app/models/omen/instructions.rb', line 19

def self.block(reading)
  [ { type: 'text', text: new(reading).text, cache_control: { type: 'ephemeral', ttl: '1h' } } ]
end

Instance Method Details

#text ⇒ String

Today's date is said out loud because "last month" is Claude's to resolve, and it has no clock.

Returns:

  • (String) —

    the prose, with the schema, the subclasses and the host's notes filled in.



30
31
32
33
34
35
# File 'app/models/omen/instructions.rb', line 30

def text
  format File.read(PROSE), today: Date.current.to_fs(:long), zone_fn: TIME_ZONE,
    today_fn: TODAY, miles_fn: MILES,
    schema: schema, types: types, readable: readable, refused: refused,
    notes: @reading.notes
end