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
23
# File 'lib/omakase/fake_chat.rb', line 17

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

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



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

def attachments
  @attachments
end

#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, with: nil) ⇒ Object



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

def ask(task, with: nil)
  @tasks << task
  @attachments << with if with
  Response.new(@script.call(self))
end

#run(code) ⇒ Object

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



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

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

#with_instructions(text) ⇒ Object



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

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

#with_schema(schema) ⇒ Object



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

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

#with_tool(tool) ⇒ Object



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

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