uptriever 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/uptriever/client.rb +39 -7
- data/lib/uptriever/config.rb +1 -1
- data/lib/uptriever/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d560762067e20107bf3f7e01850924035f533da723f49a0d83d076cbb05a6dfe
|
4
|
+
data.tar.gz: 535736316a8248d66cf6cc14723b98129de2c83a29298deac10b6de3094d2b93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c8bc654e0c71835078513c631959bbaecdb5f792dcb51ec59b5e162677416790bfb4208f92baa28491abcd2485d2e2bd3fe938a83a7666bcb024dc2c22599c4
|
7
|
+
data.tar.gz: cc1830d5f0365bd834e3fc5374e21e3c20c2a31643658679abfb37186c0131c4891bd11e4fed9c05d4c59cf9f3daffd0825b2ee8b1ac257e4fd9c651191a5b96
|
data/CHANGELOG.md
CHANGED
data/lib/uptriever/client.rb
CHANGED
@@ -8,9 +8,10 @@ module Uptriever
|
|
8
8
|
BASE_URL = "https://api.trieve.ai/api"
|
9
9
|
|
10
10
|
attr_reader :headers
|
11
|
-
private attr_reader :dry_run
|
11
|
+
private attr_reader :dry_run, :dataset_id
|
12
12
|
|
13
|
-
def initialize(api_key, dataset, dry_run: false)
|
13
|
+
def initialize(api_key = ENV["TRIEVE_API_KEY"], dataset = ENV["TRIEVE_DATASET"], dry_run: false)
|
14
|
+
@dataset_id = dataset
|
14
15
|
@dry_run = dry_run
|
15
16
|
@headers = {
|
16
17
|
"Authorization" => api_key,
|
@@ -28,19 +29,50 @@ module Uptriever
|
|
28
29
|
perform_request("/chunk", chunk.to_json)
|
29
30
|
end
|
30
31
|
|
32
|
+
def scroll_chunks(per_page: 100)
|
33
|
+
data = {
|
34
|
+
filters: {must: nil},
|
35
|
+
page_size: per_page
|
36
|
+
}
|
37
|
+
|
38
|
+
offset_id = nil
|
39
|
+
|
40
|
+
loop do
|
41
|
+
data[:offset_chunk_id] = offset_id if offset_id
|
42
|
+
data = perform_request("/chunks/scroll", data.to_json)
|
43
|
+
|
44
|
+
chunks = data.fetch("chunks")
|
45
|
+
chunks = chunks.select { _1["id"] != offset_id } if offset_id
|
46
|
+
|
47
|
+
break if chunks.empty?
|
48
|
+
|
49
|
+
chunks.each { yield _1 }
|
50
|
+
|
51
|
+
offset_id = chunks.last["id"]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete_chunk(id)
|
56
|
+
perform_request("/chunk/#{id}", method: :delete, expected_code: 204)
|
57
|
+
end
|
58
|
+
|
59
|
+
def usage
|
60
|
+
perform_request("/dataset/usage/#{dataset_id}", method: :get)
|
61
|
+
end
|
62
|
+
|
31
63
|
private
|
32
64
|
|
33
|
-
def perform_request(path, data)
|
65
|
+
def perform_request(path, data = nil, method: :post, expected_code: 200)
|
34
66
|
uri = URI.parse(BASE_URL + path)
|
35
67
|
|
36
68
|
http = Net::HTTP.new(uri.host, uri.port)
|
37
69
|
http.use_ssl = true if uri.scheme == "https"
|
38
70
|
|
39
|
-
request = Net::HTTP
|
71
|
+
request = Net::HTTP.const_get(method.to_s.capitalize).new(
|
40
72
|
uri.request_uri,
|
41
73
|
headers.merge("Content-Type" => "application/json")
|
42
74
|
)
|
43
|
-
request.body = data
|
75
|
+
request.body = data if data
|
44
76
|
|
45
77
|
if dry_run
|
46
78
|
puts "[DRY RUN] Perform POST #{path}: #{data}"
|
@@ -49,11 +81,11 @@ module Uptriever
|
|
49
81
|
|
50
82
|
response = http.request(request)
|
51
83
|
|
52
|
-
if response.code.to_i !=
|
84
|
+
if response.code.to_i != expected_code
|
53
85
|
raise "Invalid response code: #{response.code} (#{response.body[100...]})"
|
54
86
|
end
|
55
87
|
|
56
|
-
JSON.parse(response.body)
|
88
|
+
JSON.parse(response.body) if response.body
|
57
89
|
end
|
58
90
|
end
|
59
91
|
end
|
data/lib/uptriever/config.rb
CHANGED
@@ -10,7 +10,7 @@ module Uptriever
|
|
10
10
|
attr_reader :config_path, :root_dir
|
11
11
|
|
12
12
|
def initialize(root_dir)
|
13
|
-
@root_dir = root_dir
|
13
|
+
@root_dir = File.expand_path(root_dir)
|
14
14
|
@config_path = File.join(root_dir, ".trieve.yml")
|
15
15
|
raise ArgumentError, ".trieve.yml is missing in the #{root_dir}" unless File.file?(config_path)
|
16
16
|
end
|
data/lib/uptriever/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uptriever
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|