Class: Omnibot::Testing::FakeChat
- Inherits:
-
Object
- Object
- Omnibot::Testing::FakeChat
- Defined in:
- lib/omnibot/testing.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#tool_results ⇒ Object
readonly
Returns the value of attribute tool_results.
Instance Method Summary collapse
- #add_message(role:, content:) ⇒ Object
- #ask(message, &stream_block) ⇒ Object
- #before_tool_call(&blk) ⇒ Object
-
#initialize(agent_class: nil) ⇒ FakeChat
constructor
A new instance of FakeChat.
- #with_instructions(text) ⇒ Object
- #with_schema(schema) ⇒ Object
- #with_tools(*tools, replace: false) ⇒ Object
Constructor Details
#initialize(agent_class: nil) ⇒ FakeChat
Returns a new instance of FakeChat.
51 52 53 54 55 56 57 |
# File 'lib/omnibot/testing.rb', line 51 def initialize(agent_class: nil) @agent_class = agent_class @messages = [] @tools = [] @before_tool_call_hooks = [] @tool_results = [] end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
49 50 51 |
# File 'lib/omnibot/testing.rb', line 49 def @messages end |
#tool_results ⇒ Object (readonly)
Returns the value of attribute tool_results.
49 50 51 |
# File 'lib/omnibot/testing.rb', line 49 def tool_results @tool_results end |
Instance Method Details
#add_message(role:, content:) ⇒ Object
70 71 72 73 |
# File 'lib/omnibot/testing.rb', line 70 def (role:, content:) @messages << { role: role, content: content } self end |
#ask(message, &stream_block) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/omnibot/testing.rb', line 85 def ask(, &stream_block) @messages << { role: :user, content: } script = Testing.script_for(@agent_class) while (step = script.shift) kind, a, b = step case kind when :tool tool_call = FakeToolCall.new(a, b) @before_tool_call_hooks.each { |h| h.call(tool_call) } tool = @tools.find { |t| t.name.to_s == a } raise Omnibot::Error, "FakeChat: no tool #{a.inspect} attached" unless tool @tool_results << tool.execute(**b) when :reply return emit_reply(a, stream_block) end end emit_reply("(fake) #{}", stream_block) end |
#before_tool_call(&blk) ⇒ Object
75 76 77 78 |
# File 'lib/omnibot/testing.rb', line 75 def before_tool_call(&blk) @before_tool_call_hooks << blk self end |
#with_instructions(text) ⇒ Object
59 60 61 62 |
# File 'lib/omnibot/testing.rb', line 59 def with_instructions(text, **) @messages << { role: :system, content: text } self end |
#with_schema(schema) ⇒ Object
80 81 82 83 |
# File 'lib/omnibot/testing.rb', line 80 def with_schema(schema) @schema = schema self end |
#with_tools(*tools, replace: false) ⇒ Object
64 65 66 67 68 |
# File 'lib/omnibot/testing.rb', line 64 def with_tools(*tools, replace: false) @tools = [] if replace @tools.concat(tools) self end |