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, the schema, and the shape of a reply.

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'
ANSWER =

The one shape a reply may take: both keys required, and no others admitted.

{
  type: 'object', additionalProperties: false, required: %w[ sql note combine ],
  properties: {
    sql: { type: 'string',
           description: 'The one PostgreSQL SELECT that answers the question, or ' \
                        'empty to ask something first.', },
    note: { type: 'string',
            description: 'A sentence or two: what the query returns and any ' \
                         'assumption made. If sql is empty, the question you ' \
                         'need answered first.', },
    combine: Omen::Combination::SCHEMA,
  },
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.blockArray<Hash>

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

Returns:

  • (Array<Hash>)

    the one system block of a request.



36
37
38
# File 'app/models/omen/instructions.rb', line 36

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

.output_configHash

Returns what a reply is constrained to, so that it always parses.

Returns:

  • (Hash)

    what a reply is constrained to, so that it always parses.



32
# File 'app/models/omen/instructions.rb', line 32

def self.output_config = { format_: { type: :json_schema, schema: ANSWER } }

Instance Method Details

#textString

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.



42
43
44
45
46
47
# File 'app/models/omen/instructions.rb', line 42

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: Omen.config.notes
end