Class: BandcampDiscover::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/bandcamp-discover/analyzer.rb

Instance Method Summary collapse

Constructor Details

#initialize(description, model = nil) ⇒ Analyzer

Returns a new instance of Analyzer.



3
4
5
6
# File 'lib/bandcamp-discover/analyzer.rb', line 3

def initialize(description, model = nil)
  @description = description
  @model = model || "openrouter/auto"
end

Instance Method Details

#accepts_demos?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bandcamp-discover/analyzer.rb', line 31

def accepts_demos?
  if defined?(OpenRouter) && !!OpenRouter.configuration.access_token
    response = OpenRouter::Client.new.complete(
      [
        { role: "system", content: "You are given a description of a record label or music platform. Analyze if they accept demo submissions from artists. Look for mentions of 'demos', 'demo submissions', 'send demos', 'submit music', 'accepting submissions', contact information for demos, or similar language. Be critical, and default to false. Only answer with true when you are certain that the label accepts demos. Answer with a JSON object {\"answer\": true|false}." },
        { role: "user", content: @description }
      ],
      model: [
        @model
      ],
      extras: {
        response_format: {
          type: "json_object"
        }
      }
    )

    JSON.parse(response["choices"][0]["message"]["content"])["answer"]&.to_s&.downcase == "true"
  else
    false
  end
end

#label?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bandcamp-discover/analyzer.rb', line 8

def label?
  if defined?(OpenRouter) && !!OpenRouter.configuration.access_token
    response = OpenRouter::Client.new.complete(
      [
        { role: "system", content: "You are given a description that could or could not be that of a record label. Analyze and answer witha JSON object  {\"answer\": true|false}. Be critical: Individuals and bands are not labels, but collectives can be labels." },
        { role: "user", content: @description }
      ],
      model: [
        @model
      ],
      extras: {
        response_format: {
          type: "json_object"
        }
      }
    )

    JSON.parse(response["choices"][0]["message"]["content"])["answer"]&.to_s&.downcase == "true"
  else
    @description.match? /label|platform|records/i
  end
end