summaryrefslogtreecommitdiff
path: root/logic/cartridge/streaming.rb
blob: 0b9b19ffd5860b03c312bb2b00ecb4f15058bbe3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

require_relative '../helpers/hash'

module NanoBot
  module Logic
    module Cartridge
      module Streaming
        def self.enabled?(cartridge, interface)
          provider_stream = case Helpers::Hash.fetch(cartridge, %i[provider id])
                            when 'openai', 'mistral'
                              Helpers::Hash.fetch(cartridge, %i[provider settings stream])
                            when 'google'
                              Helpers::Hash.fetch(cartridge, %i[provider options stream])
                            end

          return false if provider_stream == false

          specific_interface = Helpers::Hash.fetch(cartridge, [:interfaces, interface, :output, :stream])

          return specific_interface unless specific_interface.nil?

          interface = Helpers::Hash.fetch(cartridge, %i[interfaces output stream])

          return interface unless interface.nil?

          true
        end
      end
    end
  end
end