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:

  • messages (Array)

    The messages

  • instructions (String)

    The system instructions

  • tools (Array)

    The tools to use

  • tool_choice (String)

    The tool choice

  • parallel_tool_calls (Boolean)

    Whether to make parallel tool calls

Returns:

  • (Hash)

    The chat parameters

Raises:

  • (NotImplementedError)


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:

  • role (String)

    The role of the message

  • content (String) (defaults to: nil)

    The content of the message

  • image_url (String) (defaults to: nil)

    The image URL

  • tool_calls (Array) (defaults to: [])

    The tool calls

  • tool_call_id (String) (defaults to: nil)

    The tool call ID

Returns:

Raises:

  • (NotImplementedError)


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:

  • tool_call (Hash)

    The tool call hash

Returns:

  • (Array)

    The tool call information

Raises:

  • (NotImplementedError)


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:

  • (Boolean)

    Whether the adapter supports system messages

Raises:

  • (NotImplementedError)


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:

  • (String)

    The tool role

Raises:

  • (NotImplementedError)


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

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