Class: LLM::Provider
Overview
The Provider class represents an abstract class for LLM (Language Model) providers
Instance Method Summary collapse
-
#assistant_role ⇒ String
Returns the role of the assistant in the conversation.
-
#chat(prompt, role = :user, **params) ⇒ LLM::LazyConversation
Starts a new lazy conversation.
-
#chat!(prompt, role = :user, **params) ⇒ LLM::Conversation
Starts a new conversation.
-
#complete(prompt, role = :user, **params) ⇒ LLM::Response::Completion
Completes a given prompt using the LLM.
- #embed(input, **params) ⇒ LLM::Response::Embedding
-
#initialize(secret, host:, port: 443, timeout: 60, ssl: true) ⇒ Provider
constructor
A new instance of Provider.
-
#inspect ⇒ String
Returns an inspection of the provider object.
-
#models ⇒ Hash<String, LLM::Model>
Returns a hash of available models.
Methods included from HTTPClient
Constructor Details
#initialize(secret, host:, port: 443, timeout: 60, ssl: true) ⇒ Provider
Returns a new instance of Provider.
19 20 21 22 23 24 25 |
# File 'lib/llm/provider.rb', line 19 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
#assistant_role ⇒ String
Returns the role of the assistant in the conversation. Usually “assistant” or “model”
82 83 84 |
# File 'lib/llm/provider.rb', line 82 def assistant_role raise NotImplementedError end |
#chat(prompt, role = :user, **params) ⇒ LLM::LazyConversation
Starts a new lazy conversation
64 65 66 |
# File 'lib/llm/provider.rb', line 64 def chat(prompt, role = :user, **params) LLM::LazyConversation.new(self, params).chat(prompt, role) end |
#chat!(prompt, role = :user, **params) ⇒ LLM::Conversation
Starts a new conversation
74 75 76 |
# File 'lib/llm/provider.rb', line 74 def chat!(prompt, role = :user, **params) LLM::Conversation.new(self, params).chat(prompt, role) end |
#complete(prompt, role = :user, **params) ⇒ LLM::Response::Completion
Completes a given prompt using the LLM
54 55 56 |
# File 'lib/llm/provider.rb', line 54 def complete(prompt, role = :user, **params) raise NotImplementedError end |
#embed(input, **params) ⇒ LLM::Response::Embedding
41 42 43 |
# File 'lib/llm/provider.rb', line 41 def (input, **params) raise NotImplementedError end |
#inspect ⇒ String
Note:
The secret key is redacted in inspect for security reasons
Returns an inspection of the provider object
31 32 33 |
# File 'lib/llm/provider.rb', line 31 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} @secret=[REDACTED] @http=#{@http.inspect}>" end |
#models ⇒ Hash<String, LLM::Model>
Returns a hash of available models
89 90 91 |
# File 'lib/llm/provider.rb', line 89 def models raise NotImplementedError end |