Class: PodcastBuddy::SystemDependency

Inherits:
Struct
  • Object
show all
Defined in:
lib/podcast_buddy/system_dependency.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type: :system) ⇒ SystemDependency

Returns a new instance of SystemDependency.



8
9
10
11
# File 'lib/podcast_buddy/system_dependency.rb', line 8

def initialize(name:, type: :system)
  @name = name
  @type = type || :system
end

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/podcast_buddy/system_dependency.rb', line 4

def name
  @name
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



4
5
6
# File 'lib/podcast_buddy/system_dependency.rb', line 4

def type
  @type
end

Class Method Details

.auto_install!(name) ⇒ Object



13
14
15
16
# File 'lib/podcast_buddy/system_dependency.rb', line 13

def self.auto_install!(name)
  system_dependency = new(name: name, type: :system)
  system_dependency.install unless system_dependency.installed?
end

.download_model(model) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/podcast_buddy/system_dependency.rb', line 27

def self.download_model(model)
  originating_directory = Dir.pwd
  Dir.chdir("whisper.cpp")
  PodcastBuddy.logger.info "Downloading GGML model: #{PodcastBuddy.whisper_model}"
  PodcastBuddy.logger.info `bash ./models/download-ggml-model.sh #{PodcastBuddy.whisper_model}`
ensure
  Dir.chdir(originating_directory)
end

.model_downloaded?(model) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/podcast_buddy/system_dependency.rb', line 23

def self.model_downloaded?(model)
  File.exist?(File.join(PodcastBuddy.root, "whisper.cpp", "models", "ggml-#{model}.bin"))
end

.resolve_whisper_model(model) ⇒ Object



18
19
20
21
# File 'lib/podcast_buddy/system_dependency.rb', line 18

def self.resolve_whisper_model(model)
  return if model_downloaded?(model)
  download_model(model)
end

Instance Method Details

#installObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/podcast_buddy/system_dependency.rb', line 45

def install
  PodcastBuddy.logger.info "Installing #{name}..."
  originating_directory = Dir.pwd
  if name.to_s == "whisper"
    Dir.chdir(PodcastBuddy.root)
    PodcastBuddy.logger.info `git clone https://github.com/ggerganov/whisper.cpp`
    Dir.chdir("whisper.cpp")
    PodcastBuddy.logger.info "Downloading GGML model: #{PodcastBuddy.whisper_model}"
    PodcastBuddy.logger.info `bash ./models/download-ggml-model.sh #{PodcastBuddy.whisper_model}`
    PodcastBuddy.logger.info `make && make stream`
  else
    `brew list #{name} || brew install #{name}`
  end
ensure
  Dir.chdir(originating_directory)
end

#installed?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/podcast_buddy/system_dependency.rb', line 36

def installed?
  PodcastBuddy.logger.info "Checking for system dependency: #{name}..."
  if name.to_s == "whisper"
    Dir.exist?("whisper.cpp")
  else
    system("brew list -1 #{name} > /dev/null") || system("type -a #{name}")
  end
end