uptriever 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef0c09b8b1aaaa5e6fbed152bb6f54f555afe79106a5cd96ac0e2181e16d1e34
4
- data.tar.gz: 352a763cc73f0875d60ecc2af9b06f4cb5d5dd644084e685f993e906cd9cda60
3
+ metadata.gz: d560762067e20107bf3f7e01850924035f533da723f49a0d83d076cbb05a6dfe
4
+ data.tar.gz: 535736316a8248d66cf6cc14723b98129de2c83a29298deac10b6de3094d2b93
5
5
  SHA512:
6
- metadata.gz: 21345da63b6abb10004dad561afbe502da916ef5a357f7bd63962c00ad9d94adce8a7f8bfb8c01f34c12321464db8677c340df364d89f1b8afd9c595f67eca3c
7
- data.tar.gz: e2588b54b5ea1bbaa86f7b09ebe69491bfcaf547dc1e31f9f1b2b22bd9c7d1ff9ad9b821be1a0c4054ea299b9d51bb95e6a5fee453ccffb47dea7d7fbe10c335
6
+ metadata.gz: 4c8bc654e0c71835078513c631959bbaecdb5f792dcb51ec59b5e162677416790bfb4208f92baa28491abcd2485d2e2bd3fe938a83a7666bcb024dc2c22599c4
7
+ data.tar.gz: cc1830d5f0365bd834e3fc5374e21e3c20c2a31643658679abfb37186c0131c4891bd11e4fed9c05d4c59cf9f3daffd0825b2ee8b1ac257e4fd9c651191a5b96
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
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
+
9
+ ## 0.1.1 (2024-07-25)
10
+
11
+ - Add ERB support to allow include dynamic fragments to configs. ([@palkan][])
12
+
5
13
  ## 0.1.0 (2024-07-24)
6
14
 
7
15
  - Initial release. ([@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
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "yaml"
4
+ require "erb"
4
5
 
5
6
  module Uptriever
6
7
  class Config
@@ -9,7 +10,7 @@ module Uptriever
9
10
  attr_reader :config_path, :root_dir
10
11
 
11
12
  def initialize(root_dir)
12
- @root_dir = root_dir
13
+ @root_dir = File.expand_path(root_dir)
13
14
  @config_path = File.join(root_dir, ".trieve.yml")
14
15
  raise ArgumentError, ".trieve.yml is missing in the #{root_dir}" unless File.file?(config_path)
15
16
  end
@@ -40,7 +41,9 @@ module Uptriever
40
41
 
41
42
  private
42
43
 
43
- def config = @config ||= YAML.load_file(config_path)
44
+ def config
45
+ @config ||= YAML.load(ERB.new(File.read(config_path)).result)
46
+ end
44
47
 
45
48
  def unwrap_pages(items)
46
49
  items.flat_map do |item|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uptriever # :nodoc:
4
- VERSION = "0.1.0"
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.0
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-24 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
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: erb
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: bundler
113
127
  requirement: !ruby/object:Gem::Requirement