Class: Omakase::Request

Inherits:
Data
  • Object
show all
Defined in:
lib/omakase/request.rb

Overview

One invocation of a generation method: all a strategy may depend on.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agent ⇒ Object (readonly)

Returns the value of attribute agent

Returns:

  • (Object) —

    the current value of agent



5
6
7
# File 'lib/omakase/request.rb', line 5

def agent
  @agent
end

#generation ⇒ Object (readonly)

Returns the value of attribute generation

Returns:

  • (Object) —

    the current value of generation



5
6
7
# File 'lib/omakase/request.rb', line 5

def generation
  @generation
end

#inputs ⇒ Object (readonly)

Returns the value of attribute inputs

Returns:

  • (Object) —

    the current value of inputs



5
6
7
# File 'lib/omakase/request.rb', line 5

def inputs
  @inputs
end

Instance Method Details

#attachments ⇒ Object

with: is reserved: files for the model to look at, passed through to RubyLLM's ask(with:) as attachments rather than rendered into the text.



17
# File 'lib/omakase/request.rb', line 17

def attachments = inputs[:with]

#chat ⇒ Object



6
# File 'lib/omakase/request.rb', line 6

def chat = agent.chat(**{model: generation.model}.compact)

#context ⇒ Object

Rebuilt on every call, so it goes after what a provider can cache.



13
# File 'lib/omakase/request.rb', line 13

def context = agent.context.to_s

#instructions ⇒ Object



10
# File 'lib/omakase/request.rb', line 10

def instructions = agent.class.instructions

#prompt ⇒ Object

A prompt written as a block is read at call time, on the agent — so one declaration serves an object however it happens to be configured.



30
31
32
33
# File 'lib/omakase/request.rb', line 30

def prompt
  text = generation.prompt
  text.is_a?(Proc) ? agent.instance_exec(&text) : text
end

#schema ⇒ Object



8
# File 'lib/omakase/request.rb', line 8

def schema = generation.schema

#shorten(text, limit = 500) ⇒ Object

Past the limit, code_act shows the start of an input: the whole value is a local. ponytail: inspects the whole value, then cuts; a bounded printer if a huge input shows up in a profile.



37
38
39
40
41
# File 'lib/omakase/request.rb', line 37

def shorten(text, limit = 500)
  return text if text.length <= limit

  "#{text[0, limit]}… (#{text.length} characters — the whole value is in the local)"
end

#task(preview: false) ⇒ Object

With preview:, the model's code holds the inputs, so the prompt only shows them.



20
21
22
23
24
25
26
# File 'lib/omakase/request.rb', line 20

def task(preview: false)
  arguments = inputs.except(:with)
  return prompt if arguments.empty?

  lines = arguments.map { |name, value| "- #{name}: #{preview ? shorten(value.inspect) : value.inspect}" }
  "#{prompt}\n\nInputs:\n#{lines.join("\n")}"
end