Class: Langchain::LLM::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
DependencyHelper
Defined in:
lib/langchain/llm/base.rb

Overview

This class is abstract.

A LLM is a language model consisting of a neural network with many parameters (typically billions of weights or more), trained on large quantities of unlabeled text using self-supervised learning or semi-supervised learning.

Langchain.rb provides a common interface to interact with all supported LLMs:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DependencyHelper

#depends_on

Instance Attribute Details

#clientObject

A client for communicating with the LLM



24
25
26
# File 'lib/langchain/llm/base.rb', line 24

def client
  @client
end

#defaultsObject (readonly)

Default LLM options. Can be overridden by passing ‘default_options: {}` to the Langchain::LLM::* constructors.



27
28
29
# File 'lib/langchain/llm/base.rb', line 27

def defaults
  @defaults
end

Instance Method Details

#chatObject

Generate a chat completion for a given prompt. Parameters will depend on the LLM

Raises:

  • NotImplementedError if not supported by the LLM



46
47
48
# File 'lib/langchain/llm/base.rb', line 46

def chat(...)
  raise NotImplementedError, "#{self.class.name} does not support chat"
end

#chat_parameters(params = {}) ⇒ Object

Returns an instance of Langchain::LLM::Parameters::Chat



79
80
81
82
83
# File 'lib/langchain/llm/base.rb', line 79

def chat_parameters(params = {})
  @chat_parameters ||= Langchain::LLM::Parameters::Chat.new(
    parameters: params
  )
end

#completeObject

Generate a completion for a given prompt. Parameters will depend on the LLM.

Raises:

  • NotImplementedError if not supported by the LLM



54
55
56
# File 'lib/langchain/llm/base.rb', line 54

def complete(...)
  raise NotImplementedError, "#{self.class.name} does not support completion"
end

#default_dimensionObject

Ensuring backward compatibility after github.com/patterns-ai-core/langchainrb/pull/586 TODO: Delete this method later



31
32
33
# File 'lib/langchain/llm/base.rb', line 31

def default_dimension
  default_dimensions
end

#default_dimensionsInteger

Returns the number of vector dimensions used by DEFAULTS

Returns:

  • (Integer)

    Vector dimensions



38
39
40
# File 'lib/langchain/llm/base.rb', line 38

def default_dimensions
  self.class.const_get(:DEFAULTS).dig(:dimensions)
end

#embedObject

Generate an embedding for a given text. Parameters depends on the LLM.

Raises:

  • NotImplementedError if not supported by the LLM



63
64
65
# File 'lib/langchain/llm/base.rb', line 63

def embed(...)
  raise NotImplementedError, "#{self.class.name} does not support generating embeddings"
end

#summarizeObject

Generate a summary for a given text. Parameters depends on the LLM.

Raises:

  • NotImplementedError if not supported by the LLM



72
73
74
# File 'lib/langchain/llm/base.rb', line 72

def summarize(...)
  raise NotImplementedError, "#{self.class.name} does not support summarization"
end