ask-web-search 0.2.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +104 -0
- data/lib/ask/web_search/tool.rb +67 -0
- data/lib/ask/web_search/version.rb +5 -0
- data/lib/ask/web_search.rb +2 -0
- data/lib/ask-web-search.rb +1 -0
- metadata +93 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fb54630bbd045d98988c9c09a75de1034b661f58557ca2382341b457410afbcb
|
|
4
|
+
data.tar.gz: 16528fa60924c43f4492028ee1f7d91a8f4b834253473501cbc2536bd401e2cc
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7e9b65c07f603682f3ce93b9a6056296f71e066f842b7aa3abefbe83a7a9783ce443b566d1dfc2ecf1bb5c11abdd3b406227e5db3846f10578152b4398bcb9bf
|
|
7
|
+
data.tar.gz: 1a46d1527807fb70a4169961fa0e5b56efb5a96e696c1d2d1c465ee8f4911bfaa2591c45220e6574b1d6bddfa2538ea57e21ed9e6d160d9c3feb8eb4e721cd8a
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kaka Ruto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# ask-web-search
|
|
2
|
+
|
|
3
|
+
A web search tool for the ask-rb ecosystem. Provides `Ask::Tools::WebSearch`, which
|
|
4
|
+
searches the web via a local [SearXNG](https://docs.searxng.org/) instance and returns
|
|
5
|
+
formatted results for LLM consumption.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
A running SearXNG instance. The default is `http://localhost:8888`.
|
|
10
|
+
|
|
11
|
+
Start one with Docker:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
docker run -d --name searxng -p 8888:8080 searxng/searxng
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or use the provided `docker-compose.yml`:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
cd searxng
|
|
21
|
+
docker compose up -d
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
gem install ask-web-search
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or in your Gemfile:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
gem "ask-web-search"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
Set the `SEARXNG_URL` environment variable to point to your SearXNG instance:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
export SEARXNG_URL=http://localhost:8888
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Defaults to `http://localhost:8888`.
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
require "ask/web_search"
|
|
50
|
+
|
|
51
|
+
tool = Ask::Tools::WebSearch.new
|
|
52
|
+
result = tool.execute(query: "ruby programming language")
|
|
53
|
+
puts result
|
|
54
|
+
# => 1. Ruby — A Programmer's Best Friend
|
|
55
|
+
# https://www.ruby-lang.org
|
|
56
|
+
# Ruby is a dynamic, open-source programming language...
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### With ask-rb Chat
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
chat = Ask::Agent::Chat.new(
|
|
63
|
+
model: "deepseek-v4-flash",
|
|
64
|
+
tools: [Ask::Tools::WebSearch.new]
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
chat.ask("What's the latest on AI? Search the web.")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### With ask-rb Agent
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
agent = Ask::Agent.new(tools: [Ask::Tools::WebSearch])
|
|
74
|
+
agent.run("Find recent news about SpaceX")
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Output Format
|
|
78
|
+
|
|
79
|
+
Results are returned as a numbered markdown-like string:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
1. Ruby — A Programmer's Best Friend
|
|
83
|
+
https://www.ruby-lang.org
|
|
84
|
+
Ruby is a dynamic, open-source programming language...
|
|
85
|
+
|
|
86
|
+
2. Ruby on Rails
|
|
87
|
+
https://rubyonrails.org
|
|
88
|
+
Rails is a web application framework...
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If no results are found, returns `"No results found."`.
|
|
92
|
+
|
|
93
|
+
## Development
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
git clone https://github.com/ask-rb/ask-web-search
|
|
97
|
+
cd ask-web-search
|
|
98
|
+
bundle install
|
|
99
|
+
bundle exec rake test
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require "ask/tools"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
module Ask
|
|
7
|
+
module Tools
|
|
8
|
+
class WebSearch < Ask::Tool
|
|
9
|
+
SEARXNG_URL = ENV.fetch("SEARXNG_URL", "http://localhost:8888")
|
|
10
|
+
|
|
11
|
+
description "Search the web for current information. Use this to get up-to-date results, recent events, or facts that may have changed."
|
|
12
|
+
|
|
13
|
+
params(
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
query: { type: "string", description: "The search query" }
|
|
17
|
+
},
|
|
18
|
+
required: ["query"]
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
def execute(query:)
|
|
22
|
+
results = search(query)
|
|
23
|
+
format_results(results)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def search(query)
|
|
29
|
+
uri = URI("#{SEARXNG_URL}/search?q=#{URI.encode_www_form_component(query)}&format=json")
|
|
30
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
31
|
+
http.open_timeout = 5
|
|
32
|
+
http.read_timeout = 10
|
|
33
|
+
req = Net::HTTP::Get.new(uri)
|
|
34
|
+
req["User-Agent"] = "ask-web-search/1.0"
|
|
35
|
+
res = http.request(req)
|
|
36
|
+
raise "SearXNG returned #{res.code}: #{res.body}" unless res.code.start_with?("2")
|
|
37
|
+
|
|
38
|
+
data = JSON.parse(res.body)
|
|
39
|
+
parse_results(data)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def parse_results(data)
|
|
43
|
+
results = []
|
|
44
|
+
data.fetch("results", []).each do |r|
|
|
45
|
+
results << { url: r["url"], title: r["title"], content: r["content"] }
|
|
46
|
+
end
|
|
47
|
+
data.fetch("infoboxes", []).each do |ib|
|
|
48
|
+
results << { url: ib["id"], title: ib["infobox"], content: ib["content"] }
|
|
49
|
+
end
|
|
50
|
+
results.uniq { |r| r[:url] }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def format_results(results)
|
|
54
|
+
return "No results found." if results.empty?
|
|
55
|
+
|
|
56
|
+
results.each_with_index.map do |r, i|
|
|
57
|
+
line = "#{i + 1}. #{r[:title]}"
|
|
58
|
+
line += "\n #{r[:url]}"
|
|
59
|
+
line += "\n #{r[:content]}" if r[:content] && !r[:content].empty?
|
|
60
|
+
line
|
|
61
|
+
end.join("\n\n")
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
Ask::Tools.register(Ask::Tools::WebSearch) if defined?(Ask::Tools)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative "ask/web_search"
|
metadata
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ask-web-search
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Kaka Ruto
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: ask-tools
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: minitest
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '5.25'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '5.25'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rake
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '13.0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '13.0'
|
|
54
|
+
description: Provides Ask::Tools::WebSearch, a tool that searches the web via SearXNG
|
|
55
|
+
(local instance). Works with any ask-rb chat or agent. Configure endpoint via SEARXNG_URL
|
|
56
|
+
env var.
|
|
57
|
+
email:
|
|
58
|
+
- kaka@myrrlabs.com
|
|
59
|
+
executables: []
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- LICENSE
|
|
64
|
+
- README.md
|
|
65
|
+
- lib/ask-web-search.rb
|
|
66
|
+
- lib/ask/web_search.rb
|
|
67
|
+
- lib/ask/web_search/tool.rb
|
|
68
|
+
- lib/ask/web_search/version.rb
|
|
69
|
+
homepage: https://github.com/ask-rb/ask-web-search
|
|
70
|
+
licenses:
|
|
71
|
+
- MIT
|
|
72
|
+
metadata:
|
|
73
|
+
homepage_uri: https://github.com/ask-rb/ask-web-search
|
|
74
|
+
source_code_uri: https://github.com/ask-rb/ask-web-search
|
|
75
|
+
changelog_uri: https://github.com/ask-rb/ask-web-search/blob/master/CHANGELOG.md
|
|
76
|
+
rdoc_options: []
|
|
77
|
+
require_paths:
|
|
78
|
+
- lib
|
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '3.2'
|
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
requirements: []
|
|
90
|
+
rubygems_version: 4.0.3
|
|
91
|
+
specification_version: 4
|
|
92
|
+
summary: Web search tool for the ask-rb ecosystem
|
|
93
|
+
test_files: []
|