Class: MockServer::LLM::TurnBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/llm.rb

Overview

TurnBuilder — one turn within a conversation.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#chaosObject (readonly)

Returns the value of attribute chaos.



507
508
509
# File 'lib/mockserver/llm.rb', line 507

def chaos
  @chaos
end

#completionObject (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_thenLlmConversationBuilder

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).

Returns:

  • (Boolean)


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>

Returns:



596
597
598
# File 'lib/mockserver/llm.rb', line 596

def apply_to(client)
  @parent.apply_to(client)
end

#buildArray<Hash>

Returns:

  • (Array<Hash>)


591
592
593
# File 'lib/mockserver/llm.rb', line 591

def build
  @parent.build
end

#predicatesHash?

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.

Returns:

  • (Hash, nil)

    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

Returns:

  • (self)


573
574
575
576
# File 'lib/mockserver/llm.rb', line 573

def responding_with(completion)
  @completion = completion
  self
end

#turnTurnBuilder

Start a new turn on the parent conversation builder.

Returns:



580
581
582
# File 'lib/mockserver/llm.rb', line 580

def turn
  @parent.turn
end

#when_contains_tool_result_for(tool_name) ⇒ self

Returns:

  • (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

Returns:

  • (self)


529
530
531
532
# File 'lib/mockserver/llm.rb', line 529

def when_latest_message_contains(text)
  @latest_message_contains = text
  self
end

#when_latest_message_matches(regex) ⇒ self

Returns:

  • (self)

Raises:

  • (ArgumentError)


535
536
537
538
539
540
# File 'lib/mockserver/llm.rb', line 535

def when_latest_message_matches(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

Returns:

  • (self)


543
544
545
546
# File 'lib/mockserver/llm.rb', line 543

def when_latest_message_role(role)
  @latest_message_role = role
  self
end

#when_semantic_match(expected_meaning) ⇒ self

Returns:

  • (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

Returns:

  • (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

Returns:

  • (self)


567
568
569
570
# File 'lib/mockserver/llm.rb', line 567

def with_chaos(chaos)
  @chaos = chaos
  self
end

#with_normalization(normalization) ⇒ self

Returns:

  • (self)


561
562
563
564
# File 'lib/mockserver/llm.rb', line 561

def with_normalization(normalization)
  @normalization = normalization
  self
end