Class: Durable::Llm::Providers::Base
- Inherits:
-
Object
- Object
- Durable::Llm::Providers::Base
show all
- Defined in:
- lib/durable/llm/providers/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(api_key: nil) ⇒ Base
Returns a new instance of Base.
11
12
13
|
# File 'lib/durable/llm/providers/base.rb', line 11
def initialize(api_key: nil)
@api_key = api_key || default_api_key
end
|
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
9
10
11
|
# File 'lib/durable/llm/providers/base.rb', line 9
def api_key
@api_key
end
|
Class Method Details
.models ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/durable/llm/providers/base.rb', line 19
def self.models
cache_dir = File.expand_path("#{Dir.home}/.local/durable-llm/cache")
FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
cache_file = File.join(cache_dir, "#{name.split('::').last}.json")
file_exists = File.exist?(cache_file)
file_new_enough = file_exists && File.mtime(cache_file) > Time.now - 3600
if file_exists && file_new_enough
JSON.parse(File.read(cache_file))
else
models = new.models
File.write(cache_file, JSON.generate(models)) if models.length > 0
models
end
end
|
.stream? ⇒ Boolean
41
42
43
|
# File 'lib/durable/llm/providers/base.rb', line 41
def self.stream?
false
end
|
Instance Method Details
#completion(options) ⇒ Object
15
16
17
|
# File 'lib/durable/llm/providers/base.rb', line 15
def completion(options)
raise NotImplementedError, 'Subclasses must implement completion'
end
|
#default_api_key ⇒ Object
5
6
7
|
# File 'lib/durable/llm/providers/base.rb', line 5
def default_api_key
raise NotImplementedError, 'Subclasses must implement default_api_key'
end
|
#embedding(model:, input:, **options) ⇒ Object
53
54
55
|
# File 'lib/durable/llm/providers/base.rb', line 53
def embedding(model:, input:, **options)
raise NotImplementedError, 'Subclasses must implement embedding'
end
|
#models ⇒ Object
37
38
39
|
# File 'lib/durable/llm/providers/base.rb', line 37
def models
raise NotImplementedError, 'Subclasses must implement models'
end
|
#stream(options, &block) ⇒ Object
49
50
51
|
# File 'lib/durable/llm/providers/base.rb', line 49
def stream(options, &block)
raise NotImplementedError, 'Subclasses must implement stream'
end
|
#stream? ⇒ Boolean
45
46
47
|
# File 'lib/durable/llm/providers/base.rb', line 45
def stream?
self.class.stream?
end
|