Class: LLM::Provider Abstract
Overview
This class is not meant to be instantiated directly. Instead, use one of the subclasses that implement the methods defined here.
The Provider class represents an abstract class for LLM (Language Model) providers.
Instance Method Summary collapse
-
#models ⇒ Hash<String, LLM::Model>
Returns a hash of available models.
-
#inspect ⇒ String
Returns an inspection of the provider object.
-
#embed(input, **params) ⇒ LLM::Response::Embedding
-
#complete(prompt, role = :user, **params) ⇒ LLM::Response::Completion
Completes a given prompt using the LLM.
-
#chat(prompt, role = :user, **params) ⇒ LLM::LazyConversation
Starts a new lazy conversation.
-
#chat!(prompt, role = :user, **params) ⇒ LLM::Conversation
Starts a new conversation.
-
#assistant_role ⇒ String
Returns the role of the assistant in the conversation.
-
#initialize(secret, host:, port: 443, timeout: 60, ssl: true) ⇒ Provider
constructor
A new instance of Provider.
Methods included from HTTPClient
Constructor Details
#initialize(secret, host:, port: 443, timeout: 60, ssl: true) ⇒ Provider
Returns a new instance of Provider.
30 31 32 33 34 35 36 |
# File 'lib/llm/provider.rb', line 30 def initialize(secret, host:, port: 443, timeout: 60, ssl: true) @secret = secret @http = Net::HTTP.new(host, port).tap do |http| http.use_ssl = ssl http.read_timeout = timeout end end |
Instance Method Details
#models ⇒ Hash<String, LLM::Model>
Returns a hash of available models
116 117 118 |
# File 'lib/llm/provider.rb', line 116 def models raise NotImplementedError end |
#inspect ⇒ String
The secret key is redacted in inspect for security reasons
Returns an inspection of the provider object
42 43 44 |
# File 'lib/llm/provider.rb', line 42 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} @secret=[REDACTED] @http=#{@http.inspect}>" end |
#embed(input, **params) ⇒ LLM::Response::Embedding
52 53 54 |
# File 'lib/llm/provider.rb', line 52 def (input, **params) raise NotImplementedError end |
#complete(prompt, role = :user, **params) ⇒ LLM::Response::Completion
Completes a given prompt using the LLM
75 76 77 |
# File 'lib/llm/provider.rb', line 75 def complete(prompt, role = :user, **params) raise NotImplementedError end |
#chat(prompt, role = :user, **params) ⇒ LLM::LazyConversation
This method creates a lazy variant of a LLM::Conversation object.
Starts a new lazy conversation
88 89 90 |
# File 'lib/llm/provider.rb', line 88 def chat(prompt, role = :user, **params) LLM::Conversation.new(self, params).lazy.chat(prompt, role) end |
#chat!(prompt, role = :user, **params) ⇒ LLM::Conversation
This method creates a non-lazy variant of a LLM::Conversation object.
Starts a new conversation
101 102 103 |
# File 'lib/llm/provider.rb', line 101 def chat!(prompt, role = :user, **params) LLM::Conversation.new(self, params).chat(prompt, role) end |
#assistant_role ⇒ String
Returns the role of the assistant in the conversation. Usually “assistant” or “model”
109 110 111 |
# File 'lib/llm/provider.rb', line 109 def assistant_role raise NotImplementedError end |