Class: BxBuilderChain::Llm::Base Abstract
- Inherits:
-
Object
- Object
- BxBuilderChain::Llm::Base
- Includes:
- DependencyHelper
- Defined in:
- lib/bx_builder_chain/llm/base.rb
Overview
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.
BxBuilderChain.rb provides a common interface to interact with all supported LLMs:
-
OpenAI
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
A client for communicating with the LLM.
Instance Method Summary collapse
-
#chat(**kwargs) ⇒ Object
Generate a chat completion for a given prompt.
-
#complete(**kwargs) ⇒ Object
Generate a completion for a given prompt.
- #count_tokens(string) ⇒ Object
- #default_dimension ⇒ Object
-
#embed(**kwargs) ⇒ Object
Generate an embedding for a given text.
-
#summarize(**kwargs) ⇒ Object
Generate a summary for a given text.
Methods included from DependencyHelper
Instance Attribute Details
#client ⇒ Object (readonly)
A client for communicating with the LLM
17 18 19 |
# File 'lib/bx_builder_chain/llm/base.rb', line 17 def client @client end |
Instance Method Details
#chat(**kwargs) ⇒ Object
Generate a chat completion for a given prompt. Parameters will depend on the LLM
27 28 29 |
# File 'lib/bx_builder_chain/llm/base.rb', line 27 def chat(**kwargs) raise NotImplementedError, "#{self.class.name} does not support chat" end |
#complete(**kwargs) ⇒ Object
Generate a completion for a given prompt. Parameters will depend on the LLM.
35 36 37 |
# File 'lib/bx_builder_chain/llm/base.rb', line 35 def complete(**kwargs) raise NotImplementedError, "#{self.class.name} does not support completion" end |
#count_tokens(string) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/bx_builder_chain/llm/base.rb', line 57 def count_tokens(string) tokens = string.scan(/[\w]+|[\W]/) tokens = tokens.flat_map { |token| token.split(/(?<=[\W])$/) } return (tokens.length*1.07).to_i end |
#default_dimension ⇒ Object
19 20 21 |
# File 'lib/bx_builder_chain/llm/base.rb', line 19 def default_dimension self.class.const_get(:DEFAULTS).dig(:dimension) end |
#embed(**kwargs) ⇒ Object
Generate an embedding for a given text. Parameters depends on the LLM.
44 45 46 |
# File 'lib/bx_builder_chain/llm/base.rb', line 44 def (**kwargs) raise NotImplementedError, "#{self.class.name} does not support generating embeddings" end |
#summarize(**kwargs) ⇒ Object
Generate a summary for a given text. Parameters depends on the LLM.
53 54 55 |
# File 'lib/bx_builder_chain/llm/base.rb', line 53 def summarize(**kwargs) raise NotImplementedError, "#{self.class.name} does not support summarization" end |