active_genie 0.25.2 → 0.26.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/VERSION +1 -1
- data/lib/active_genie/clients/providers/anthropic_client.rb +1 -3
- data/lib/active_genie/clients/providers/base_client.rb +10 -10
- data/lib/active_genie/clients/providers/deepseek_client.rb +7 -9
- data/lib/active_genie/clients/providers/google_client.rb +4 -6
- data/lib/active_genie/clients/providers/openai_client.rb +4 -6
- data/lib/active_genie/config/log_config.rb +8 -6
- data/lib/active_genie/data_extractor/from_informal.rb +2 -2
- data/lib/active_genie/logger.rb +3 -1
- data/lib/active_genie/ranking/elo_round.rb +4 -6
- data/lib/active_genie/ranking/free_for_all.rb +1 -1
- data/lib/active_genie/ranking/player.rb +11 -5
- data/lib/active_genie/ranking/players_collection.rb +1 -7
- data/lib/active_genie/ranking/ranking_scoring.rb +1 -2
- 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: 848de45258263935accfd02ce16d14eb96c6b5a73f42979fe0a74e5b9b746fb4
|
4
|
+
data.tar.gz: cb1f9eb843559a7040dc20b1442e120325d734b7610a75b57bfde91cba63dc4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12f38e95348fae6beab3cc7a74cfdefc132ef9e8308303f2df04a40703d6f86a9fe6f859c958dc8a1d9fca52d41ceb1f380324c5b34d5d13e0bde4a702362830
|
7
|
+
data.tar.gz: c512e6ae0fb0b47403f9c2fc3be5c55a458320877fe2aae93780af1fab4e95b2fa1553ff60a62ec30653933f77a5c8892e96227ee637e8ab03a30cf0c9ad177d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.26.0
|
@@ -81,16 +81,13 @@ module ActiveGenie
|
|
81
81
|
|
82
82
|
response = http_request(request, uri)
|
83
83
|
|
84
|
-
|
85
|
-
when Net::HTTPSuccess
|
86
|
-
parsed_response = parse_response(response)
|
84
|
+
raise ClientError, "Unexpected response: #{response.code} - #{response.body}" unless response.is_a?(Net::HTTPSuccess)
|
87
85
|
|
88
|
-
|
86
|
+
parsed_response = parse_response(response)
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
88
|
+
log_request_details(uri:, request:, response:, start_time:, parsed_response:)
|
89
|
+
|
90
|
+
parsed_response
|
94
91
|
end
|
95
92
|
|
96
93
|
# Create and configure an HTTP client
|
@@ -103,7 +100,10 @@ module ActiveGenie
|
|
103
100
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
104
101
|
http.read_timeout = @config.llm.read_timeout || DEFAULT_TIMEOUT
|
105
102
|
http.open_timeout = @config.llm.open_timeout || DEFAULT_OPEN_TIMEOUT
|
106
|
-
|
103
|
+
|
104
|
+
retry_with_backoff do
|
105
|
+
http.request(request)
|
106
|
+
end
|
107
107
|
end
|
108
108
|
|
109
109
|
# Apply headers to the request
|
@@ -170,7 +170,7 @@ module ActiveGenie
|
|
170
170
|
|
171
171
|
begin
|
172
172
|
yield
|
173
|
-
rescue Net::
|
173
|
+
rescue Net::OpenTimeout, Net::ReadTimeout, ClientError => e
|
174
174
|
raise if retries > max_retries
|
175
175
|
|
176
176
|
sleep_time = retry_delay * (2**retries)
|
@@ -25,18 +25,16 @@ module ActiveGenie
|
|
25
25
|
model:
|
26
26
|
}
|
27
27
|
|
28
|
-
|
29
|
-
response = request(payload)
|
28
|
+
response = request(payload)
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
if response.nil? || response.keys.empty?
|
31
|
+
raise InvalidResponseError,
|
32
|
+
"Invalid response: #{response}"
|
33
|
+
end
|
35
34
|
|
36
|
-
|
35
|
+
ActiveGenie::Logger.call({ code: :function_calling, fine_tune: true, payload:, response: })
|
37
36
|
|
38
|
-
|
39
|
-
end
|
37
|
+
response
|
40
38
|
end
|
41
39
|
|
42
40
|
private
|
@@ -29,14 +29,12 @@ module ActiveGenie
|
|
29
29
|
}
|
30
30
|
params = { key: provider_config.api_key }
|
31
31
|
|
32
|
-
|
33
|
-
response = request(payload, params)
|
32
|
+
response = request(payload, params)
|
34
33
|
|
35
|
-
|
36
|
-
|
34
|
+
json_string = response&.dig('candidates', 0, 'content', 'parts', 0, 'text')
|
35
|
+
return nil if json_string.nil? || json_string.empty?
|
37
36
|
|
38
|
-
|
39
|
-
end
|
37
|
+
normalize_response(json_string)
|
40
38
|
end
|
41
39
|
|
42
40
|
API_VERSION_PATH = 'v1beta/models'
|
@@ -25,15 +25,13 @@ module ActiveGenie
|
|
25
25
|
model:
|
26
26
|
}
|
27
27
|
|
28
|
-
|
29
|
-
response = request(payload)
|
28
|
+
response = request(payload)
|
30
29
|
|
31
|
-
|
30
|
+
raise InvalidResponseError, "Invalid response: #{response}" if response.nil? || response.keys.empty?
|
32
31
|
|
33
|
-
|
32
|
+
ActiveGenie::Logger.call({ code: :function_calling, fine_tune: true, payload:, response: })
|
34
33
|
|
35
|
-
|
36
|
-
end
|
34
|
+
response
|
37
35
|
end
|
38
36
|
|
39
37
|
private
|
@@ -24,25 +24,27 @@ module ActiveGenie
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def output_call(log)
|
27
|
-
output
|
27
|
+
output&.call(log)
|
28
28
|
|
29
29
|
Array(@observers).each do |obs|
|
30
30
|
next unless obs[:scope].all? { |key, value| log[key.to_sym] == value }
|
31
31
|
|
32
|
-
obs[:observer]
|
32
|
+
obs[:observer]&.call(log)
|
33
33
|
rescue StandardError => e
|
34
34
|
ActiveGenie::Logger.call(code: :observer_error, **obs, error: e.message)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def add_observer(observers: [], scope:
|
38
|
+
def add_observer(observers: [], scope: {}, &block)
|
39
39
|
@observers ||= []
|
40
40
|
|
41
|
-
raise ArgumentError, 'Scope must be a hash'
|
41
|
+
raise ArgumentError, 'Scope must be a hash' if scope && !scope.is_a?(Hash)
|
42
42
|
|
43
|
-
@observers << { observer: block, scope:
|
43
|
+
@observers << { observer: block, scope: } if block_given?
|
44
44
|
Array(observers).each do |observer|
|
45
|
-
|
45
|
+
next unless observer.respond_to?(:call)
|
46
|
+
|
47
|
+
@observers << { observer:, scope: }
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
@@ -37,8 +37,8 @@ module ActiveGenie
|
|
37
37
|
def call
|
38
38
|
response = Generalist.call(@text, data_to_extract_with_litote, config: @config)
|
39
39
|
|
40
|
-
if response[
|
41
|
-
response = Generalist.call(response[
|
40
|
+
if response[:message_litote]
|
41
|
+
response = Generalist.call(response[:litote_rephrased], @data_to_extract, config: @config)
|
42
42
|
end
|
43
43
|
|
44
44
|
response
|
data/lib/active_genie/logger.rb
CHANGED
@@ -21,13 +21,15 @@ module ActiveGenie
|
|
21
21
|
log
|
22
22
|
end
|
23
23
|
|
24
|
-
def with_context(context)
|
24
|
+
def with_context(context, observer: nil)
|
25
25
|
@context ||= {}
|
26
26
|
begin
|
27
27
|
@context = @context.merge(context)
|
28
|
+
config.add_observer(observers: [observer])
|
28
29
|
yield if block_given?
|
29
30
|
ensure
|
30
31
|
@context.delete_if { |key, _| context.key?(key) }
|
32
|
+
config.remove_observer([observer])
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -17,11 +17,13 @@ module ActiveGenie
|
|
17
17
|
@config = config
|
18
18
|
@tmp_defenders = []
|
19
19
|
@total_tokens = 0
|
20
|
-
@previous_elo =
|
20
|
+
@previous_elo = {}
|
21
21
|
@previous_highest_elo = @defender_tier.max_by(&:elo).elo
|
22
22
|
end
|
23
23
|
|
24
24
|
def call
|
25
|
+
@previous_elo = @players.to_h { |player| [player.id, player.elo] }
|
26
|
+
|
25
27
|
ActiveGenie::Logger.with_context(log_context) do
|
26
28
|
matches.each do |player_a, player_b|
|
27
29
|
# TODO: battle can take a while, can be parallelized
|
@@ -38,10 +40,6 @@ module ActiveGenie
|
|
38
40
|
|
39
41
|
private
|
40
42
|
|
41
|
-
def save_previous_elo
|
42
|
-
@previous_elo = @players.to_h { |player| [player.id, player.elo] }
|
43
|
-
end
|
44
|
-
|
45
43
|
def matches
|
46
44
|
@relegation_tier.each_with_object([]) do |attack_player, matches|
|
47
45
|
BATTLE_PER_PLAYER.times do
|
@@ -130,7 +128,7 @@ module ActiveGenie
|
|
130
128
|
elo_diffs = players_in_round.map do |player|
|
131
129
|
[player.id, player.elo - @previous_elo[player.id]]
|
132
130
|
end
|
133
|
-
elo_diffs.sort_by { |_, diff| -diff }.to_h
|
131
|
+
elo_diffs.sort_by { |_, diff| -(diff || 0) }.to_h
|
134
132
|
end
|
135
133
|
|
136
134
|
def log_observer(log)
|
@@ -18,7 +18,7 @@ module ActiveGenie
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def call
|
21
|
-
ActiveGenie::Logger.with_context(log_context, observer:
|
21
|
+
ActiveGenie::Logger.with_context(log_context, observer: ->(log) { log_observer(log) }) do
|
22
22
|
matches.each do |player_a, player_b|
|
23
23
|
winner, loser = battle(player_a, player_b)
|
24
24
|
|
@@ -10,8 +10,6 @@ module ActiveGenie
|
|
10
10
|
@params[:content] ||= @params
|
11
11
|
end
|
12
12
|
|
13
|
-
attr_accessor :rank
|
14
|
-
|
15
13
|
def content
|
16
14
|
@content ||= @params[:content]
|
17
15
|
end
|
@@ -29,7 +27,13 @@ module ActiveGenie
|
|
29
27
|
end
|
30
28
|
|
31
29
|
def elo
|
32
|
-
@elo
|
30
|
+
@elo = if @params[:elo]
|
31
|
+
@params[:elo]
|
32
|
+
elsif @score
|
33
|
+
generate_elo_by_score
|
34
|
+
else
|
35
|
+
BASE_ELO
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
def ffa_win_count
|
@@ -56,7 +60,7 @@ module ActiveGenie
|
|
56
60
|
|
57
61
|
def elo=(value)
|
58
62
|
ActiveGenie::Logger.call({ code: :new_elo, player_id: id, elo: value }) if value != @elo
|
59
|
-
@elo = value
|
63
|
+
@elo = value || BASE_ELO
|
60
64
|
end
|
61
65
|
|
62
66
|
def eliminated=(value)
|
@@ -93,7 +97,9 @@ module ActiveGenie
|
|
93
97
|
|
94
98
|
def to_h
|
95
99
|
{
|
96
|
-
id:, name:, content:,
|
100
|
+
id:, name:, content:,
|
101
|
+
|
102
|
+
score:, elo:,
|
97
103
|
ffa_win_count:, ffa_lose_count:, ffa_draw_count:,
|
98
104
|
eliminated:, ffa_score:, sort_value:
|
99
105
|
}
|
@@ -52,19 +52,13 @@ module ActiveGenie
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def sorted
|
55
|
-
|
56
|
-
sorted_players.each_with_index { |p, i| p.rank = i + 1 }
|
57
|
-
sorted_players
|
55
|
+
@players.sort_by { |p| -p.sort_value }
|
58
56
|
end
|
59
57
|
|
60
58
|
def to_json(*_args)
|
61
59
|
to_h.to_json
|
62
60
|
end
|
63
61
|
|
64
|
-
def to_h
|
65
|
-
sorted.map(&:to_h)
|
66
|
-
end
|
67
|
-
|
68
62
|
def method_missing(...)
|
69
63
|
@players.send(...)
|
70
64
|
end
|
@@ -20,8 +20,7 @@ module ActiveGenie
|
|
20
20
|
ActiveGenie::Logger.with_context(log_context) do
|
21
21
|
@reviewers = generate_reviewers
|
22
22
|
|
23
|
-
|
24
|
-
players_to_score.each do |player|
|
23
|
+
players_without_score.each do |player|
|
25
24
|
player.score = generate_score(player)
|
26
25
|
end
|
27
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_genie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radamés Roriz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-06-
|
11
|
+
date: 2025-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
The lodash for GenAI, stop reinventing the wheel
|