Class: Durable::Llm::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/durable/llm/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @model = options.delete('model') || options.delete(:model) if options['model'] || options[:model]

  provider_class = Durable::Llm::Providers.const_get(provider_name.to_s.capitalize)

  @provider = provider_class.new(**options)
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



8
9
10
# File 'lib/durable/llm/client.rb', line 8

def model
  @model
end

#providerObject (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_paramsObject



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 embed(params = {})
  @provider.embed(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.message.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

Returns:

  • (Boolean)


44
45
46
# File 'lib/durable/llm/client.rb', line 44

def stream?
  @provider.stream?
end