Class: Langchain::Assistant::Messages::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/langchain/assistant/messages/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/langchain/assistant/messages/base.rb', line 7

def content
  @content
end

#image_urlObject (readonly)

Returns the value of attribute image_url.



7
8
9
# File 'lib/langchain/assistant/messages/base.rb', line 7

def image_url
  @image_url
end

#roleObject (readonly)

Returns the value of attribute role.



7
8
9
# File 'lib/langchain/assistant/messages/base.rb', line 7

def role
  @role
end

#tool_call_idObject (readonly)

Returns the value of attribute tool_call_id.



7
8
9
# File 'lib/langchain/assistant/messages/base.rb', line 7

def tool_call_id
  @tool_call_id
end

#tool_callsObject (readonly)

Returns the value of attribute tool_calls.



7
8
9
# File 'lib/langchain/assistant/messages/base.rb', line 7

def tool_calls
  @tool_calls
end

Instance Method Details

#llm?Boolean

Check if the message came from an LLM

Returns:

  • (Boolean)

Raises:

  • NotImplementedError if the subclass does not implement this method



23
24
25
# File 'lib/langchain/assistant/messages/base.rb', line 23

def llm?
  raise NotImplementedError, "Class #{self.class.name} must implement the method 'llm?'"
end

#standard_roleSymbol

Returns the standardized role symbol based on the specific role methods

Returns:

  • (Symbol)

    the standardized role symbol (:system, :llm, :tool, :user, or :unknown)



44
45
46
47
48
49
50
51
52
# File 'lib/langchain/assistant/messages/base.rb', line 44

def standard_role
  return :user if user?
  return :llm if llm?
  return :tool if tool?
  return :system if system?

  # TODO: Should we return :unknown or raise an error?
  :unknown
end

#system?Boolean

Check if the message is a system prompt

Returns:

  • (Boolean)

Raises:

  • NotImplementedError if the subclass does not implement this method



37
38
39
# File 'lib/langchain/assistant/messages/base.rb', line 37

def system?
  raise NotImplementedError, "Class #{self.class.name} must implement the method 'system?'"
end

#tool?Boolean

Check if the message is a tool call

Returns:

  • (Boolean)

Raises:

  • NotImplementedError if the subclass does not implement this method



30
31
32
# File 'lib/langchain/assistant/messages/base.rb', line 30

def tool?
  raise NotImplementedError, "Class #{self.class.name} must implement the method 'tool?'"
end

#user?Boolean

Check if the message came from a user

Returns:

  • (Boolean)

    true/false whether the message came from a user



16
17
18
# File 'lib/langchain/assistant/messages/base.rb', line 16

def user?
  role == "user"
end