Module: Omen::Stubs
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/omen/stubs.rb
Overview
Answers the Anthropic API with canned turns, so no test of a host reaches the network.
Constant Summary collapse
- MESSAGES_URL =
Where a message is asked for.
'https://api.anthropic.com/v1/messages'
Instance Method Summary collapse
-
#claude_answers(sql: '', note: '', combine: []) ⇒ Hash
Carries a stray
caller, so a test notices if a reply is ever replayed whole. -
#claude_says(text) ⇒ Hash
A reply cut short at max_tokens is not JSON, whatever the output schema demanded.
-
#stub_claude(*turns) ⇒ Object
Answers each request with the next turn, so a question and its refinement are scripted apart.
Instance Method Details
#claude_answers(sql: '', note: '', combine: []) ⇒ Hash
Carries a stray caller, so a test notices if a reply is ever replayed whole.
18 19 20 21 22 |
# File 'lib/omen/stubs.rb', line 18 def claude_answers(sql: '', note: '', combine: []) answered = { sql: sql, note: note, combine: combine } claude_turn 'end_turn', [ { type: 'text', text: answered.to_json, caller: { type: 'assistant' }, } ] end |
#claude_says(text) ⇒ Hash
A reply cut short at max_tokens is not JSON, whatever the output schema demanded.
27 28 29 |
# File 'lib/omen/stubs.rb', line 27 def claude_says(text) claude_turn 'max_tokens', [ { type: 'text', text: text } ] end |
#stub_claude(*turns) ⇒ Object
Answers each request with the next turn, so a question and its refinement are scripted apart.
8 9 10 11 |
# File 'lib/omen/stubs.rb', line 8 def stub_claude(*turns) stub_request(:post, MESSAGES_URL). to_return(*turns.map { |turn| { body: turn.to_json, headers: json_headers } }) end |