ruby_llm-datacircle 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c4bfba388f78279248bbc165d86adca4e355af696236758d383fe6f1cd5535f9
4
+ data.tar.gz: e9228d52d62157f904af52980df41dd4f88bcc8a9a2f5b8a239c0d4dc320f2a0
5
+ SHA512:
6
+ metadata.gz: 16a4fb27eac737385c868828fc300517af5113ba18825d89986efde76cc3432865cdf8155bce1663291b905eb7dfeff282fc996d893a1153c866e2eb6c072855
7
+ data.tar.gz: 82913369c82cda9cede723680a35af7480efddb41080703c8dbdd6c615858f21f6ebc7d98721510e234776fcee9696ca8a82173a1e887a2c82062e7cbf6f718f
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Datacircle
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,65 @@
1
+ # Datacircle tools for RubyLLM
2
+
3
+ Find the best GTM APIs. We benchmark all the GTM APIs and we put the results on our website: https://datacircle.dev
4
+
5
+ This gem gives your [RubyLLM](https://github.com/crmne/ruby_llm) chats four tools on Datacircle's open API, https://api.datacircle.dev/v1. You need no key and no account.
6
+
7
+ | Tool | What the tool gives | Call |
8
+ | --- | --- | --- |
9
+ | `datacircle_list_apis` | Every GTM API on Datacircle, with the API's slug, number of plans, number of providers and best plan | `GET /apis` |
10
+ | `datacircle_best_plans` | One API's plans, sorted by score out of 100, best first. Each plan comes with a rank and a price per 1,000 calls | `GET /apis/{slug}/best` |
11
+ | `datacircle_search_plans` | Plans that match a provider or plan name, on all APIs or on one API. Sort by score, provider or price | `GET /plans` |
12
+ | `datacircle_provider` | The APIs a provider sells, and the provider's rank on each API | `GET /providers/{slug}` |
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ gem install ruby_llm-datacircle
18
+ ```
19
+
20
+ Or add it to your Gemfile:
21
+
22
+ ```ruby
23
+ gem 'ruby_llm-datacircle'
24
+ ```
25
+
26
+ It needs RubyLLM 2.2 or later and Ruby 3.2 or later.
27
+
28
+ ## Use the tools
29
+
30
+ ```ruby
31
+ require 'ruby_llm/datacircle'
32
+
33
+ chat = RubyLLM.chat.with_tools(*RubyLLM::Datacircle.tools)
34
+ chat.ask 'Which email finder API is best for under $5 per 1,000?'
35
+ ```
36
+
37
+ Each tool is a class: `RubyLLM::Datacircle::ListApis`, `BestPlans`, `SearchPlans` and `Provider`. Give an agent only the ones it needs:
38
+
39
+ ```ruby
40
+ class PlanFinder < RubyLLM::Agent
41
+ tools RubyLLM::Datacircle::BestPlans, RubyLLM::Datacircle::SearchPlans
42
+ end
43
+ ```
44
+
45
+ You can also call a tool yourself:
46
+
47
+ ```ruby
48
+ RubyLLM::Datacircle::BestPlans.new.call(slug: 'email-finder', limit: 3)
49
+ # => {"api" => "Employee email", "slug" => "email-finder", ..., "plans" => [{"api" => "Employee email", "rank" => 1, "provider" => "Emelia", ...}, ...]}
50
+ ```
51
+
52
+ Each plan comes with its rank, provider, plan, score, price per 1,000 (`perThousand`, in dollars) and its page on datacircle.dev. That page lists every field. When the API gives no data, like for a slug it doesn't know, a chat gets the API's error as the tool's result. A call of your own raises `RubyLLM::Datacircle::Error`.
53
+
54
+ ## Network
55
+
56
+ Each tool call makes one HTTPS GET request to https://api.datacircle.dev/v1 and nothing else. The request holds only the tool's own arguments: no key, no config, nothing from your chats. The API takes up to 60 calls a minute from one IP address. The tool waits once, for a minute at most, when the API asks the tool to wait. The gem has no dependency but RubyLLM and stores nothing.
57
+
58
+ ## Links
59
+
60
+ - Datacircle: https://datacircle.dev
61
+ - The API: https://datacircle.dev/api
62
+ - The API's spec: https://api.datacircle.dev/v1/openapi.json
63
+ - What each key means: https://datacircle.dev/fields
64
+
65
+ MIT license.
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ module RubyLLM
8
+ module Datacircle
9
+ # What Datacircle's API answered when it gave no data (its HTTP status in #status), or why it could not be reached.
10
+ class Error < StandardError
11
+ attr_reader :status
12
+
13
+ def initialize(message = nil, status: nil)
14
+ super(message)
15
+ @status = status
16
+ end
17
+ end
18
+
19
+ # One HTTPS GET to Datacircle's open API, with no key: its answer as a Hash or an Array.
20
+ class Client
21
+ BASE = 'https://api.datacircle.dev/v1'
22
+
23
+ def get(path, params = {})
24
+ uri = URI("#{BASE}#{path}")
25
+ query = params.reject { |_, value| value.nil? || value == '' }
26
+ uri.query = URI.encode_www_form(query) unless query.empty?
27
+ 2.times do |attempt|
28
+ response = request(uri)
29
+ return JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)
30
+
31
+ if response.code == '429' && attempt.zero?
32
+ sleep(wait(response))
33
+ next
34
+ end
35
+ raise Error.new("Datacircle's API answered #{response.code}: #{words(response.body)}", status: response.code.to_i)
36
+ end
37
+ raise Error, "Datacircle's API answered 429 twice: wait a minute and call again"
38
+ end
39
+
40
+ private
41
+
42
+ def request(uri)
43
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 15, read_timeout: 30) do |http|
44
+ http.get(uri.request_uri, 'Accept' => 'application/json', 'User-Agent' => "ruby_llm-datacircle/#{VERSION}")
45
+ end
46
+ rescue SocketError, SystemCallError, Timeout::Error, OpenSSL::SSL::SSLError, Net::HTTPBadResponse => e
47
+ raise Error, "Datacircle's API could not be reached: #{e.message}"
48
+ end
49
+
50
+ # The API asks to wait in Retry-After: its seconds, a minute at most.
51
+ def wait(response)
52
+ Integer(response['Retry-After'] || 30).clamp(1, 60)
53
+ rescue ArgumentError
54
+ 30
55
+ end
56
+
57
+ # The API's error, with the slugs it knows when it gives them.
58
+ def words(body)
59
+ parsed = JSON.parse(body)
60
+ return body[0, 3000] unless parsed.is_a?(Hash) && parsed['error']
61
+ return parsed['error'] unless parsed['slugs']
62
+
63
+ "#{parsed['error']}; the slugs: #{Array(parsed['slugs']).join(', ')}"[0, 3000]
64
+ rescue JSON::ParserError
65
+ body.to_s[0, 3000]
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLLM
4
+ module Datacircle
5
+ # What the four tools share: the client, the keys of a plan the model gets, and the API's errors given back as a result.
6
+ class Base < RubyLLM::Tool
7
+ # A plan holds about 90 keys (its terms of use, its aggregators...): the model gets the ones that choose a plan,
8
+ # the rest is on its page.
9
+ PLAN_KEYS = %w[api rank provider plan score perThousand notFoundPerThousand billing pay currency units unit
10
+ strengths latencyMs page pricingPage docs].freeze
11
+
12
+ rescue_from(Error) { |error| { error: error.message } }
13
+
14
+ private
15
+
16
+ def client
17
+ @client ||= Client.new
18
+ end
19
+
20
+ def brief(item, keys = PLAN_KEYS)
21
+ keys.each_with_object({}) { |key, kept| kept[key] = item[key] unless item[key].nil? }
22
+ end
23
+
24
+ # A number the model sent, within the API's range, or nil when it sent none.
25
+ def number(value, low, high)
26
+ return nil if value.nil? || value.to_s.strip.empty?
27
+
28
+ Integer(value.to_s.strip, 10).clamp(low, high)
29
+ rescue ArgumentError
30
+ nil
31
+ end
32
+
33
+ # The API's rule for a slug: the name in lowercase letters and digits, the rest a hyphen.
34
+ def slugify(value)
35
+ value.to_s.strip.downcase.unicode_normalize(:nfkd).gsub(/\p{Mn}/, '').gsub(/[^a-z0-9]+/, '-').gsub(/\A-|-\z/, '')
36
+ end
37
+ end
38
+
39
+ # GET /apis
40
+ class ListApis < Base
41
+ def self.tool_name = 'datacircle_list_apis'
42
+
43
+ description "Lists the GTM APIs on Datacircle's sheet (https://datacircle.dev), with each API's slug, " \
44
+ "how many plans and providers it has and its best plan. Call it first to find an API's slug."
45
+ parameters(
46
+ type: 'object',
47
+ properties: {
48
+ query: { type: 'string',
49
+ description: "Words of the API's name or slug, like 'email' or 'linkedin profile': the APIs " \
50
+ "that hold the most of them come first. The sheet's order when left out." },
51
+ limit: { type: 'integer', minimum: 1, maximum: 200,
52
+ description: 'How many APIs to give, 1 to 200. 20 when left out: the sheet has about 150.' }
53
+ },
54
+ required: []
55
+ )
56
+
57
+ def execute(query: nil, limit: nil)
58
+ words = query.to_s.downcase.tr('-', ' ').split
59
+ held = client.get('/apis').each_with_index.filter_map do |api, index|
60
+ name = "#{api['api']} #{api['slug'].to_s.tr('-', ' ')}".downcase
61
+ matched = words.count { |word| name.include?(word) }
62
+ [-matched, index, api] if matched.positive? || words.empty?
63
+ end
64
+ found = held.sort_by { |matched, index, _| [matched, index] }
65
+ .map { |_, _, api| brief(api, %w[api slug plans providers best bestPage sheetPage]) }
66
+ { total: found.size, apis: found.first(number(limit, 1, 200) || 20) }
67
+ end
68
+ end
69
+
70
+ # GET /apis/{slug}/best
71
+ class BestPlans < Base
72
+ def self.tool_name = 'datacircle_best_plans'
73
+
74
+ description "Gives an API's plans best first by their score out of 100 on Datacircle's benchmark " \
75
+ '(https://datacircle.dev), each with its rank, provider, plan, $ per 1,000 calls and its page. ' \
76
+ "perThousand is a plan's price of 1,000 items in dollars, pay the plan's whole price in its currency."
77
+ parameters(
78
+ type: 'object',
79
+ properties: {
80
+ slug: { type: 'string',
81
+ description: "The API's slug, like 'email-finder' or 'linkedin-profile', as datacircle_list_apis gives it." },
82
+ limit: { type: 'integer', minimum: 1, maximum: 50, description: 'How many plans to give, 1 to 50. 10 when left out.' }
83
+ },
84
+ required: ['slug']
85
+ )
86
+
87
+ def execute(slug:, limit: nil)
88
+ api = slugify(slug)
89
+ raise Error, "Give an API's slug, like 'email-finder': datacircle_list_apis gives every slug" if api.empty?
90
+
91
+ answer = client.get("/apis/#{api}/best", limit: number(limit, 1, 50))
92
+ answer.merge('plans' => Array(answer['plans']).map { |plan| brief(plan) })
93
+ end
94
+ end
95
+
96
+ # GET /plans
97
+ class SearchPlans < Base
98
+ def self.tool_name = 'datacircle_search_plans'
99
+
100
+ description "Searches every plan on Datacircle's sheet (https://datacircle.dev), or one API's, by provider or plan " \
101
+ 'name, sorted by score, provider or price. Gives how many were found and up to limit of them. ' \
102
+ "perThousand is a plan's price of 1,000 items in dollars, pay the plan's whole price in its currency."
103
+ parameters(
104
+ type: 'object',
105
+ properties: {
106
+ api: { type: 'string',
107
+ description: "Only this API's plans: its name or slug, like 'email-finder'. A provider's name goes in " \
108
+ 'query, never here. Every API when left out.' },
109
+ query: { type: 'string', description: "Words that must all appear in the provider's or plan's name, like 'bright data'." },
110
+ sort: { type: 'string', enum: %w[score provider price],
111
+ description: 'score (best first, the default), provider (A to Z) or price ($ per 1,000, lowest first).' },
112
+ limit: { type: 'integer', minimum: 1, maximum: 50, description: 'How many plans to give, 1 to 50. 10 when left out.' },
113
+ offset: { type: 'integer', minimum: 0, description: 'How many found plans to skip first. 0 when left out.' }
114
+ },
115
+ required: []
116
+ )
117
+
118
+ def execute(api: nil, query: nil, sort: nil, limit: nil, offset: nil)
119
+ answer = search(api, query, sort, limit, offset)
120
+ answer.merge('plans' => Array(answer['plans']).map { |plan| brief(plan) })
121
+ rescue Error => e
122
+ raise unless e.status == 400 && e.message.include?('api must be') && query.to_s.strip.empty?
123
+
124
+ # A provider's name sent as the API, as models do: the plans whose provider or plan name holds it.
125
+ answer = search(nil, api, sort, limit, offset)
126
+ { 'note' => "No API is named #{api.inspect}: these are the plans whose provider or plan name holds it." }
127
+ .merge(answer, 'plans' => Array(answer['plans']).map { |plan| brief(plan) })
128
+ end
129
+
130
+ private
131
+
132
+ def search(api, query, sort, limit, offset)
133
+ client.get('/plans', api: api, query: query, sort: (sort if %w[score provider price].include?(sort)),
134
+ limit: number(limit, 1, 50), offset: number(offset, 0, 1_000_000))
135
+ end
136
+ end
137
+
138
+ # GET /providers/{slug}
139
+ class Provider < Base
140
+ def self.tool_name = 'datacircle_provider'
141
+
142
+ description "Gives each API one provider sells and its rank on each on Datacircle's benchmark " \
143
+ '(https://datacircle.dev), with its best plan there.'
144
+ parameters(
145
+ type: 'object',
146
+ properties: {
147
+ slug: { type: 'string',
148
+ description: "The provider's slug, like 'bright-data', or its name, like 'Bright Data': the name is made a slug." }
149
+ },
150
+ required: ['slug']
151
+ )
152
+
153
+ def execute(slug:)
154
+ provider = slugify(slug)
155
+ raise Error, "Give a provider's slug or name, like 'bright-data' or 'Bright Data'" if provider.empty?
156
+
157
+ answer = client.get("/providers/#{provider}")
158
+ apis = Array(answer['apis']).map do |entry|
159
+ plans = Array(entry['plans'])
160
+ brief(entry, %w[api slug rank bestPage]).merge('plans' => plans.size, 'best' => best(plans))
161
+ end
162
+ answer.merge('apis' => apis)
163
+ end
164
+
165
+ private
166
+
167
+ # A provider's best plan on an API: its lowest rank, a plan with no score having none.
168
+ def best(plans)
169
+ top = plans.min_by { |plan| plan['rank'].is_a?(Numeric) ? plan['rank'] : Float::INFINITY }
170
+ top && brief(top, %w[plan score perThousand page])
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLLM
4
+ module Datacircle
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_llm'
4
+ require_relative 'datacircle/version'
5
+ require_relative 'datacircle/client'
6
+ require_relative 'datacircle/tools'
7
+
8
+ module RubyLLM
9
+ # Four RubyLLM tools on Datacircle's open API (https://api.datacircle.dev/v1), with no key.
10
+ module Datacircle
11
+ # The four tools, for chat.with_tools(*RubyLLM::Datacircle.tools).
12
+ def self.tools
13
+ [ListApis, BestPlans, SearchPlans, Provider]
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_llm-datacircle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wayne Hamadi
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: ruby_llm
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '2.2'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '3'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '2.2'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '3'
32
+ description: 'Four RubyLLM tools on Datacircle''s open API, with no key: list the
33
+ GTM APIs, the best plans of one API, a search of every plan and one provider''s
34
+ ranks. We benchmark all the GTM APIs and we put the results on our website: https://datacircle.dev'
35
+ email:
36
+ - wayne@datacircle.dev
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - LICENSE.txt
42
+ - README.md
43
+ - lib/ruby_llm/datacircle.rb
44
+ - lib/ruby_llm/datacircle/client.rb
45
+ - lib/ruby_llm/datacircle/tools.rb
46
+ - lib/ruby_llm/datacircle/version.rb
47
+ homepage: https://datacircle.dev
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://datacircle.dev
52
+ source_code_uri: https://github.com/waynehamadi/ruby_llm-datacircle
53
+ documentation_uri: https://github.com/waynehamadi/ruby_llm-datacircle#readme
54
+ bug_tracker_uri: https://github.com/waynehamadi/ruby_llm-datacircle/issues
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '3.2'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.6.9
70
+ specification_version: 4
71
+ summary: Find the best GTM APIs, in RubyLLM.
72
+ test_files: []