uptriever 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f44598b07e4b7c130e49c2308587dcc675eda01710f9ad24ce2fb4284fcfea63
4
- data.tar.gz: 98ba686f341d7cdb66c06db19b2c0fba4c871a9c8b92c760177a6fd8f51d673e
3
+ metadata.gz: d560762067e20107bf3f7e01850924035f533da723f49a0d83d076cbb05a6dfe
4
+ data.tar.gz: 535736316a8248d66cf6cc14723b98129de2c83a29298deac10b6de3094d2b93
5
5
  SHA512:
6
- metadata.gz: 7627037babef9668fd456b79bd09e34686e543871e51eff72e8126ebf08113f3cc79517fa2a62846f192651e34d2e36bebb30a8d8d574aeeb9eef67685fa1f3a
7
- data.tar.gz: a74448f80ab208acbf768c31464f730ea9402e73a68630fc4f71f372b93f26b573890d329640213dedc2afe977b9b9e5acd78fc59929e9285614ee16201677dc
6
+ metadata.gz: 4c8bc654e0c71835078513c631959bbaecdb5f792dcb51ec59b5e162677416790bfb4208f92baa28491abcd2485d2e2bd3fe938a83a7666bcb024dc2c22599c4
7
+ data.tar.gz: cc1830d5f0365bd834e3fc5374e21e3c20c2a31643658679abfb37186c0131c4891bd11e4fed9c05d4c59cf9f3daffd0825b2ee8b1ac257e4fd9c651191a5b96
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.1.2 (2025-01-03)
6
+
7
+ - Fix the bug with links including PWD. ([@palkan][])
8
+
5
9
  ## 0.1.1 (2024-07-25)
6
10
 
7
11
  - Add ERB support to allow include dynamic fragments to configs. ([@palkan][])
@@ -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::Post.new(
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 != 200
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uptriever # :nodoc:
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
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.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: 2024-07-25 00:00:00.000000000 Z
11
+ date: 2025-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet