Module: LLM::RequestAdapter::Role Private

Included in:
Bedrock::RequestAdapter::Completion
Defined in:
lib/llm/request_adapter/role.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Maps a saved role to the role a provider expects.

Messages are saved with an abstract role: assistant for a model reply, tool for a tool return. The provider's spelling is produced here, at assembly time, and is never stored. Google writes model, Anthropic wants tool returns under user.

Instance Method Summary collapse

Instance Method Details

#adapt_role(role) ⇒ String

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 role the provider expects.

Parameters:

  • role (Symbol, String) —

    An abstract role

Returns:

  • (String) —

    The role the provider expects



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/llm/request_adapter/role.rb', line 21

def adapt_role(role)
  role = case role.to_s
  when "assistant", "model" then llm.assistant_role
  when "tool" then llm.tool_role
  when "system" then llm.system_role
  when "developer" then llm.developer_role
  when "user" then llm.user_role
  else role
  end
  role.to_s
end

#adapt_message_role(message) ⇒ String

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 role a message is sent under.

Parameters:

Returns:

  • (String) —

    The role a message is sent under



37
38
39
40
41
42
43
# File 'lib/llm/request_adapter/role.rb', line 37

def adapt_message_role(message)
  ##
  # A Hash isn't something the runtime saves,
  # so it carries no abstract role to map.
  return message[:role].to_s if Hash === message
  adapt_role(message.role)
end