langchainrb_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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/lib/langchainrb_datacircle/client.rb +68 -0
- data/lib/langchainrb_datacircle/tool.rb +200 -0
- data/lib/langchainrb_datacircle/version.rb +5 -0
- data/lib/langchainrb_datacircle.rb +6 -0
- metadata +72 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2f51b5257434ed1f0310396bd99c0588774ccb470e3bf8484058aa6a9abede67
|
|
4
|
+
data.tar.gz: 57136f9d3a9a6fa1a0d8ec54d1dfd51bcea50a3b4f1cacaedc194f7094c1dcf5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f4b26aa0cb32fe152cc1eb797fde70e112577e181c57f7f3a5c9641aa62a0629a578c9e60b8c5b29f2a6d0e12b7be03935f750da7de052d5f4d370e42de40bd0
|
|
7
|
+
data.tar.gz: 7b6b7194f874d970ee7d063cd8d7ecad80255245b91480d8837d63603456590d254ac03d06dafd3f1703762987bd5479bdd7d8e5bdce6c6c9c4ec802068ca3af
|
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,63 @@
|
|
|
1
|
+
# Datacircle tool for Langchain.rb
|
|
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 a [Langchain.rb](https://github.com/patterns-ai-core/langchainrb) assistant one tool, `Langchain::Tool::Datacircle`, that calls Datacircle's open API, https://api.datacircle.dev/v1. You need no key and no account.
|
|
6
|
+
|
|
7
|
+
| Function | What the function 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. Search all APIs or 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
|
+
bundle add langchainrb_datacircle
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The gem needs Langchain.rb 0.19.4 or a later 0.19 release, and Ruby 3.1 or later.
|
|
21
|
+
|
|
22
|
+
## Use the tool
|
|
23
|
+
|
|
24
|
+
Give the tool to an assistant:
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
require "langchainrb_datacircle"
|
|
28
|
+
|
|
29
|
+
llm = Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"])
|
|
30
|
+
assistant = Langchain::Assistant.new(
|
|
31
|
+
llm: llm,
|
|
32
|
+
instructions: "You help people choose a GTM API.",
|
|
33
|
+
tools: [Langchain::Tool::Datacircle.new]
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
assistant.add_message_and_run!(content: "Which email finder API is best for under $5 per 1,000?")
|
|
37
|
+
assistant.messages.last.content
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Langchain.rb's OpenAI LLM needs the `ruby-openai` gem in your Gemfile. Other LLMs of Langchain.rb's assistant work the same way, for example `Langchain::LLM::Ollama`. With `Langchain::LLM::Anthropic`, create the assistant with `parallel_tool_calls: false`. Langchain.rb 0.19 runs only the first tool call when Claude makes several at once.
|
|
41
|
+
|
|
42
|
+
You can call a function yourself:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
tool = Langchain::Tool::Datacircle.new
|
|
46
|
+
tool.best_plans(slug: "email-finder", limit: 3).content
|
|
47
|
+
# => "{\"api\":\"Employee email\",\"slug\":\"email-finder\",...,\"plans\":[{\"api\":\"Employee email\",\"rank\":1,\"provider\":\"Emelia\",...}]}"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Each function gives a `Langchain::ToolResponse` with JSON in its content. Each plan comes with a rank, provider, plan, score, price per 1,000 (`perThousand`, in dollars) and a page on datacircle.dev. That page lists every field. When the API has no data, for example for an unknown slug, the content is `{"error": ...}` with the API's words. The assistant reads the error and can call the function again.
|
|
51
|
+
|
|
52
|
+
## Network
|
|
53
|
+
|
|
54
|
+
Each function call makes one HTTPS GET request to https://api.datacircle.dev/v1. A plan search makes a second request when the model names a provider instead of an API. A request holds only the function's own arguments: no key, no config, nothing from your messages. 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 it to wait. The gem depends only on Langchain.rb and stores nothing.
|
|
55
|
+
|
|
56
|
+
## Links
|
|
57
|
+
|
|
58
|
+
- Datacircle: https://datacircle.dev
|
|
59
|
+
- The API: https://datacircle.dev/api
|
|
60
|
+
- The API's spec: https://api.datacircle.dev/v1/openapi.json
|
|
61
|
+
- What each key means: https://datacircle.dev/fields
|
|
62
|
+
|
|
63
|
+
MIT license.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'uri'
|
|
6
|
+
|
|
7
|
+
module LangchainrbDatacircle
|
|
8
|
+
# What Datacircle's API answered when it gave no data (its HTTP status in #status), or why it could not be reached.
|
|
9
|
+
class Error < StandardError
|
|
10
|
+
attr_reader :status
|
|
11
|
+
|
|
12
|
+
def initialize(message = nil, status: nil)
|
|
13
|
+
super(message)
|
|
14
|
+
@status = status
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# One HTTPS GET to Datacircle's open API, with no key: its answer as a Hash or an Array.
|
|
19
|
+
class Client
|
|
20
|
+
BASE = 'https://api.datacircle.dev/v1'
|
|
21
|
+
|
|
22
|
+
def initialize(base_url: BASE)
|
|
23
|
+
@base = base_url.to_s.chomp('/')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get(path, params = {})
|
|
27
|
+
uri = URI("#{@base}#{path}")
|
|
28
|
+
query = params.reject { |_, value| value.nil? || value.to_s.strip.empty? }
|
|
29
|
+
uri.query = URI.encode_www_form(query) unless query.empty?
|
|
30
|
+
2.times do |attempt|
|
|
31
|
+
response = request(uri)
|
|
32
|
+
return JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)
|
|
33
|
+
|
|
34
|
+
if response.code == '429' && attempt.zero?
|
|
35
|
+
sleep(wait(response))
|
|
36
|
+
next
|
|
37
|
+
end
|
|
38
|
+
raise Error.new(words(response), status: response.code.to_i)
|
|
39
|
+
end
|
|
40
|
+
raise Error.new("Datacircle's API answered 429 twice: wait a minute and call again", status: 429)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def request(uri)
|
|
46
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', open_timeout: 15, read_timeout: 30) do |http|
|
|
47
|
+
http.get(uri.request_uri, 'Accept' => 'application/json', 'User-Agent' => "langchainrb_datacircle/#{VERSION}")
|
|
48
|
+
end
|
|
49
|
+
rescue SocketError, SystemCallError, Timeout::Error, OpenSSL::SSL::SSLError, Net::HTTPBadResponse => e
|
|
50
|
+
raise Error, "Datacircle's API could not be reached: #{e.message}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# The API asks to wait in Retry-After: its seconds, a minute at most.
|
|
54
|
+
def wait(response)
|
|
55
|
+
Integer(response['Retry-After'] || 30).clamp(1, 60)
|
|
56
|
+
rescue ArgumentError
|
|
57
|
+
30
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# The API's own words: its error of a 4xx, else its status.
|
|
61
|
+
def words(response)
|
|
62
|
+
parsed = JSON.parse(response.body.to_s)
|
|
63
|
+
parsed.is_a?(Hash) && parsed['error'] ? parsed['error'].to_s : "Datacircle's API answered #{response.code}"
|
|
64
|
+
rescue JSON::ParserError
|
|
65
|
+
"Datacircle's API answered #{response.code}"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Langchain
|
|
4
|
+
module Tool
|
|
5
|
+
# Datacircle's open API as a tool of Langchain::Assistant, with no key: find the best GTM APIs. We benchmark all the
|
|
6
|
+
# GTM APIs and we put the results on our website, https://datacircle.dev
|
|
7
|
+
#
|
|
8
|
+
# assistant = Langchain::Assistant.new(llm: llm, tools: [Langchain::Tool::Datacircle.new])
|
|
9
|
+
#
|
|
10
|
+
# Its four functions are shown to the model as datacircle__list_apis, datacircle__best_plans, datacircle__search_plans
|
|
11
|
+
# and datacircle__provider, one GET of https://api.datacircle.dev/v1 each. Each answers JSON; the API's error, or why
|
|
12
|
+
# it could not be reached, is answered as {"error": ...} for the model to read and call again.
|
|
13
|
+
class Datacircle
|
|
14
|
+
extend Langchain::ToolDefinition
|
|
15
|
+
|
|
16
|
+
# A plan holds about 90 keys (its terms of use, its aggregators...): these choose a plan, the rest is on its page.
|
|
17
|
+
PLAN_KEYS = %w[api rank provider plan score perThousand notFoundPerThousand billing pay currency units unit
|
|
18
|
+
strengths latencyMs page pricingPage docs].freeze
|
|
19
|
+
|
|
20
|
+
# Where a provider's plans are, for a model that sent a provider's name to an API's function.
|
|
21
|
+
FOR_PROVIDER = "A provider's plans: datacircle__search_plans with its name as query, like bright data, " \
|
|
22
|
+
'or datacircle__provider.'
|
|
23
|
+
|
|
24
|
+
# The name the functions' names start with: datacircle__list_apis and so on.
|
|
25
|
+
def self.tool_name
|
|
26
|
+
'datacircle'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
define_function :list_apis,
|
|
30
|
+
description: "Lists the GTM APIs on Datacircle's sheet (https://datacircle.dev), with each API's slug, " \
|
|
31
|
+
'how many plans and providers it has and its best plan. Call it first to find an ' \
|
|
32
|
+
"API's slug." do
|
|
33
|
+
property :query, type: 'string',
|
|
34
|
+
description: "Words of the API's name or slug, like email or linkedin profile: the APIs that hold " \
|
|
35
|
+
"the most of them come first. The sheet's order when left out."
|
|
36
|
+
property :limit, type: 'integer', description: 'How many APIs to give, 1 to 200. 20 when left out: the sheet has about 150.'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
define_function :best_plans,
|
|
40
|
+
description: "Gives an API's plans best first by their score out of 100 on Datacircle's benchmark " \
|
|
41
|
+
'(https://datacircle.dev), each with its rank, provider, plan, $ per 1,000 calls and its ' \
|
|
42
|
+
"page. perThousand is a plan's price of 1,000 items in dollars, pay the plan's whole " \
|
|
43
|
+
'price in its currency.' do
|
|
44
|
+
property :slug, type: 'string', required: true,
|
|
45
|
+
description: "The API's slug, like email-finder or linkedin-profile, as datacircle__list_apis gives it."
|
|
46
|
+
property :limit, type: 'integer', description: 'How many plans to give, 1 to 50. 10 when left out.'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
define_function :search_plans,
|
|
50
|
+
description: "Searches every plan on Datacircle's sheet (https://datacircle.dev), or one API's, by " \
|
|
51
|
+
'provider or plan name, sorted by score, provider or price. Gives how many were found ' \
|
|
52
|
+
"and up to limit of them. perThousand is a plan's price of 1,000 items in dollars, pay " \
|
|
53
|
+
"the plan's whole price in its currency." do
|
|
54
|
+
property :api, type: 'string',
|
|
55
|
+
description: "Only this API's plans: its name or slug, like email-finder. A provider's name goes in " \
|
|
56
|
+
'query, never here. Every API when left out.'
|
|
57
|
+
property :query, type: 'string', description: "Words that must all appear in the provider's or plan's name, like bright data."
|
|
58
|
+
property :sort, type: 'string', enum: %w[score provider price],
|
|
59
|
+
description: 'score (best first, the default), provider (A to Z) or price ($ per 1,000, lowest first).'
|
|
60
|
+
property :limit, type: 'integer', description: 'How many plans to give, 1 to 50. 10 when left out.'
|
|
61
|
+
property :offset, type: 'integer', description: 'How many found plans to skip first. 0 when left out.'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
define_function :provider,
|
|
65
|
+
description: "Gives each API one provider sells and its rank on each on Datacircle's benchmark " \
|
|
66
|
+
'(https://datacircle.dev), with its best plan there, its best rank first. total is how ' \
|
|
67
|
+
'many APIs it sells, ranked on how many of them it has a rank.' do
|
|
68
|
+
property :slug, type: 'string', required: true,
|
|
69
|
+
description: "The provider's slug, like bright-data, or its name, like Bright Data: the name is made a slug."
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# base_url: where the functions call, https://api.datacircle.dev/v1 when left out.
|
|
73
|
+
def initialize(base_url: LangchainrbDatacircle::Client::BASE)
|
|
74
|
+
@client = LangchainrbDatacircle::Client.new(base_url: base_url)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# GET /apis, the APIs whose name or slug holds the most of the query's words first.
|
|
78
|
+
def list_apis(query: nil, limit: nil, **_others)
|
|
79
|
+
answer do
|
|
80
|
+
words = query.to_s.downcase.tr('-', ' ').split
|
|
81
|
+
held = @client.get('/apis').each_with_index.filter_map do |api, index|
|
|
82
|
+
name = "#{api['api']} #{api['slug'].to_s.tr('-', ' ')}".downcase
|
|
83
|
+
matched = words.count { |word| name.include?(word) }
|
|
84
|
+
[-matched, index, api] if matched.positive? || words.empty?
|
|
85
|
+
end.sort_by { |matched, index, _| [matched, index] }
|
|
86
|
+
found = { 'total' => held.size,
|
|
87
|
+
'apis' => held.first(number(limit, 1, 200) || 20).map { |_, _, api| brief(api, %w[api slug plans providers best bestPage sheetPage]) } }
|
|
88
|
+
if words.any? && (held.empty? || -held.first.first < words.size)
|
|
89
|
+
# A provider's name sent as an API's, like Bright Data, whose data matches many APIs: where its plans are.
|
|
90
|
+
found['note'] = "No API's name holds every word of #{query.to_s.strip.inspect}. #{FOR_PROVIDER}"
|
|
91
|
+
end
|
|
92
|
+
found
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# GET /apis/{slug}/best
|
|
97
|
+
def best_plans(slug: nil, limit: nil, **_others)
|
|
98
|
+
api = slugify(slug)
|
|
99
|
+
return error("Give an API's slug, like email-finder: datacircle__list_apis gives every slug. #{FOR_PROVIDER}") if api.empty?
|
|
100
|
+
|
|
101
|
+
answer do
|
|
102
|
+
found = @client.get("/apis/#{api}/best", limit: number(limit, 1, 50))
|
|
103
|
+
found.merge('plans' => Array(found['plans']).map { |plan| brief(plan) })
|
|
104
|
+
rescue LangchainrbDatacircle::Error => e
|
|
105
|
+
raise unless e.status == 404
|
|
106
|
+
|
|
107
|
+
# A provider's name sent as the API's slug: the API's words, and where a provider's plans are.
|
|
108
|
+
{ 'error' => "#{e.message}. datacircle__list_apis gives every API's slug. #{FOR_PROVIDER}" }
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# GET /plans
|
|
113
|
+
def search_plans(api: nil, query: nil, sort: nil, limit: nil, offset: nil, **_others)
|
|
114
|
+
answer do
|
|
115
|
+
notes = []
|
|
116
|
+
begin
|
|
117
|
+
found = search(api, query, sort, limit, offset)
|
|
118
|
+
rescue LangchainrbDatacircle::Error => e
|
|
119
|
+
raise unless e.status == 400 && e.message.include?('api must be') && query.to_s.strip.empty?
|
|
120
|
+
|
|
121
|
+
# A provider's name sent as the API: the plans whose provider or plan name holds it.
|
|
122
|
+
api, query = nil, api
|
|
123
|
+
found = search(api, query, sort, limit, offset)
|
|
124
|
+
notes << "No API is named #{query.to_s.strip.inspect}: these are the plans whose provider or plan name holds it."
|
|
125
|
+
end
|
|
126
|
+
if found['total'].to_i.zero? && query.to_s.include?('-')
|
|
127
|
+
# A slug sent as a name, like bright-data, which no name holds: its words, like bright data. A name with a
|
|
128
|
+
# hyphen, like A-Leads, is found as it is first.
|
|
129
|
+
words = query.to_s.tr('-', ' ').split.join(' ')
|
|
130
|
+
found = search(api, words, sort, limit, offset)
|
|
131
|
+
notes << "No provider's or plan's name holds #{query.to_s.strip.inspect}: these are the plans whose name holds #{words.inspect}."
|
|
132
|
+
end
|
|
133
|
+
found = found.merge('plans' => Array(found['plans']).map { |plan| brief(plan) })
|
|
134
|
+
notes.empty? ? found : { 'note' => notes.join(' ') }.merge(found)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# GET /providers/{slug}
|
|
139
|
+
def provider(slug: nil, **_others)
|
|
140
|
+
name = slugify(slug)
|
|
141
|
+
return error("Give a provider's slug or name, like bright-data or Bright Data") if name.empty?
|
|
142
|
+
|
|
143
|
+
answer do
|
|
144
|
+
found = @client.get("/providers/#{name}")
|
|
145
|
+
apis = Array(found['apis']).map do |entry|
|
|
146
|
+
plans = Array(entry['plans'])
|
|
147
|
+
brief(entry, %w[api slug rank bestPage]).merge('plans' => plans.size, 'best' => best(plans)).compact
|
|
148
|
+
end
|
|
149
|
+
# Its best rank first, the APIs where it has none last, in the API's order.
|
|
150
|
+
apis = apis.each_with_index.sort_by { |entry, index| [entry['rank'].is_a?(Numeric) ? entry['rank'] : Float::INFINITY, index] }.map(&:first)
|
|
151
|
+
found.merge('apis' => apis, 'total' => apis.size, 'ranked' => apis.count { |entry| entry['rank'].is_a?(Numeric) })
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
private
|
|
156
|
+
|
|
157
|
+
# A function's answer as Langchain::Assistant takes it: the call's JSON, or the API's error as {"error": ...}.
|
|
158
|
+
def answer
|
|
159
|
+
tool_response(content: JSON.generate(yield))
|
|
160
|
+
rescue LangchainrbDatacircle::Error => e
|
|
161
|
+
error(e.message)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def error(message)
|
|
165
|
+
tool_response(content: JSON.generate('error' => message))
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def search(api, query, sort, limit, offset)
|
|
169
|
+
@client.get('/plans', api: api.to_s.strip, query: query.to_s.strip,
|
|
170
|
+
sort: (sort.to_s if %w[score provider price].include?(sort.to_s)),
|
|
171
|
+
limit: number(limit, 1, 50), offset: number(offset, 0, 1_000_000))
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def brief(item, keys = PLAN_KEYS)
|
|
175
|
+
keys.each_with_object({}) { |key, kept| kept[key] = item[key] unless item[key].nil? }
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# A number the model sent, within the API's range, or nil when it sent none.
|
|
179
|
+
def number(value, low, high)
|
|
180
|
+
return nil if value.nil? || value.to_s.strip.empty?
|
|
181
|
+
return value.to_i.clamp(low, high) if value.is_a?(Numeric)
|
|
182
|
+
|
|
183
|
+
Integer(value.to_s.strip, 10).clamp(low, high)
|
|
184
|
+
rescue ArgumentError
|
|
185
|
+
nil
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# The API's rule for a slug: the name in lowercase letters and digits, the rest a hyphen.
|
|
189
|
+
def slugify(value)
|
|
190
|
+
value.to_s.strip.downcase.unicode_normalize(:nfkd).gsub(/\p{Mn}/, '').gsub(/[^a-z0-9]+/, '-').gsub(/\A-|-\z/, '')
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# A provider's best plan on an API: its lowest rank, else its first.
|
|
194
|
+
def best(plans)
|
|
195
|
+
top = plans.select { |plan| plan['rank'].is_a?(Numeric) }.min_by { |plan| plan['rank'] } || plans.first
|
|
196
|
+
top && brief(top, %w[plan score perThousand page])
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: langchainrb_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: langchainrb
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.19.4
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0.20'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: 0.19.4
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '0.20'
|
|
32
|
+
description: 'A Langchain.rb tool 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/langchainrb_datacircle.rb
|
|
44
|
+
- lib/langchainrb_datacircle/client.rb
|
|
45
|
+
- lib/langchainrb_datacircle/tool.rb
|
|
46
|
+
- lib/langchainrb_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/langchainrb_datacircle
|
|
53
|
+
documentation_uri: https://github.com/waynehamadi/langchainrb_datacircle#readme
|
|
54
|
+
bug_tracker_uri: https://github.com/waynehamadi/langchainrb_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.1'
|
|
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 Langchain.rb.
|
|
72
|
+
test_files: []
|