rager 0.5.0 → 0.7.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 +4 -4
- data/README.md +49 -7
- data/lib/rager/chat/message.rb +10 -0
- data/lib/rager/chat/message_content.rb +7 -0
- data/lib/rager/chat/message_delta.rb +7 -0
- data/lib/rager/chat/options.rb +12 -9
- data/lib/rager/chat/providers/openai.rb +64 -48
- data/lib/rager/chat/schema.rb +3 -4
- data/lib/rager/config.rb +16 -20
- data/lib/rager/context.rb +326 -97
- data/lib/rager/context_options.rb +23 -0
- data/lib/rager/embed/options.rb +4 -3
- data/lib/rager/embed/providers/openai.rb +14 -6
- data/lib/rager/errors/credentials_error.rb +24 -0
- data/lib/rager/errors/dependency_error.rb +23 -0
- data/lib/rager/errors/http_error.rb +12 -5
- data/lib/rager/errors/options_error.rb +10 -5
- data/lib/rager/errors/parse_error.rb +9 -5
- data/lib/rager/errors/template_error.rb +10 -4
- data/lib/rager/errors/timeout_error.rb +25 -0
- data/lib/rager/http/adapters/async_http.rb +66 -14
- data/lib/rager/http/adapters/mock.rb +41 -45
- data/lib/rager/http/adapters/net_http.rb +144 -0
- data/lib/rager/http/request.rb +2 -0
- data/lib/rager/{image_gen → image}/options.rb +5 -4
- data/lib/rager/{image_gen → image}/output_format.rb +1 -1
- data/lib/rager/{image_gen → image}/providers/abstract.rb +4 -4
- data/lib/rager/{image_gen → image}/providers/replicate.rb +19 -14
- data/lib/rager/{logger.rb → log_strategy.rb} +2 -1
- data/lib/rager/{mesh_gen → mesh}/options.rb +4 -3
- data/lib/rager/{mesh_gen → mesh}/providers/abstract.rb +4 -4
- data/lib/rager/{mesh_gen → mesh}/providers/replicate.rb +20 -14
- data/lib/rager/operation.rb +2 -2
- data/lib/rager/options.rb +1 -1
- data/lib/rager/outcome.rb +25 -0
- data/lib/rager/providers.rb +61 -0
- data/lib/rager/rerank/{query.rb → input.rb} +8 -1
- data/lib/rager/rerank/options.rb +3 -2
- data/lib/rager/rerank/providers/abstract.rb +2 -2
- data/lib/rager/rerank/providers/cohere.rb +24 -15
- data/lib/rager/rerank/result.rb +8 -1
- data/lib/rager/result.rb +98 -108
- data/lib/rager/search/options.rb +4 -1
- data/lib/rager/search/providers/jina.rb +68 -0
- data/lib/rager/search/result.rb +9 -2
- data/lib/rager/template/input.rb +9 -0
- data/lib/rager/template/options.rb +1 -1
- data/lib/rager/template/providers/erb.rb +3 -3
- data/lib/rager/template/providers/mustache.rb +30 -0
- data/lib/rager/types.rb +28 -17
- data/lib/rager/utils/http.rb +92 -27
- data/lib/rager/utils/replicate.rb +40 -21
- data/lib/rager/utils/runtime.rb +21 -0
- data/lib/rager/version.rb +1 -1
- metadata +22 -36
- data/lib/rager/chat.rb +0 -35
- data/lib/rager/embed.rb +0 -35
- data/lib/rager/errors/missing_credentials_error.rb +0 -19
- data/lib/rager/errors/unknown_provider_error.rb +0 -17
- data/lib/rager/image_gen.rb +0 -31
- data/lib/rager/mesh_gen.rb +0 -31
- data/lib/rager/rerank.rb +0 -35
- data/lib/rager/search/providers/brave.rb +0 -59
- data/lib/rager/search.rb +0 -35
- data/lib/rager/template.rb +0 -35
@@ -0,0 +1,68 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "json"
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
require "sorbet-runtime"
|
8
|
+
|
9
|
+
module Rager
|
10
|
+
module Search
|
11
|
+
module Providers
|
12
|
+
class Jina < Rager::Search::Providers::Abstract
|
13
|
+
extend T::Sig
|
14
|
+
|
15
|
+
sig do
|
16
|
+
override.params(
|
17
|
+
query: String,
|
18
|
+
options: Rager::Search::Options
|
19
|
+
).returns(Rager::Types::SearchOutput)
|
20
|
+
end
|
21
|
+
def search(query, options)
|
22
|
+
api_key = options.api_key || ENV["JINA_API_KEY"]
|
23
|
+
raise Rager::Errors::CredentialsError.new("Jina", env_var: ["JINA_API_KEY"]) if api_key.nil?
|
24
|
+
|
25
|
+
base_url = "https://s.jina.ai"
|
26
|
+
url = "#{base_url}/?#{URI.encode_www_form({"q" => query})}"
|
27
|
+
pagination = options.pagination
|
28
|
+
url = "#{url}&page=#{pagination}" if pagination && pagination > 1
|
29
|
+
|
30
|
+
headers = {
|
31
|
+
"Accept" => "application/json",
|
32
|
+
"X-Return-Format" => "markdown"
|
33
|
+
}.tap do |h|
|
34
|
+
h["Authorization"] = "Bearer #{api_key}" if api_key
|
35
|
+
end
|
36
|
+
|
37
|
+
request = Rager::Http::Request.new(
|
38
|
+
verb: Rager::Http::Verb::Get,
|
39
|
+
url: url,
|
40
|
+
headers: headers,
|
41
|
+
timeout: options.timeout || Rager.config.timeout
|
42
|
+
)
|
43
|
+
|
44
|
+
response = Rager.config.http_adapter.make_request(request)
|
45
|
+
response_body = T.cast(T.must(response.body), String)
|
46
|
+
|
47
|
+
raise Rager::Errors::HttpError.new(Rager.config.http_adapter, request.url, response.status, body: response_body) if response.status != 200
|
48
|
+
|
49
|
+
parsed_response = JSON.parse(response_body)
|
50
|
+
search_results = parsed_response["data"] || []
|
51
|
+
|
52
|
+
search_results = search_results.first(options.n) if options.n
|
53
|
+
|
54
|
+
search_results.map do |r|
|
55
|
+
content = r["content"] || r["description"]
|
56
|
+
content = content&.slice(0, options.max_length) if options.max_length
|
57
|
+
|
58
|
+
Rager::Search::Result.new(
|
59
|
+
url: r["url"],
|
60
|
+
title: r["title"],
|
61
|
+
content: content
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/rager/search/result.rb
CHANGED
@@ -6,9 +6,16 @@ require "sorbet-runtime"
|
|
6
6
|
module Rager
|
7
7
|
module Search
|
8
8
|
class Result < T::Struct
|
9
|
-
|
9
|
+
extend T::Sig
|
10
|
+
|
10
11
|
const :url, String
|
11
|
-
const :
|
12
|
+
const :title, String
|
13
|
+
const :content, String
|
14
|
+
|
15
|
+
sig { params(options: T.untyped).returns(String) }
|
16
|
+
def to_json(options = nil)
|
17
|
+
serialize.to_json(options)
|
18
|
+
end
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
data/lib/rager/template/input.rb
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require "sorbet-runtime"
|
5
|
+
|
4
6
|
module Rager
|
5
7
|
module Template
|
6
8
|
class Input < T::Struct
|
9
|
+
extend T::Sig
|
10
|
+
|
7
11
|
const :template, String
|
8
12
|
const :variables, T::Hash[Symbol, T.untyped]
|
13
|
+
|
14
|
+
sig { params(options: T.untyped).returns(String) }
|
15
|
+
def to_json(options = nil)
|
16
|
+
serialize.to_json(options)
|
17
|
+
end
|
9
18
|
end
|
10
19
|
end
|
11
20
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require "erb"
|
5
|
-
require "ostruct"
|
6
5
|
|
7
6
|
module Rager
|
8
7
|
module Template
|
@@ -17,8 +16,9 @@ module Rager
|
|
17
16
|
).returns(Rager::Types::TemplateOutput)
|
18
17
|
end
|
19
18
|
def template(input, options)
|
20
|
-
|
21
|
-
|
19
|
+
ERB.new(input.template).result_with_hash(input.variables)
|
20
|
+
rescue SyntaxError, NameError => e
|
21
|
+
raise Rager::Errors::TemplateError.new(input.template, input.variables, details: e.message)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rager
|
5
|
+
module Template
|
6
|
+
module Providers
|
7
|
+
class Mustache < Rager::Template::Providers::Abstract
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
sig do
|
11
|
+
override.params(
|
12
|
+
input: Rager::Template::Input,
|
13
|
+
options: Rager::Template::Options
|
14
|
+
).returns(Rager::Types::TemplateOutput)
|
15
|
+
end
|
16
|
+
def template(input, options)
|
17
|
+
begin
|
18
|
+
require "mustache"
|
19
|
+
rescue LoadError
|
20
|
+
raise Rager::Errors::DependencyError.new("mustache", details: "Please install the mustache gem to use mustache templates")
|
21
|
+
end
|
22
|
+
|
23
|
+
::Mustache.render(input.template, input.variables)
|
24
|
+
rescue ::Mustache::Parser::SyntaxError, ::Mustache::ContextMiss => e
|
25
|
+
raise Rager::Errors::TemplateError.new(input.template, input.variables, details: e.message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rager/types.rb
CHANGED
@@ -7,35 +7,35 @@ module Rager
|
|
7
7
|
|
8
8
|
ChatInput = T.type_alias { T::Array[Rager::Chat::Message] }
|
9
9
|
EmbedInput = T.type_alias { T::Array[String] }
|
10
|
-
|
11
|
-
|
12
|
-
RerankInput = T.type_alias { Rager::Rerank::
|
10
|
+
ImageInput = T.type_alias { String }
|
11
|
+
MeshInput = T.type_alias { String }
|
12
|
+
RerankInput = T.type_alias { Rager::Rerank::Input }
|
13
13
|
SearchInput = T.type_alias { String }
|
14
14
|
TemplateInput = T.type_alias { Rager::Template::Input }
|
15
15
|
Input = T.type_alias {
|
16
16
|
T.any(
|
17
17
|
ChatInput,
|
18
18
|
EmbedInput,
|
19
|
-
|
20
|
-
|
19
|
+
ImageInput,
|
20
|
+
MeshInput,
|
21
21
|
RerankInput,
|
22
22
|
SearchInput,
|
23
23
|
TemplateInput
|
24
24
|
)
|
25
25
|
}
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
ChatStream = T.type_alias { T::Enumerator[Rager::Chat::MessageDelta] }
|
30
|
-
Stream = T.type_alias { ChatStream }
|
27
|
+
ChatStreamOutput = T.type_alias { T::Enumerator[Rager::Chat::MessageDelta] }
|
28
|
+
Stream = T.type_alias { ChatStreamOutput }
|
31
29
|
|
32
30
|
ChatBuffer = T.type_alias { T::Array[Rager::Chat::MessageDelta] }
|
33
31
|
Buffer = T.type_alias { ChatBuffer }
|
34
32
|
|
35
|
-
|
33
|
+
ChatNonStreamOutput = T.type_alias { T.any(String, T::Array[String]) }
|
34
|
+
|
35
|
+
ChatOutput = T.type_alias { T.any(ChatNonStreamOutput, ChatStreamOutput) }
|
36
36
|
EmbedOutput = T.type_alias { T::Array[T::Array[Float]] }
|
37
|
-
|
38
|
-
|
37
|
+
ImageOutput = T.type_alias { String }
|
38
|
+
MeshOutput = T.type_alias { String }
|
39
39
|
RerankOutput = T.type_alias { T::Array[Rager::Rerank::Result] }
|
40
40
|
SearchOutput = T.type_alias { T::Array[Rager::Search::Result] }
|
41
41
|
TemplateOutput = T.type_alias { String }
|
@@ -43,25 +43,36 @@ module Rager
|
|
43
43
|
T.any(
|
44
44
|
ChatOutput,
|
45
45
|
EmbedOutput,
|
46
|
-
|
47
|
-
|
46
|
+
ImageOutput,
|
47
|
+
MeshOutput,
|
48
48
|
RerankOutput,
|
49
49
|
SearchOutput,
|
50
50
|
TemplateOutput
|
51
51
|
)
|
52
52
|
}
|
53
53
|
|
54
|
-
ChatNonStreamOutput = T.type_alias { ChatNonStream }
|
55
54
|
NonStreamOutput = T.type_alias {
|
56
55
|
T.any(
|
57
56
|
ChatNonStreamOutput,
|
58
57
|
EmbedOutput,
|
59
|
-
|
60
|
-
|
58
|
+
ImageOutput,
|
59
|
+
MeshOutput,
|
61
60
|
RerankOutput,
|
62
61
|
SearchOutput,
|
63
62
|
TemplateOutput
|
64
63
|
)
|
65
64
|
}
|
65
|
+
|
66
|
+
Options = T.type_alias {
|
67
|
+
T.any(
|
68
|
+
Rager::Chat::Options,
|
69
|
+
Rager::Embed::Options,
|
70
|
+
Rager::Image::Options,
|
71
|
+
Rager::Mesh::Options,
|
72
|
+
Rager::Rerank::Options,
|
73
|
+
Rager::Search::Options,
|
74
|
+
Rager::Template::Options
|
75
|
+
)
|
76
|
+
}
|
66
77
|
end
|
67
78
|
end
|
data/lib/rager/utils/http.rb
CHANGED
@@ -1,48 +1,113 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "
|
4
|
+
require "fileutils"
|
5
|
+
require "json"
|
6
|
+
require "net/http"
|
5
7
|
require "uri"
|
6
8
|
|
9
|
+
require "sorbet-runtime"
|
10
|
+
|
7
11
|
module Rager
|
8
12
|
module Utils
|
9
13
|
module Http
|
10
14
|
extend T::Sig
|
11
15
|
|
12
|
-
sig {
|
13
|
-
|
14
|
-
|
15
|
-
Rager::Http::
|
16
|
+
sig {
|
17
|
+
params(
|
18
|
+
url: String,
|
19
|
+
http_adapter: T.nilable(Rager::Http::Adapters::Abstract)
|
20
|
+
).returns(T.nilable(String))
|
21
|
+
}
|
22
|
+
def self.download(url, http_adapter: nil)
|
23
|
+
adapter = http_adapter || Rager.config.http_adapter
|
24
|
+
response = adapter.make_request(
|
25
|
+
Rager::Http::Request.new(url: url, headers: {})
|
16
26
|
)
|
17
27
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
28
|
+
return nil unless response.success?
|
29
|
+
body = response.body
|
30
|
+
return nil if body.nil?
|
31
|
+
|
32
|
+
if body.is_a?(String)
|
33
|
+
body
|
34
|
+
elsif body.respond_to?(:each)
|
35
|
+
body.to_a.join
|
36
|
+
else
|
37
|
+
body.to_s
|
22
38
|
end
|
23
|
-
rescue
|
24
|
-
nil
|
25
39
|
end
|
26
40
|
|
27
|
-
sig {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
41
|
+
sig {
|
42
|
+
params(
|
43
|
+
url: String,
|
44
|
+
path: String,
|
45
|
+
http_adapter: T.nilable(Rager::Http::Adapters::Abstract)
|
46
|
+
).returns(T.nilable(String))
|
47
|
+
}
|
48
|
+
def self.download_to_file(url, path, http_adapter: nil)
|
49
|
+
content = download(url, http_adapter: http_adapter)
|
50
|
+
return nil if content.nil?
|
51
|
+
|
52
|
+
FileUtils.mkdir_p(File.dirname(path))
|
53
|
+
File.write(path, content, mode: "wb")
|
54
|
+
path
|
55
|
+
end
|
56
|
+
|
57
|
+
sig do
|
58
|
+
params(
|
59
|
+
endpoint: String,
|
60
|
+
body: String,
|
61
|
+
error: T::Boolean
|
62
|
+
).void
|
63
|
+
end
|
64
|
+
def self.log_remote(endpoint, body, error = false)
|
65
|
+
logger = Rager.config.logger
|
66
|
+
|
67
|
+
case Rager.config.log_strategy
|
68
|
+
when Rager::LogStrategy::Stdout
|
69
|
+
error ? logger.error(body) : logger.info(body)
|
70
|
+
when Rager::LogStrategy::Remote
|
71
|
+
http_adapter = Rager.config.http_adapter
|
72
|
+
url = Rager.config.url
|
73
|
+
api_key = Rager.config.api_key
|
74
|
+
|
75
|
+
unless url && api_key
|
76
|
+
raise Rager::Errors::CredentialsError.new("Rager Cloud", details: "Missing url or api_key for remote logging")
|
36
77
|
end
|
37
|
-
end
|
38
78
|
|
39
|
-
|
40
|
-
|
79
|
+
headers = {
|
80
|
+
"Content-Type" => "application/json",
|
81
|
+
"Authorization" => "Bearer #{api_key}"
|
82
|
+
}
|
41
83
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
84
|
+
request = Rager::Http::Request.new(
|
85
|
+
url: "#{url}/#{endpoint}",
|
86
|
+
verb: Rager::Http::Verb::Post,
|
87
|
+
headers: headers,
|
88
|
+
body: body
|
89
|
+
)
|
90
|
+
|
91
|
+
begin
|
92
|
+
response = http_adapter.make_request(request)
|
93
|
+
|
94
|
+
unless response.success?
|
95
|
+
raise Rager::Errors::HttpError.new(
|
96
|
+
http_adapter,
|
97
|
+
request.url,
|
98
|
+
response.status,
|
99
|
+
body: T.cast(response.body, String),
|
100
|
+
details: "HTTP request failed during remote logging"
|
101
|
+
)
|
102
|
+
end
|
103
|
+
rescue Rager::Error => e
|
104
|
+
if Rager.config.log_raise
|
105
|
+
raise e
|
106
|
+
else
|
107
|
+
Rager.config.logger.error(e.message)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
46
111
|
end
|
47
112
|
end
|
48
113
|
end
|
@@ -1,38 +1,48 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "sorbet-runtime"
|
5
4
|
require "json"
|
6
5
|
|
6
|
+
require "sorbet-runtime"
|
7
|
+
|
7
8
|
module Rager
|
8
9
|
module Utils
|
9
10
|
module Replicate
|
10
11
|
extend T::Sig
|
11
12
|
|
12
|
-
sig {
|
13
|
+
sig {
|
14
|
+
params(
|
15
|
+
prediction_url: String,
|
16
|
+
key: T.nilable(String),
|
17
|
+
http_adapter: T.nilable(Rager::Http::Adapters::Abstract)
|
18
|
+
).returns(T.nilable(String))
|
19
|
+
}
|
13
20
|
def self.download_prediction(prediction_url, key = nil, http_adapter: nil)
|
14
21
|
download_url = get_download_url(prediction_url, key, http_adapter: http_adapter)
|
15
22
|
return nil if download_url.nil?
|
16
23
|
|
17
|
-
Rager::Utils::Http.
|
18
|
-
rescue
|
19
|
-
nil
|
24
|
+
Rager::Utils::Http.download(download_url)
|
20
25
|
end
|
21
26
|
|
22
|
-
sig {
|
27
|
+
sig {
|
28
|
+
params(
|
29
|
+
prediction_url: String,
|
30
|
+
key: T.nilable(String),
|
31
|
+
path: String,
|
32
|
+
http_adapter: T.nilable(Rager::Http::Adapters::Abstract)
|
33
|
+
).returns(T.nilable(String))
|
34
|
+
}
|
23
35
|
def self.download_prediction_to_file(prediction_url, key = nil, path:, http_adapter: nil)
|
24
36
|
download_url = get_download_url(prediction_url, key, http_adapter: http_adapter)
|
25
37
|
return nil if download_url.nil?
|
26
38
|
|
27
|
-
Rager::Utils::Http.
|
28
|
-
rescue
|
29
|
-
nil
|
39
|
+
Rager::Utils::Http.download_to_file(download_url, path)
|
30
40
|
end
|
31
41
|
|
32
42
|
sig { params(prediction_url: String, key: T.nilable(String), http_adapter: T.nilable(Rager::Http::Adapters::Abstract)).returns(T.nilable(String)) }
|
33
43
|
def self.get_download_url(prediction_url, key = nil, http_adapter: nil)
|
34
44
|
api_key = ENV["REPLICATE_API_KEY"]
|
35
|
-
raise Rager::Errors::
|
45
|
+
raise Rager::Errors::CredentialsError.new("Replicate", env_var: ["REPLICATE_API_KEY"]) if api_key.nil?
|
36
46
|
|
37
47
|
adapter = http_adapter || Rager.config.http_adapter
|
38
48
|
response = adapter.make_request(
|
@@ -42,14 +52,14 @@ module Rager
|
|
42
52
|
)
|
43
53
|
)
|
44
54
|
|
45
|
-
raise Rager::Errors::HttpError.new(adapter, response.status,
|
55
|
+
raise Rager::Errors::HttpError.new(adapter, prediction_url, response.status, body: response.body&.to_s) unless response.success?
|
46
56
|
|
47
57
|
data = JSON.parse(T.cast(T.must(response.body), String))
|
48
58
|
return nil if ["starting", "processing"].include?(data["status"])
|
49
59
|
|
50
60
|
if data["status"] == "failed"
|
51
61
|
error_msg = data["error"] || "Prediction failed"
|
52
|
-
raise Rager::Errors::HttpError.new(adapter, 422,
|
62
|
+
raise Rager::Errors::HttpError.new(adapter, prediction_url, 422, body: error_msg)
|
53
63
|
end
|
54
64
|
|
55
65
|
return nil unless data["status"] == "succeeded"
|
@@ -70,14 +80,19 @@ module Rager
|
|
70
80
|
return nil if download_url.nil? || download_url.empty?
|
71
81
|
download_url
|
72
82
|
rescue JSON::ParserError => e
|
73
|
-
raise Rager::Errors::ParseError.new("Failed to parse prediction response", e.message)
|
74
|
-
rescue Rager::Errors::HttpError, Rager::Errors::ParseError, Rager::Errors::MissingCredentialsError
|
75
|
-
raise
|
76
|
-
rescue
|
77
|
-
nil
|
83
|
+
raise Rager::Errors::ParseError.new("Failed to parse prediction response", details: e.message)
|
78
84
|
end
|
79
85
|
|
80
|
-
sig {
|
86
|
+
sig {
|
87
|
+
params(
|
88
|
+
prediction_url: String,
|
89
|
+
key: T.nilable(String),
|
90
|
+
path: T.nilable(String),
|
91
|
+
max_attempts: Integer,
|
92
|
+
sleep_interval: Integer,
|
93
|
+
http_adapter: T.nilable(Rager::Http::Adapters::Abstract)
|
94
|
+
).returns(T.nilable(String))
|
95
|
+
}
|
81
96
|
def self.poll_prediction(prediction_url, key: nil, path: nil, max_attempts: 30, sleep_interval: 10, http_adapter: nil)
|
82
97
|
max_attempts.times do
|
83
98
|
result = if path
|
@@ -86,11 +101,15 @@ module Rager
|
|
86
101
|
download_prediction(prediction_url, key, http_adapter: http_adapter)
|
87
102
|
end
|
88
103
|
return result unless result.nil?
|
89
|
-
sleep(sleep_interval)
|
104
|
+
Rager::Utils::Runtime.sleep(sleep_interval)
|
90
105
|
end
|
91
106
|
|
92
|
-
|
93
|
-
|
107
|
+
raise Rager::Errors::TimeoutError.new(
|
108
|
+
"Replicate prediction polling",
|
109
|
+
timeout_seconds: max_attempts * sleep_interval,
|
110
|
+
attempts: max_attempts,
|
111
|
+
details: "Prediction at #{prediction_url} did not complete within #{max_attempts} attempts"
|
112
|
+
)
|
94
113
|
end
|
95
114
|
end
|
96
115
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "sorbet-runtime"
|
5
|
+
|
6
|
+
module Rager
|
7
|
+
module Utils
|
8
|
+
module Runtime
|
9
|
+
extend T::Sig
|
10
|
+
|
11
|
+
sig { params(duration: Numeric).void }
|
12
|
+
def self.sleep(duration)
|
13
|
+
if defined?(Async::Task) && (task = Async::Task.current?)
|
14
|
+
task.sleep(duration)
|
15
|
+
else
|
16
|
+
Kernel.sleep(duration)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/rager/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mvkvc
|
@@ -23,20 +23,6 @@ dependencies:
|
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: '1.14'
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: ostruct
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
29
|
-
requirements:
|
30
|
-
- - "~>"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 0.6.2
|
33
|
-
type: :runtime
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 0.6.2
|
40
26
|
- !ruby/object:Gem::Dependency
|
41
27
|
name: sorbet-runtime
|
42
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,7 +60,6 @@ files:
|
|
74
60
|
- LICENSE.md
|
75
61
|
- README.md
|
76
62
|
- lib/rager.rb
|
77
|
-
- lib/rager/chat.rb
|
78
63
|
- lib/rager/chat/message.rb
|
79
64
|
- lib/rager/chat/message_content.rb
|
80
65
|
- lib/rager/chat/message_content_image_type.rb
|
@@ -87,55 +72,56 @@ files:
|
|
87
72
|
- lib/rager/chat/schema.rb
|
88
73
|
- lib/rager/config.rb
|
89
74
|
- lib/rager/context.rb
|
90
|
-
- lib/rager/
|
75
|
+
- lib/rager/context_options.rb
|
91
76
|
- lib/rager/embed/options.rb
|
92
77
|
- lib/rager/embed/providers/abstract.rb
|
93
78
|
- lib/rager/embed/providers/openai.rb
|
94
79
|
- lib/rager/error.rb
|
80
|
+
- lib/rager/errors/credentials_error.rb
|
81
|
+
- lib/rager/errors/dependency_error.rb
|
95
82
|
- lib/rager/errors/http_error.rb
|
96
|
-
- lib/rager/errors/missing_credentials_error.rb
|
97
83
|
- lib/rager/errors/options_error.rb
|
98
84
|
- lib/rager/errors/parse_error.rb
|
99
85
|
- lib/rager/errors/template_error.rb
|
100
|
-
- lib/rager/errors/
|
86
|
+
- lib/rager/errors/timeout_error.rb
|
101
87
|
- lib/rager/http/adapters/abstract.rb
|
102
88
|
- lib/rager/http/adapters/async_http.rb
|
103
89
|
- lib/rager/http/adapters/mock.rb
|
90
|
+
- lib/rager/http/adapters/net_http.rb
|
104
91
|
- lib/rager/http/request.rb
|
105
92
|
- lib/rager/http/response.rb
|
106
93
|
- lib/rager/http/verb.rb
|
107
|
-
- lib/rager/
|
108
|
-
- lib/rager/
|
109
|
-
- lib/rager/
|
110
|
-
- lib/rager/
|
111
|
-
- lib/rager/
|
112
|
-
- lib/rager/
|
113
|
-
- lib/rager/
|
114
|
-
- lib/rager/
|
115
|
-
- lib/rager/mesh_gen/providers/abstract.rb
|
116
|
-
- lib/rager/mesh_gen/providers/replicate.rb
|
94
|
+
- lib/rager/image/options.rb
|
95
|
+
- lib/rager/image/output_format.rb
|
96
|
+
- lib/rager/image/providers/abstract.rb
|
97
|
+
- lib/rager/image/providers/replicate.rb
|
98
|
+
- lib/rager/log_strategy.rb
|
99
|
+
- lib/rager/mesh/options.rb
|
100
|
+
- lib/rager/mesh/providers/abstract.rb
|
101
|
+
- lib/rager/mesh/providers/replicate.rb
|
117
102
|
- lib/rager/operation.rb
|
118
103
|
- lib/rager/options.rb
|
119
|
-
- lib/rager/
|
104
|
+
- lib/rager/outcome.rb
|
105
|
+
- lib/rager/providers.rb
|
106
|
+
- lib/rager/rerank/input.rb
|
120
107
|
- lib/rager/rerank/options.rb
|
121
108
|
- lib/rager/rerank/providers/abstract.rb
|
122
109
|
- lib/rager/rerank/providers/cohere.rb
|
123
|
-
- lib/rager/rerank/query.rb
|
124
110
|
- lib/rager/rerank/result.rb
|
125
111
|
- lib/rager/result.rb
|
126
|
-
- lib/rager/search.rb
|
127
112
|
- lib/rager/search/options.rb
|
128
113
|
- lib/rager/search/providers/abstract.rb
|
129
|
-
- lib/rager/search/providers/
|
114
|
+
- lib/rager/search/providers/jina.rb
|
130
115
|
- lib/rager/search/result.rb
|
131
|
-
- lib/rager/template.rb
|
132
116
|
- lib/rager/template/input.rb
|
133
117
|
- lib/rager/template/options.rb
|
134
118
|
- lib/rager/template/providers/abstract.rb
|
135
119
|
- lib/rager/template/providers/erb.rb
|
120
|
+
- lib/rager/template/providers/mustache.rb
|
136
121
|
- lib/rager/types.rb
|
137
122
|
- lib/rager/utils/http.rb
|
138
123
|
- lib/rager/utils/replicate.rb
|
124
|
+
- lib/rager/utils/runtime.rb
|
139
125
|
- lib/rager/version.rb
|
140
126
|
homepage: https://github.com/mvkvc/rager_rb
|
141
127
|
licenses:
|
@@ -155,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
141
|
- !ruby/object:Gem::Version
|
156
142
|
version: '0'
|
157
143
|
requirements: []
|
158
|
-
rubygems_version: 3.6.
|
144
|
+
rubygems_version: 3.6.9
|
159
145
|
specification_version: 4
|
160
|
-
summary: Build continuously improving
|
146
|
+
summary: Build continuously improving generative workflows.
|
161
147
|
test_files: []
|