Class: MockServer::LLM::TurnBuilder
- Inherits:
-
Object
- Object
- MockServer::LLM::TurnBuilder
- Defined in:
- lib/mockserver/llm.rb
Overview
TurnBuilder — one turn within a conversation.
Instance Attribute Summary collapse
-
#chaos ⇒ Object
readonly
Returns the value of attribute chaos.
-
#completion ⇒ Object
readonly
Returns the value of attribute completion.
Instance Method Summary collapse
-
#and_then ⇒ LlmConversationBuilder
Return to the parent conversation builder.
-
#any_predicate? ⇒ Boolean
private
normalizationis intentionally excluded (a modifier, not a predicate). - #apply_to(client) ⇒ Array<Expectation>
- #build ⇒ Array<Hash>
-
#initialize(parent) ⇒ TurnBuilder
constructor
A new instance of TurnBuilder.
-
#predicates ⇒ Hash?
private
The conversationPredicates Hash, or nil if none set.
- #responding_with(completion) ⇒ self
-
#turn ⇒ TurnBuilder
Start a new turn on the parent conversation builder.
- #when_contains_tool_result_for(tool_name) ⇒ self
- #when_latest_message_contains(text) ⇒ self
- #when_latest_message_matches(regex) ⇒ self
- #when_latest_message_role(role) ⇒ self
- #when_semantic_match(expected_meaning) ⇒ self
- #when_turn_index(index) ⇒ self
- #with_chaos(chaos) ⇒ self
- #with_normalization(normalization) ⇒ self
Constructor Details
#initialize(parent) ⇒ TurnBuilder
Returns a new instance of TurnBuilder.
509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/mockserver/llm.rb', line 509 def initialize(parent) @parent = parent @turn_index = nil @latest_message_contains = nil @latest_message_matches = nil @latest_message_role = nil @contains_tool_result_for = nil @semantic_match_against = nil @normalization = nil @chaos = nil @completion = nil end |
Instance Attribute Details
#chaos ⇒ Object (readonly)
Returns the value of attribute chaos.
507 508 509 |
# File 'lib/mockserver/llm.rb', line 507 def chaos @chaos end |
#completion ⇒ Object (readonly)
Returns the value of attribute completion.
507 508 509 |
# File 'lib/mockserver/llm.rb', line 507 def completion @completion end |
Instance Method Details
#and_then ⇒ LlmConversationBuilder
Return to the parent conversation builder.
586 587 588 |
# File 'lib/mockserver/llm.rb', line 586 def and_then @parent end |
#any_predicate? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
normalization is intentionally excluded (a modifier, not a predicate).
618 619 620 621 622 623 624 625 |
# File 'lib/mockserver/llm.rb', line 618 def any_predicate? !@turn_index.nil? || !@latest_message_contains.nil? || !@latest_message_matches.nil? || !@latest_message_role.nil? || !@contains_tool_result_for.nil? || !@semantic_match_against.nil? end |
#apply_to(client) ⇒ Array<Expectation>
596 597 598 |
# File 'lib/mockserver/llm.rb', line 596 def apply_to(client) @parent.apply_to(client) end |
#build ⇒ Array<Hash>
591 592 593 |
# File 'lib/mockserver/llm.rb', line 591 def build @parent.build end |
#predicates ⇒ Hash?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the conversationPredicates Hash, or nil if none set.
602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/mockserver/llm.rb', line 602 def predicates return nil unless any_predicate? LLM.omit_nil( 'turnIndex' => @turn_index, 'latestMessageContains' => @latest_message_contains, 'latestMessageMatches' => @latest_message_matches, 'latestMessageRole' => @latest_message_role, 'containsToolResultFor' => @contains_tool_result_for, 'semanticMatchAgainst' => @semantic_match_against, 'normalization' => LLM.wire(@normalization) ) end |
#responding_with(completion) ⇒ self
573 574 575 576 |
# File 'lib/mockserver/llm.rb', line 573 def responding_with(completion) @completion = completion self end |
#turn ⇒ TurnBuilder
Start a new turn on the parent conversation builder.
580 581 582 |
# File 'lib/mockserver/llm.rb', line 580 def turn @parent.turn end |
#when_contains_tool_result_for(tool_name) ⇒ self
549 550 551 552 |
# File 'lib/mockserver/llm.rb', line 549 def when_contains_tool_result_for(tool_name) @contains_tool_result_for = tool_name self end |
#when_latest_message_contains(text) ⇒ self
529 530 531 532 |
# File 'lib/mockserver/llm.rb', line 529 def (text) @latest_message_contains = text self end |
#when_latest_message_matches(regex) ⇒ self
535 536 537 538 539 540 |
# File 'lib/mockserver/llm.rb', line 535 def (regex) raise ArgumentError, 'regex must not be nil' if regex.nil? @latest_message_matches = regex.is_a?(Regexp) ? regex.source : regex self end |
#when_latest_message_role(role) ⇒ self
543 544 545 546 |
# File 'lib/mockserver/llm.rb', line 543 def (role) @latest_message_role = role self end |
#when_semantic_match(expected_meaning) ⇒ self
555 556 557 558 |
# File 'lib/mockserver/llm.rb', line 555 def when_semantic_match(expected_meaning) @semantic_match_against = expected_meaning self end |
#when_turn_index(index) ⇒ self
523 524 525 526 |
# File 'lib/mockserver/llm.rb', line 523 def when_turn_index(index) @turn_index = index self end |
#with_chaos(chaos) ⇒ self
567 568 569 570 |
# File 'lib/mockserver/llm.rb', line 567 def with_chaos(chaos) @chaos = chaos self end |
#with_normalization(normalization) ⇒ self
561 562 563 564 |
# File 'lib/mockserver/llm.rb', line 561 def with_normalization(normalization) @normalization = normalization self end |