ask-web-search 0.7.0 → 0.8.0
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/lib/ask/web_search/version.rb +1 -1
- data/lib/ask/web_search.rb +32 -6
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b83b3aa3b4e051445e316284580fa85a0d478bb5256b60c87e14031e60c6130
|
|
4
|
+
data.tar.gz: '0168f632c9d32eb42996d55f197cf2a322ad86f839b7698788c9f0cfc2e8ba87'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e5cb4c7817665ca81783898ea4709e7883786f5db18778ec09a7375ef4f2abadecc77c001900a48aea277e3b18859e11a9b2c1f1cc97ecb8ded1fb6e29478f7
|
|
7
|
+
data.tar.gz: 889707ff4c5f114ffbd2340cd667de622c281374e20fdee3023280706b8bad91ad3d46b02091274779a2e1ce8ed7acbb5bcad7669cb0f616765af50d6244a282
|
data/lib/ask/web_search.rb
CHANGED
|
@@ -48,7 +48,9 @@ module Ask
|
|
|
48
48
|
|
|
49
49
|
# TinyFish's hosted search endpoint — the primary backend for anyone
|
|
50
50
|
# holding a (free) TINYFISH_API_KEY, so no SearXNG instance is needed.
|
|
51
|
-
|
|
51
|
+
# The bare host root per the official docs curl example; the
|
|
52
|
+
# /client.search.query path seen on the marketing pages 404s.
|
|
53
|
+
TINYFISH_SEARCH_URL = "https://api.search.tinyfish.ai"
|
|
52
54
|
|
|
53
55
|
# Our time_range → TinyFish's recency_minutes (SearXNG's month/year
|
|
54
56
|
# are approximate engine filters anyway; these are the equivalents).
|
|
@@ -70,13 +72,25 @@ module Ask
|
|
|
70
72
|
"research_paper" => "research_paper"
|
|
71
73
|
}.freeze
|
|
72
74
|
|
|
73
|
-
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
75
|
+
# The TinyFish API key: ask-auth's chain when that gem is present
|
|
76
|
+
# (env override → ~/.ask/credentials.yml → …), raw ENV otherwise.
|
|
77
|
+
# nil when nothing resolves.
|
|
78
|
+
def self.tinyfish_api_key
|
|
79
|
+
return ENV["TINYFISH_API_KEY"] unless defined?(Ask::Auth)
|
|
80
|
+
|
|
81
|
+
Ask::Auth.resolve(:tinyfish_api_key)
|
|
82
|
+
rescue Ask::Auth::MissingCredential
|
|
83
|
+
nil
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# True when TinyFish should be the primary backend: a key resolves
|
|
87
|
+
# (#tinyfish_api_key) and TINYFISH_SEARCH=0 has not disabled it.
|
|
88
|
+
# Read fresh on every call so tests and config reloads don't need
|
|
89
|
+
# memo resets.
|
|
76
90
|
def self.use_tinyfish?
|
|
77
91
|
return false if ENV["TINYFISH_SEARCH"] == "0"
|
|
78
92
|
|
|
79
|
-
!
|
|
93
|
+
!tinyfish_api_key.to_s.empty?
|
|
80
94
|
end
|
|
81
95
|
|
|
82
96
|
# True when a SearXNG endpoint was configured explicitly (SEARXNG_URL
|
|
@@ -210,7 +224,7 @@ module Ask
|
|
|
210
224
|
http.open_timeout = 5
|
|
211
225
|
http.read_timeout = 10
|
|
212
226
|
req = Net::HTTP::Get.new(uri)
|
|
213
|
-
req["X-API-Key"] =
|
|
227
|
+
req["X-API-Key"] = tinyfish_api_key
|
|
214
228
|
req["User-Agent"] = "ask-web-search/#{Ask::WebSearch::VERSION}"
|
|
215
229
|
res = http.request(req)
|
|
216
230
|
raise Error, "TinyFish returned #{res.code}: #{res.body[0, 200]}" unless res.code.start_with?("2")
|
|
@@ -330,3 +344,15 @@ begin
|
|
|
330
344
|
rescue LoadError => e
|
|
331
345
|
raise unless e.path == "ask-tools"
|
|
332
346
|
end
|
|
347
|
+
|
|
348
|
+
# ask-auth is an OPTIONAL credential source for the TinyFish key: when
|
|
349
|
+
# present, #tinyfish_api_key resolves through Ask::Auth (env override →
|
|
350
|
+
# ~/.ask/credentials.yml → …) instead of raw ENV alone, so the key can
|
|
351
|
+
# live in one canonical 0600 file instead of every config that spawns a
|
|
352
|
+
# server. Only the ask-auth miss is swallowed; any other LoadError is
|
|
353
|
+
# real.
|
|
354
|
+
begin
|
|
355
|
+
require "ask-auth"
|
|
356
|
+
rescue LoadError => e
|
|
357
|
+
raise unless e.path == "ask-auth"
|
|
358
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ask-web-search
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kaka Ruto
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: ask-auth
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0.3'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0.3'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: vcr
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|