Class: Durable::Llm::Client
- Inherits:
-
Object
- Object
- Durable::Llm::Client
- Defined in:
- lib/durable/llm/client.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
- #chat(params = {}) ⇒ Object
- #completion(params = {}) ⇒ Object
- #default_params ⇒ Object
- #embed(params = {}) ⇒ Object
-
#initialize(provider_name, options = {}) ⇒ Client
constructor
A new instance of Client.
- #quick_complete(text, _opts = {}) ⇒ Object
- #stream(params = {}, &block) ⇒ Object
- #stream? ⇒ Boolean
Constructor Details
#initialize(provider_name, options = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 |
# File 'lib/durable/llm/client.rb', line 10 def initialize(provider_name, = {}) @model = .delete('model') || .delete(:model) if ['model'] || [:model] provider_class = Durable::Llm::Providers.const_get(provider_name.to_s.capitalize) @provider = provider_class.new(**) end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
8 9 10 |
# File 'lib/durable/llm/client.rb', line 8 def model @model end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
7 8 9 |
# File 'lib/durable/llm/client.rb', line 7 def provider @provider end |
Instance Method Details
#chat(params = {}) ⇒ Object
32 33 34 |
# File 'lib/durable/llm/client.rb', line 32 def chat(params = {}) @provider.chat(process_params(params)) end |
#completion(params = {}) ⇒ Object
28 29 30 |
# File 'lib/durable/llm/client.rb', line 28 def completion(params = {}) @provider.completion(process_params(params)) end |
#default_params ⇒ Object
18 19 20 |
# File 'lib/durable/llm/client.rb', line 18 def default_params { model: @model } end |
#embed(params = {}) ⇒ Object
36 37 38 |
# File 'lib/durable/llm/client.rb', line 36 def (params = {}) @provider.(process_params(params)) end |
#quick_complete(text, _opts = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/durable/llm/client.rb', line 22 def quick_complete(text, _opts = {}) response = completion(process_params(messages: [{ role: 'user', content: text }])) response.choices.first..content end |
#stream(params = {}, &block) ⇒ Object
40 41 42 |
# File 'lib/durable/llm/client.rb', line 40 def stream(params = {}, &block) @provider.stream(process_params(params), &block) end |
#stream? ⇒ Boolean
44 45 46 |
# File 'lib/durable/llm/client.rb', line 44 def stream? @provider.stream? end |