Class: Langchain::Assistant::LLM::Adapters::Base

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

Direct Known Subclasses

Anthropic, GoogleGemini, MistralAI, Ollama, OpenAI

Instance Method Summary collapse

Instance Method Details

#build_chat_params(messages:, instructions:, tools:, tool_choice:, parallel_tool_calls:) ⇒ Hash

Build the chat parameters for the LLM

Parameters:

  • The messages

  • The system instructions

  • The tools to use

  • The tool choice

  • Whether to make parallel tool calls

Returns:

  • The chat parameters

Raises:



16
17
18
19
20
21
22
23
24
# File 'lib/langchain/assistant/llm/adapters/base.rb', line 16

def build_chat_params(
  messages:,
  instructions:,
  tools:,
  tool_choice:,
  parallel_tool_calls:
)
  raise NotImplementedError, "Subclasses must implement build_chat_params"
end

#build_message(role:, content: nil, image_url: nil, tool_calls: [], tool_call_id: nil) ⇒ Messages::Base

Build a message for the LLM

Parameters:

  • The role of the message

  • (defaults to: nil)

    The content of the message

  • (defaults to: nil)

    The image URL

  • (defaults to: [])

    The tool calls

  • (defaults to: nil)

    The tool call ID

Returns:

  • The message

Raises:



42
43
44
# File 'lib/langchain/assistant/llm/adapters/base.rb', line 42

def build_message(role:, content: nil, image_url: nil, tool_calls: [], tool_call_id: nil)
  raise NotImplementedError, "Subclasses must implement build_message"
end

#extract_tool_call_args(tool_call:) ⇒ Array

Extract the tool call information from the tool call hash

Parameters:

  • The tool call hash

Returns:

  • The tool call information

Raises:



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

def extract_tool_call_args(tool_call:)
  raise NotImplementedError, "Subclasses must implement extract_tool_call_args"
end

#support_system_message?Boolean

Does this adapter accept messages with role=“system”?

Returns:

  • Whether the adapter supports system messages

Raises:



49
50
51
# File 'lib/langchain/assistant/llm/adapters/base.rb', line 49

def support_system_message?
  raise NotImplementedError, "Subclasses must implement support_system_message?"
end

#tool_roleString

Role name used to return the tool output

Returns:

  • The tool role

Raises:



56
57
58
# File 'lib/langchain/assistant/llm/adapters/base.rb', line 56

def tool_role
  raise NotImplementedError, "Subclasses must implement tool_role"
end