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

#agentObject (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

#generationObject (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

#inputsObject (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

#attachmentsObject

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.



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

def attachments = inputs[:with]

#chatObject



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

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

#instructionsObject



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

def instructions = [agent.class.instructions, agent.context].reject { |text| text.to_s.empty? }.join("\n\n")

#promptObject

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.



26
27
28
29
# File 'lib/omakase/request.rb', line 26

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

#schemaObject



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

def schema = generation.schema

#taskObject



16
17
18
19
20
21
22
# File 'lib/omakase/request.rb', line 16

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

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