bandcamp-discover 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e4dc43f9146747097ff3c34b9a581e02e96ad6e3dc812b84e7c77f1dd459147
4
- data.tar.gz: 208fdb4ae22424fb73d93722bbbb1158703a89c4626a4897dbfb79a5dffa32b1
3
+ metadata.gz: 0f788095223220ca96084269592bcfacc5ffcd11bdc4ccc27c43312f9a4f019e
4
+ data.tar.gz: d8428295e7b665d2ae448f34f4a84b74bd1290357499d6266e6859fe9b60b7fd
5
5
  SHA512:
6
- metadata.gz: 615dd28ade655b5c351249c4e98d1088102bb85d9ad002ca4e0396f49b60bd33c5fe058198f366dab1300f825e2e858a721e5ce715f866a77ce6a6f3afac8b32
7
- data.tar.gz: 6cc60964b92fd4cbc56544c13606397632fd526b4871cd1ae28feaa3cfcde54b1cbf7c6483c9c613e10e09a876a582d42f9d7890575cb0fb097fd5e351cdd3ed
6
+ metadata.gz: 97041bbe3141a01e73712b5fa8f1a175ce437ad8ec6f9c38a09447c21e828af10390a248a508d63048447c982b2ac27fcef24bd1f82f285421537aaeb0acbd5a
7
+ data.tar.gz: cd751e7ed3dd432b66e3988c89277cf6b91363193dd3a174f5803a2d34e620ad0ec0a2ad347b4c8636c19d263fedde9beb114d9a7594f7182922bc91bca35fb2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bandcamp-discover (0.7.0)
4
+ bandcamp-discover (0.7.1)
5
5
  async
6
6
  base64
7
7
  concurrent-ruby
@@ -43,7 +43,13 @@ module BandcampDiscover
43
43
  extras: {response_format: {type: "json_object"}}
44
44
  )
45
45
 
46
- JSON.parse(response["choices"][0]["message"]["content"])["answer"]&.to_s&.downcase == "true"
46
+ answer(response["choices"][0]["message"]["content"])["answer"]&.to_s&.downcase == "true"
47
+ end
48
+
49
+ # response_format is advisory on OpenRouter: Anthropic models return the
50
+ # object inside a ```json fence, and some prepend a sentence.
51
+ def answer(content)
52
+ JSON.parse(content[/\{.*\}/m] || content)
47
53
  end
48
54
 
49
55
  # The bio alone cannot tell one person releasing under aliases from a
@@ -1,3 +1,3 @@
1
1
  module BandcampDiscover
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -23,12 +23,12 @@ module OpenRouter
23
23
 
24
24
  class Client
25
25
  class << self
26
- attr_accessor :requests, :answer
26
+ attr_accessor :requests, :answer, :raw
27
27
  end
28
28
 
29
29
  def complete(messages, model:, extras:)
30
30
  self.class.requests << {messages: messages, model: model, extras: extras}
31
- {"choices" => [{"message" => {"content" => JSON.generate("answer" => self.class.answer)}}]}
31
+ {"choices" => [{"message" => {"content" => self.class.raw || JSON.generate("answer" => self.class.answer)}}]}
32
32
  end
33
33
  end
34
34
  end
@@ -41,6 +41,7 @@ class AnalyzerTest < Minitest::Test
41
41
  OpenRouter.configuration.access_token = "token"
42
42
  OpenRouter::Client.requests = []
43
43
  OpenRouter::Client.answer = true
44
+ OpenRouter::Client.raw = nil
44
45
  end
45
46
 
46
47
  def teardown
@@ -99,6 +100,18 @@ class AnalyzerTest < Minitest::Test
99
100
  assert_equal "", OpenRouter::Client.requests.last[:messages].last[:content]
100
101
  end
101
102
 
103
+ def test_reads_the_answer_out_of_a_markdown_fence
104
+ OpenRouter::Client.raw = "```json\n{\"answer\": false}\n```"
105
+
106
+ refute Analyzer.new("bio").label?
107
+ end
108
+
109
+ def test_reads_the_answer_out_of_surrounding_prose
110
+ OpenRouter::Client.raw = "Sure. {\"answer\": true} Hope that helps."
111
+
112
+ assert Analyzer.new("bio").label?
113
+ end
114
+
102
115
  def test_parses_the_answer
103
116
  OpenRouter::Client.answer = false
104
117
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bandcamp-discover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian RUbisch