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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/bandcamp-discover/analyzer.rb +7 -1
- data/lib/bandcamp-discover/version.rb +1 -1
- data/test/analyzer_test.rb +15 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f788095223220ca96084269592bcfacc5ffcd11bdc4ccc27c43312f9a4f019e
|
|
4
|
+
data.tar.gz: d8428295e7b665d2ae448f34f4a84b74bd1290357499d6266e6859fe9b60b7fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97041bbe3141a01e73712b5fa8f1a175ce437ad8ec6f9c38a09447c21e828af10390a248a508d63048447c982b2ac27fcef24bd1f82f285421537aaeb0acbd5a
|
|
7
|
+
data.tar.gz: cd751e7ed3dd432b66e3988c89277cf6b91363193dd3a174f5803a2d34e620ad0ec0a2ad347b4c8636c19d263fedde9beb114d9a7594f7182922bc91bca35fb2
|
data/Gemfile.lock
CHANGED
|
@@ -43,7 +43,13 @@ module BandcampDiscover
|
|
|
43
43
|
extras: {response_format: {type: "json_object"}}
|
|
44
44
|
)
|
|
45
45
|
|
|
46
|
-
|
|
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
|
data/test/analyzer_test.rb
CHANGED
|
@@ -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
|
|