legion-llm 0.3.21 → 0.3.22
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/CHANGELOG.md +8 -0
- data/lib/legion/llm/batch.rb +19 -2
- data/lib/legion/llm/off_peak.rb +6 -25
- data/lib/legion/llm/scheduling.rb +10 -10
- data/lib/legion/llm/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db13bc01a538ce15c213a0ee49dae011b79c0bdf0148ebb940dad6b54cc769c4
|
|
4
|
+
data.tar.gz: a68d77b17f0eeff3e841620cc43bae9601e9a9069b555ca583b507ab258677db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ab9351b4781dcf146d552f555d0da7eaa444a94d15125af387af33b5ae3741863fccccaafd1fd981faca6e3781589fd6f5a4a273b9a02bf940d389763c55150c
|
|
7
|
+
data.tar.gz: 4e17454656a9baf87b78a75e99bfe5cc6215a48d1135cc053abab4e85b8b300e3ece10ab5e6628dabbd7a22cbc167d1d3e1d5c63d87da226a8092db6f1ed3b64
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Legion LLM Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.22] - 2026-03-23
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- `Batch.submit_single` now calls `Legion::LLM.chat_direct` instead of returning a stub response
|
|
7
|
+
- Batch flush returns `status: :completed` on success or `status: :failed` with error on exception
|
|
8
|
+
- `OffPeak` module now delegates to `Scheduling` (consolidated duplicate peak-hour logic)
|
|
9
|
+
- `Scheduling.peak_hours?` and `Scheduling.next_off_peak` accept optional `time` parameter
|
|
10
|
+
|
|
3
11
|
## [0.3.21] - 2026-03-23
|
|
4
12
|
|
|
5
13
|
### Added
|
data/lib/legion/llm/batch.rb
CHANGED
|
@@ -101,13 +101,30 @@ module Legion
|
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
def submit_single(entry, provider:, model:)
|
|
104
|
+
response = Legion::LLM.chat_direct(
|
|
105
|
+
messages: entry[:messages],
|
|
106
|
+
model: model,
|
|
107
|
+
**entry[:opts]
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
{
|
|
111
|
+
status: :completed,
|
|
112
|
+
model: model,
|
|
113
|
+
provider: provider,
|
|
114
|
+
id: entry[:id],
|
|
115
|
+
response: response,
|
|
116
|
+
meta: { batched: true, queued_at: entry[:queued_at], completed_at: Time.now.utc }
|
|
117
|
+
}
|
|
118
|
+
rescue StandardError => e
|
|
119
|
+
Legion::Logging.warn("Batch submit_single failed for #{entry[:id]}: #{e.message}") if defined?(Legion::Logging)
|
|
104
120
|
{
|
|
105
|
-
status: :
|
|
121
|
+
status: :failed,
|
|
106
122
|
model: model,
|
|
107
123
|
provider: provider,
|
|
108
124
|
id: entry[:id],
|
|
109
125
|
response: nil,
|
|
110
|
-
|
|
126
|
+
error: e.message,
|
|
127
|
+
meta: { batched: true, queued_at: entry[:queued_at], failed_at: Time.now.utc }
|
|
111
128
|
}
|
|
112
129
|
end
|
|
113
130
|
end
|
data/lib/legion/llm/off_peak.rb
CHANGED
|
@@ -1,44 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'scheduling'
|
|
4
|
+
|
|
3
5
|
module Legion
|
|
4
6
|
module LLM
|
|
7
|
+
# Simplified peak-hour interface delegating to Scheduling.
|
|
8
|
+
# Preserved for backward compatibility.
|
|
5
9
|
module OffPeak
|
|
6
|
-
# Peak hours in UTC: 14:00-22:00 (9 AM - 5 PM CT)
|
|
7
|
-
PEAK_HOURS = (14..22)
|
|
8
|
-
|
|
9
10
|
class << self
|
|
10
|
-
# Returns true if the given time falls within peak hours.
|
|
11
|
-
#
|
|
12
|
-
# @param time [Time] time to check (defaults to now)
|
|
13
|
-
# @return [Boolean]
|
|
14
11
|
def peak_hour?(time = Time.now.utc)
|
|
15
|
-
|
|
16
|
-
Legion::Logging.debug("OffPeak peak_hour check hour=#{time.hour} peak=#{result}") if defined?(Legion::Logging)
|
|
17
|
-
result
|
|
12
|
+
Scheduling.peak_hours?(time)
|
|
18
13
|
end
|
|
19
14
|
|
|
20
|
-
# Returns true when a non-urgent request should be deferred to off-peak.
|
|
21
|
-
#
|
|
22
|
-
# @param priority [Symbol] :urgent bypasses deferral; :normal and :low defer during peak
|
|
23
|
-
# @return [Boolean]
|
|
24
15
|
def should_defer?(priority: :normal)
|
|
25
16
|
return false if priority.to_sym == :urgent
|
|
26
17
|
|
|
27
18
|
peak_hour?
|
|
28
19
|
end
|
|
29
20
|
|
|
30
|
-
# Returns the next off-peak Time (UTC).
|
|
31
|
-
# If already off-peak, returns the current time.
|
|
32
|
-
# Off-peak begins at the hour after the peak window ends (23:00 UTC).
|
|
33
|
-
#
|
|
34
|
-
# @param time [Time] reference time (defaults to now)
|
|
35
|
-
# @return [Time]
|
|
36
21
|
def next_off_peak(time = Time.now.utc)
|
|
37
|
-
|
|
38
|
-
time
|
|
39
|
-
else
|
|
40
|
-
Time.utc(time.year, time.month, time.day, PEAK_HOURS.last, 0, 0)
|
|
41
|
-
end
|
|
22
|
+
Scheduling.next_off_peak(time)
|
|
42
23
|
end
|
|
43
24
|
end
|
|
44
25
|
end
|
|
@@ -29,9 +29,9 @@ module Legion
|
|
|
29
29
|
result
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
# Returns true if the
|
|
33
|
-
def peak_hours?
|
|
34
|
-
hour = Time.now.utc.hour
|
|
32
|
+
# Returns true if the given UTC hour falls within the configured peak window.
|
|
33
|
+
def peak_hours?(time = Time.now.utc)
|
|
34
|
+
hour = time.is_a?(Time) ? time.hour : Time.now.utc.hour
|
|
35
35
|
peak_range.cover?(hour)
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -39,19 +39,19 @@ module Legion
|
|
|
39
39
|
# Off-peak begins at the hour after the peak window ends.
|
|
40
40
|
#
|
|
41
41
|
# @return [Time] next off-peak start time
|
|
42
|
-
def next_off_peak
|
|
43
|
-
now = Time.now.utc
|
|
42
|
+
def next_off_peak(time = Time.now.utc)
|
|
43
|
+
now = time.is_a?(Time) ? time : Time.now.utc
|
|
44
44
|
peak_end = peak_range.last
|
|
45
45
|
max_defer = settings.fetch(:max_defer_hours, 8)
|
|
46
46
|
|
|
47
|
-
next_time = if now
|
|
48
|
-
#
|
|
49
|
-
now
|
|
50
|
-
else
|
|
51
|
-
# During or after peak — next off-peak is at peak_end + 1
|
|
47
|
+
next_time = if peak_hours?(now)
|
|
48
|
+
# During peak — next off-peak is at peak_end + 1
|
|
52
49
|
candidate = Time.utc(now.year, now.month, now.day, peak_end + 1, 0, 0)
|
|
53
50
|
candidate += 86_400 if candidate <= now
|
|
54
51
|
candidate
|
|
52
|
+
else
|
|
53
|
+
# Already off-peak — return now
|
|
54
|
+
now
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
# Cap at max_defer_hours from now
|
data/lib/legion/llm/version.rb
CHANGED