Class: Omakase::FakeChat

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

Overview

Stands in for a RubyLLM::Chat so agents can be tested without a network: records how the chat was configured, then runs the script you gave it.

agent = SupportAgent.new(chat: Omakase::FakeChat.new { {"severity" => "high"} })

The script receives the chat, so it can drive the tool the way a model would:

Omakase::FakeChat.new { |chat| chat.run("finish(42)") }

Defined Under Namespace

Classes: Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&script) ⇒ FakeChat

Returns a new instance of FakeChat.



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

def initialize(&script)
  @script = script
  @instructions = []
  @tools = []
  @tasks = []
end

Instance Attribute Details

#instructionsObject (readonly)

Returns the value of attribute instructions.



15
16
17
# File 'lib/omakase/fake_chat.rb', line 15

def instructions
  @instructions
end

#schemaObject (readonly)

Returns the value of attribute schema.



15
16
17
# File 'lib/omakase/fake_chat.rb', line 15

def schema
  @schema
end

#tasksObject (readonly)

Returns the value of attribute tasks.



15
16
17
# File 'lib/omakase/fake_chat.rb', line 15

def tasks
  @tasks
end

#toolsObject (readonly)

Returns the value of attribute tools.



15
16
17
# File 'lib/omakase/fake_chat.rb', line 15

def tools
  @tools
end

Instance Method Details

#ask(task) ⇒ Object



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

def ask(task)
  @tasks << task
  Response.new(@script.call(self))
end

#run(code) ⇒ Object

Run code the way the model would, through the agent's one tool.



36
# File 'lib/omakase/fake_chat.rb', line 36

def run(code) = tools.fetch(0).call(code:)

#with_instructions(text) ⇒ Object



24
# File 'lib/omakase/fake_chat.rb', line 24

def with_instructions(text) = tap { @instructions << text }

#with_schema(schema) ⇒ Object



26
# File 'lib/omakase/fake_chat.rb', line 26

def with_schema(schema) = tap { @schema = schema }

#with_tool(tool) ⇒ Object



28
# File 'lib/omakase/fake_chat.rb', line 28

def with_tool(tool, **) = tap { @tools << tool }