lex-llm-gateway 0.2.12 → 0.2.13
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/LICENSE +201 -21
- data/lex-llm-gateway.gemspec +1 -0
- data/lib/legion/extensions/llm/gateway/actors/spool_flush.rb +1 -1
- data/lib/legion/extensions/llm/gateway/helpers/auth.rb +2 -2
- data/lib/legion/extensions/llm/gateway/helpers/cost_estimator.rb +12 -12
- data/lib/legion/extensions/llm/gateway/helpers/reply_dispatcher.rb +15 -15
- data/lib/legion/extensions/llm/gateway/helpers/rpc.rb +2 -4
- data/lib/legion/extensions/llm/gateway/helpers/usage_queries.rb +2 -2
- data/lib/legion/extensions/llm/gateway/runners/fleet.rb +2 -2
- data/lib/legion/extensions/llm/gateway/runners/fleet_handler.rb +21 -23
- data/lib/legion/extensions/llm/gateway/runners/inference.rb +19 -21
- data/lib/legion/extensions/llm/gateway/runners/metering.rb +10 -10
- data/lib/legion/extensions/llm/gateway/runners/metering_writer.rb +15 -15
- data/lib/legion/extensions/llm/gateway/runners/provider_stats.rb +7 -7
- data/lib/legion/extensions/llm/gateway/runners/usage_reporter.rb +11 -11
- data/lib/legion/extensions/llm/gateway/transport/messages/inference_response.rb +7 -7
- data/lib/legion/extensions/llm/gateway/transport/messages/metering_event.rb +11 -11
- data/lib/legion/extensions/llm/gateway/transport/queues/inference_process.rb +1 -1
- data/lib/legion/extensions/llm/gateway/transport/queues/metering_write.rb +1 -1
- data/lib/legion/extensions/llm/gateway/version.rb +1 -1
- data/lib/legion/extensions/llm/gateway.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3508dacc36a4c4fe57b9969cebd91aad39c5e3ab0edd67234bcb1a7b2094d84
|
|
4
|
+
data.tar.gz: 35eac64d3c2eadd149ad4c15dd87905ae83ea56a6b4b4a7ebbc1b7e0111b2605
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3910799509e5b020c223301493edae1bf5260d5544b5225448f2323740ce42139ea6fbc4a3350d61c01a66ebc0cfdf0c5fcb28a3c58d5e66796a209473e9b4e6
|
|
7
|
+
data.tar.gz: 104043cffae24348aed89a1183c1426be9205f45f9c882d92183f35759b10cd0c2d5a5958e2f2d64bf05c87163f57535b27c816eeec20d229c4b5ff7f6bffd15
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.13] - 2026-03-30
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- Add rubocop-legion 0.1.7 shared config via `inherit_gem`
|
|
7
|
+
- Replace all `log.*` calls in `module_function` modules with `Legion::Logging.*` and inline disable comments
|
|
8
|
+
- Replace `llm_chat`/`llm_embed`/`llm_structured` helper calls with `Legion::LLM.*` direct calls in `module_function` contexts
|
|
9
|
+
- Update CI workflow: rename `lint` job to `excluded-files`, update workflow ref to `excluded-files.yml@main`
|
|
10
|
+
|
|
3
11
|
## [0.2.12] - 2026-03-24
|
|
4
12
|
|
|
5
13
|
### Fixed
|
data/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2021 Esity
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/lex-llm-gateway.gemspec
CHANGED
|
@@ -39,5 +39,6 @@ Gem::Specification.new do |spec|
|
|
|
39
39
|
spec.add_development_dependency 'rake'
|
|
40
40
|
spec.add_development_dependency 'rspec'
|
|
41
41
|
spec.add_development_dependency 'rubocop'
|
|
42
|
+
spec.add_development_dependency 'rubocop-legion'
|
|
42
43
|
spec.add_development_dependency 'rubocop-rspec'
|
|
43
44
|
end
|
|
@@ -5,7 +5,7 @@ module Legion
|
|
|
5
5
|
module LLM
|
|
6
6
|
module Gateway
|
|
7
7
|
module Actor
|
|
8
|
-
class SpoolFlush < Legion::Extensions::Actors::Every
|
|
8
|
+
class SpoolFlush < Legion::Extensions::Actors::Every # rubocop:disable Legion/Extension/EveryActorRequiresTime
|
|
9
9
|
def runner_class
|
|
10
10
|
'Legion::Extensions::LLM::Gateway::Runners::Metering'
|
|
11
11
|
end
|
|
@@ -12,7 +12,7 @@ module Legion
|
|
|
12
12
|
return nil unless defined?(Legion::Crypt::JWT)
|
|
13
13
|
|
|
14
14
|
Legion::Crypt::JWT.encode(payload: payload, ttl: 60)
|
|
15
|
-
rescue StandardError
|
|
15
|
+
rescue StandardError => _e
|
|
16
16
|
nil
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ module Legion
|
|
|
20
20
|
return nil unless defined?(Legion::Crypt::JWT)
|
|
21
21
|
|
|
22
22
|
Legion::Crypt::JWT.decode(token: token)
|
|
23
|
-
rescue StandardError
|
|
23
|
+
rescue StandardError => _e
|
|
24
24
|
nil
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -9,20 +9,20 @@ module Legion
|
|
|
9
9
|
# Prices per 1M tokens [input, output] in USD
|
|
10
10
|
# Source: published API pricing as of 2026-03
|
|
11
11
|
PRICING = {
|
|
12
|
-
'claude-opus-4-6'
|
|
12
|
+
'claude-opus-4-6' => [15.0, 75.0],
|
|
13
13
|
'claude-sonnet-4-6' => [3.0, 15.0],
|
|
14
|
-
'claude-haiku-4-5'
|
|
14
|
+
'claude-haiku-4-5' => [0.80, 4.0],
|
|
15
15
|
'claude-3-5-sonnet' => [3.0, 15.0],
|
|
16
|
-
'claude-3-haiku'
|
|
17
|
-
'gpt-4o'
|
|
18
|
-
'gpt-4o-mini'
|
|
19
|
-
'gpt-4-turbo'
|
|
20
|
-
'o3'
|
|
21
|
-
'o3-mini'
|
|
22
|
-
'o4-mini'
|
|
23
|
-
'gemini-2.5-pro'
|
|
24
|
-
'gemini-2.5-flash'
|
|
25
|
-
'gemini-2.0-flash'
|
|
16
|
+
'claude-3-haiku' => [0.25, 1.25],
|
|
17
|
+
'gpt-4o' => [2.50, 10.0],
|
|
18
|
+
'gpt-4o-mini' => [0.15, 0.60],
|
|
19
|
+
'gpt-4-turbo' => [10.0, 30.0],
|
|
20
|
+
'o3' => [10.0, 40.0],
|
|
21
|
+
'o3-mini' => [1.10, 4.40],
|
|
22
|
+
'o4-mini' => [1.10, 4.40],
|
|
23
|
+
'gemini-2.5-pro' => [1.25, 10.0],
|
|
24
|
+
'gemini-2.5-flash' => [0.15, 0.60],
|
|
25
|
+
'gemini-2.0-flash' => [0.10, 0.40]
|
|
26
26
|
}.freeze
|
|
27
27
|
|
|
28
28
|
DEFAULT_PRICE = [1.0, 3.0].freeze
|
|
@@ -16,13 +16,13 @@ module Legion
|
|
|
16
16
|
|
|
17
17
|
def register(correlation_id)
|
|
18
18
|
future = Concurrent::Promises.resolvable_future
|
|
19
|
-
@pending[correlation_id] = future
|
|
19
|
+
@pending[correlation_id] = future # rubocop:disable ThreadSafety/ClassInstanceVariable
|
|
20
20
|
ensure_consumer
|
|
21
21
|
future
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def deregister(correlation_id)
|
|
25
|
-
@pending.delete(correlation_id)
|
|
25
|
+
@pending.delete(correlation_id) # rubocop:disable ThreadSafety/ClassInstanceVariable
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def handle_delivery(raw_payload, properties = {})
|
|
@@ -30,16 +30,16 @@ module Legion
|
|
|
30
30
|
cid = properties[:correlation_id] || payload[:correlation_id]
|
|
31
31
|
return unless cid
|
|
32
32
|
|
|
33
|
-
future = @pending.delete(cid)
|
|
33
|
+
future = @pending.delete(cid) # rubocop:disable ThreadSafety/ClassInstanceVariable
|
|
34
34
|
return unless future
|
|
35
35
|
|
|
36
36
|
future.fulfill(payload.merge(success: true))
|
|
37
37
|
rescue StandardError => e
|
|
38
|
-
|
|
38
|
+
Legion::Logging.warn("ReplyDispatcher: handle_delivery failed: #{e.message}") if defined?(Legion::Logging) # rubocop:disable Legion/HelperMigration/DirectLogging, Legion/HelperMigration/LoggingGuard
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def pending_count
|
|
42
|
-
@pending.size
|
|
42
|
+
@pending.size # rubocop:disable ThreadSafety/ClassInstanceVariable
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def reset!
|
|
@@ -51,7 +51,7 @@ module Legion
|
|
|
51
51
|
|
|
52
52
|
# private
|
|
53
53
|
|
|
54
|
-
def ensure_consumer
|
|
54
|
+
def ensure_consumer
|
|
55
55
|
@mutex.synchronize do
|
|
56
56
|
return if @consumer
|
|
57
57
|
return unless transport_available?
|
|
@@ -67,18 +67,18 @@ module Legion
|
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
rescue StandardError => e
|
|
70
|
-
|
|
70
|
+
Legion::Logging.warn("ReplyDispatcher: consumer setup failed: #{e.message}") if defined?(Legion::Logging) # rubocop:disable Legion/HelperMigration/DirectLogging, Legion/HelperMigration/LoggingGuard
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def cancel_consumer
|
|
74
|
-
@consumer&.cancel
|
|
75
|
-
@consumer = nil
|
|
74
|
+
@consumer&.cancel # rubocop:disable ThreadSafety/ClassInstanceVariable
|
|
75
|
+
@consumer = nil # rubocop:disable ThreadSafety/ClassInstanceVariable
|
|
76
76
|
rescue StandardError => e
|
|
77
|
-
|
|
77
|
+
Legion::Logging.warn("ReplyDispatcher: cancel failed: #{e.message}") if defined?(Legion::Logging) # rubocop:disable Legion/HelperMigration/DirectLogging, Legion/HelperMigration/LoggingGuard
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def transport_available?
|
|
81
|
-
defined?(Legion::Transport) &&
|
|
81
|
+
defined?(Legion::Transport) && # rubocop:disable Legion/HelperMigration/DefinedTransportGuard
|
|
82
82
|
Legion::Transport.respond_to?(:connection) &&
|
|
83
83
|
Legion::Transport.connection
|
|
84
84
|
end
|
|
@@ -87,17 +87,17 @@ module Legion
|
|
|
87
87
|
return raw if raw.is_a?(Hash)
|
|
88
88
|
|
|
89
89
|
if defined?(Legion::JSON)
|
|
90
|
-
Legion::JSON.load(raw)
|
|
90
|
+
Legion::JSON.load(raw) # rubocop:disable Legion/HelperMigration/DirectJson
|
|
91
91
|
else
|
|
92
92
|
require 'json'
|
|
93
|
-
JSON.parse(raw, symbolize_names: true)
|
|
93
|
+
::JSON.parse(raw, symbolize_names: true)
|
|
94
94
|
end
|
|
95
|
-
rescue StandardError
|
|
95
|
+
rescue StandardError => _e
|
|
96
96
|
{}
|
|
97
97
|
end
|
|
98
98
|
|
|
99
99
|
def log_warn(msg)
|
|
100
|
-
Legion::Logging.warn(msg) if defined?(Legion::Logging)
|
|
100
|
+
Legion::Logging.warn(msg) if defined?(Legion::Logging) # rubocop:disable Legion/HelperMigration/DirectLogging, Legion/HelperMigration/LoggingGuard
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
end
|
|
@@ -15,16 +15,14 @@ module Legion
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def agent_queue_name
|
|
18
|
-
if defined?(Legion::Transport) && Legion::Transport.respond_to?(:agent_queue_name)
|
|
19
|
-
return Legion::Transport.agent_queue_name
|
|
20
|
-
end
|
|
18
|
+
return Legion::Transport.agent_queue_name if defined?(Legion::Transport) && Legion::Transport.respond_to?(:agent_queue_name) # rubocop:disable Legion/HelperMigration/DefinedTransportGuard
|
|
21
19
|
|
|
22
20
|
nil
|
|
23
21
|
end
|
|
24
22
|
|
|
25
23
|
def build_reply_headers(correlation_id:)
|
|
26
24
|
{
|
|
27
|
-
reply_to:
|
|
25
|
+
reply_to: agent_queue_name,
|
|
28
26
|
correlation_id: correlation_id
|
|
29
27
|
}
|
|
30
28
|
end
|
|
@@ -20,8 +20,8 @@ module Legion
|
|
|
20
20
|
{
|
|
21
21
|
total_requests: dataset.count,
|
|
22
22
|
total_cost_usd: dataset.sum(:cost_usd).to_f.round(4),
|
|
23
|
-
total_input:
|
|
24
|
-
total_output:
|
|
23
|
+
total_input: dataset.sum(:input_tokens).to_i,
|
|
24
|
+
total_output: dataset.sum(:output_tokens).to_i
|
|
25
25
|
}
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -30,7 +30,7 @@ module Legion
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def transport_ready?
|
|
33
|
-
!!(defined?(Legion::Transport) &&
|
|
33
|
+
!!(defined?(Legion::Transport) && # rubocop:disable Legion/HelperMigration/DefinedTransportGuard
|
|
34
34
|
Legion::Transport.respond_to?(:connected?) &&
|
|
35
35
|
Legion::Transport.connected?)
|
|
36
36
|
end
|
|
@@ -80,7 +80,7 @@ module Legion
|
|
|
80
80
|
future = Helpers::ReplyDispatcher.register(correlation_id)
|
|
81
81
|
result = future.value!(timeout)
|
|
82
82
|
result || timeout_result(correlation_id, timeout)
|
|
83
|
-
rescue Concurrent::CancelledOperationError
|
|
83
|
+
rescue Concurrent::CancelledOperationError => _e
|
|
84
84
|
timeout_result(correlation_id, timeout)
|
|
85
85
|
ensure
|
|
86
86
|
Helpers::ReplyDispatcher.deregister(correlation_id)
|
|
@@ -48,65 +48,63 @@ module Legion
|
|
|
48
48
|
def call_chat(payload)
|
|
49
49
|
messages = payload[:messages]
|
|
50
50
|
if messages.is_a?(Array) && messages.size > 1
|
|
51
|
-
Legion::LLM.chat(model: payload[:model], messages: messages,
|
|
51
|
+
Legion::LLM.chat(model: payload[:model], messages: messages, # rubocop:disable Legion/HelperMigration/DirectLlm
|
|
52
52
|
caller: { extension: 'lex-llm-gateway', operation: 'fleet' })
|
|
53
53
|
else
|
|
54
|
-
Legion::LLM.chat(model: payload[:model], message: messages&.dig(0, :content),
|
|
54
|
+
Legion::LLM.chat(model: payload[:model], message: messages&.dig(0, :content), # rubocop:disable Legion/HelperMigration/DirectLlm
|
|
55
55
|
caller: { extension: 'lex-llm-gateway', operation: 'fleet' })
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def call_structured(payload)
|
|
60
|
-
Legion::LLM.structured(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
caller: { extension: 'lex-llm-gateway', operation: 'fleet' }
|
|
65
|
-
)
|
|
60
|
+
Legion::LLM.structured(model: payload[:model], # rubocop:disable Legion/HelperMigration/DirectLlm
|
|
61
|
+
messages: payload[:messages],
|
|
62
|
+
schema: payload[:schema],
|
|
63
|
+
caller: { extension: 'lex-llm-gateway', operation: 'fleet' })
|
|
66
64
|
end
|
|
67
65
|
|
|
68
66
|
def call_embed(payload)
|
|
69
67
|
text = payload[:text] || payload.dig(:messages, 0, :content)
|
|
70
|
-
Legion::LLM.embed(model: payload[:model], text: text,
|
|
68
|
+
Legion::LLM.embed(model: payload[:model], text: text, # rubocop:disable Legion/HelperMigration/DirectLlm
|
|
71
69
|
caller: { extension: 'lex-llm-gateway', operation: 'fleet' })
|
|
72
70
|
end
|
|
73
71
|
|
|
74
72
|
def build_response(correlation_id, response)
|
|
75
73
|
{
|
|
76
|
-
correlation_id:
|
|
77
|
-
response:
|
|
78
|
-
input_tokens:
|
|
79
|
-
output_tokens:
|
|
74
|
+
correlation_id: correlation_id,
|
|
75
|
+
response: response,
|
|
76
|
+
input_tokens: extract_token(response, :input_tokens),
|
|
77
|
+
output_tokens: extract_token(response, :output_tokens),
|
|
80
78
|
thinking_tokens: extract_token(response, :thinking_tokens),
|
|
81
|
-
provider:
|
|
82
|
-
model_id:
|
|
79
|
+
provider: extract_field(response, :provider),
|
|
80
|
+
model_id: extract_field(response, :model)
|
|
83
81
|
}
|
|
84
82
|
end
|
|
85
83
|
|
|
86
|
-
def publish_reply(reply_to, correlation_id, response_hash)
|
|
87
|
-
return unless defined?(Legion::Transport)
|
|
84
|
+
def publish_reply(reply_to, correlation_id, response_hash)
|
|
85
|
+
return unless defined?(Legion::Transport) # rubocop:disable Legion/HelperMigration/DefinedTransportGuard
|
|
88
86
|
|
|
89
87
|
payload = if defined?(Legion::JSON)
|
|
90
|
-
Legion::JSON.dump(response_hash)
|
|
88
|
+
Legion::JSON.dump(response_hash) # rubocop:disable Legion/HelperMigration/DirectJson
|
|
91
89
|
else
|
|
92
90
|
require 'json'
|
|
93
|
-
JSON.generate(response_hash)
|
|
91
|
+
::JSON.generate(response_hash)
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
channel = Legion::Transport.connection.create_channel
|
|
97
95
|
channel.default_exchange.publish(
|
|
98
96
|
payload,
|
|
99
|
-
routing_key:
|
|
97
|
+
routing_key: reply_to,
|
|
100
98
|
correlation_id: correlation_id,
|
|
101
|
-
content_type:
|
|
99
|
+
content_type: 'application/json'
|
|
102
100
|
)
|
|
103
101
|
channel.close
|
|
104
102
|
rescue StandardError => e
|
|
105
|
-
|
|
103
|
+
Legion::Logging.warn("FleetHandler: publish_reply failed: #{e.message}") if defined?(Legion::Logging) # rubocop:disable Legion/HelperMigration/DirectLogging, Legion/HelperMigration/LoggingGuard
|
|
106
104
|
end
|
|
107
105
|
|
|
108
106
|
def log_warn(msg)
|
|
109
|
-
Legion::Logging.warn(msg) if defined?(Legion::Logging)
|
|
107
|
+
Legion::Logging.warn(msg) if defined?(Legion::Logging) # rubocop:disable Legion/HelperMigration/DirectLogging, Legion/HelperMigration/LoggingGuard
|
|
110
108
|
end
|
|
111
109
|
|
|
112
110
|
def extract_token(response, field)
|
|
@@ -5,13 +5,13 @@ module Legion
|
|
|
5
5
|
module LLM
|
|
6
6
|
module Gateway
|
|
7
7
|
module Runners
|
|
8
|
-
module Inference
|
|
8
|
+
module Inference
|
|
9
9
|
module_function
|
|
10
10
|
|
|
11
|
-
def chat(model: nil, provider: nil, **opts)
|
|
11
|
+
def chat(model: nil, provider: nil, **opts)
|
|
12
12
|
if pipeline_available?
|
|
13
13
|
log_deprecation(:chat)
|
|
14
|
-
return Legion::LLM.chat(model: model, provider: provider,
|
|
14
|
+
return Legion::LLM.chat(model: model, provider: provider, # rubocop:disable Legion/HelperMigration/DirectLlm
|
|
15
15
|
caller: { extension: 'lex-llm-gateway', operation: 'inference' }, **opts)
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -23,11 +23,11 @@ module Legion
|
|
|
23
23
|
response
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
def embed(text: nil, model: nil, provider: nil, **)
|
|
26
|
+
def embed(text: nil, model: nil, provider: nil, **)
|
|
27
27
|
if pipeline_available?
|
|
28
28
|
log_deprecation(:embed)
|
|
29
|
-
return Legion::LLM.embed(text, model: model, provider: provider,
|
|
30
|
-
|
|
29
|
+
return Legion::LLM.embed(text, model: model, provider: provider, # rubocop:disable Legion/HelperMigration/DirectLlm
|
|
30
|
+
caller: { extension: 'lex-llm-gateway', operation: 'inference' }, **)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
start_ms = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :millisecond)
|
|
@@ -38,10 +38,10 @@ module Legion
|
|
|
38
38
|
response
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
def structured(messages: nil, schema: nil, model: nil, provider: nil, **)
|
|
41
|
+
def structured(messages: nil, schema: nil, model: nil, provider: nil, **)
|
|
42
42
|
if pipeline_available?
|
|
43
43
|
log_deprecation(:structured)
|
|
44
|
-
return Legion::LLM.structured(messages: messages, schema: schema, model: model,
|
|
44
|
+
return Legion::LLM.structured(messages: messages, schema: schema, model: model, # rubocop:disable Legion/HelperMigration/DirectLlm
|
|
45
45
|
provider: provider,
|
|
46
46
|
caller: { extension: 'lex-llm-gateway', operation: 'inference' }, **)
|
|
47
47
|
end
|
|
@@ -63,16 +63,14 @@ module Legion
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def log_deprecation(method)
|
|
66
|
-
return unless defined?(Legion::Logging)
|
|
66
|
+
return unless defined?(Legion::Logging) # rubocop:disable Legion/HelperMigration/LoggingGuard
|
|
67
67
|
|
|
68
|
-
Legion::Logging.warn(
|
|
69
|
-
"lex-llm-gateway is deprecated for #{method}, use Legion::LLM.#{method} directly"
|
|
70
|
-
)
|
|
68
|
+
Legion::Logging.warn("lex-llm-gateway is deprecated for #{method}, use Legion::LLM.#{method} directly") # rubocop:disable Legion/HelperMigration/DirectLogging
|
|
71
69
|
end
|
|
72
70
|
|
|
73
71
|
def dispatch_chat(message: nil, messages: nil, model: nil, provider: nil, **opts)
|
|
74
72
|
tier = opts[:tier]
|
|
75
|
-
Legion::Logging.debug
|
|
73
|
+
Legion::Logging.debug("[Gateway::Inference] dispatch_chat tier=#{tier}") if defined?(Legion::Logging) # rubocop:disable Legion/HelperMigration/DirectLogging, Legion/HelperMigration/LoggingGuard
|
|
76
74
|
if tier == 'fleet' && fleet_available?
|
|
77
75
|
fleet_messages = messages || [{ role: 'user', content: message }]
|
|
78
76
|
Fleet.dispatch(model: model, messages: fleet_messages, intent: opts[:intent])
|
|
@@ -108,7 +106,7 @@ module Legion
|
|
|
108
106
|
|
|
109
107
|
def call_llm(method_name, **)
|
|
110
108
|
unless defined?(Legion::LLM)
|
|
111
|
-
Legion::Logging.warn
|
|
109
|
+
Legion::Logging.warn('[Gateway::Inference] Legion::LLM not defined') if defined?(Legion::Logging) # rubocop:disable Legion/HelperMigration/DirectLogging, Legion/HelperMigration/LoggingGuard
|
|
112
110
|
return { error: 'llm_not_available' }
|
|
113
111
|
end
|
|
114
112
|
|
|
@@ -127,19 +125,19 @@ module Legion
|
|
|
127
125
|
|
|
128
126
|
def base_meter_fields(response, opts)
|
|
129
127
|
{
|
|
130
|
-
request_type:
|
|
131
|
-
provider:
|
|
132
|
-
model_id:
|
|
133
|
-
latency_ms:
|
|
134
|
-
tier:
|
|
128
|
+
request_type: opts[:request_type],
|
|
129
|
+
provider: extract_provider(response, opts[:provider]),
|
|
130
|
+
model_id: extract_model(response, opts[:model_id]),
|
|
131
|
+
latency_ms: opts[:latency_ms],
|
|
132
|
+
tier: opts[:tier],
|
|
135
133
|
routing_reason: opts[:intent]
|
|
136
134
|
}
|
|
137
135
|
end
|
|
138
136
|
|
|
139
137
|
def token_fields(response)
|
|
140
138
|
{
|
|
141
|
-
input_tokens:
|
|
142
|
-
output_tokens:
|
|
139
|
+
input_tokens: extract_tokens(response, :input_tokens),
|
|
140
|
+
output_tokens: extract_tokens(response, :output_tokens),
|
|
143
141
|
thinking_tokens: extract_tokens(response, :thinking_tokens)
|
|
144
142
|
}
|
|
145
143
|
end
|
|
@@ -14,13 +14,13 @@ module Legion
|
|
|
14
14
|
|
|
15
15
|
def identity_fields(opts)
|
|
16
16
|
{
|
|
17
|
-
node_id:
|
|
18
|
-
worker_id:
|
|
19
|
-
agent_id:
|
|
17
|
+
node_id: opts[:node_id],
|
|
18
|
+
worker_id: opts[:worker_id],
|
|
19
|
+
agent_id: opts[:agent_id],
|
|
20
20
|
request_type: opts[:request_type],
|
|
21
|
-
tier:
|
|
22
|
-
provider:
|
|
23
|
-
model_id:
|
|
21
|
+
tier: opts[:tier],
|
|
22
|
+
provider: opts[:provider],
|
|
23
|
+
model_id: opts[:model_id]
|
|
24
24
|
}
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -34,10 +34,10 @@ module Legion
|
|
|
34
34
|
|
|
35
35
|
def timing_and_context(opts)
|
|
36
36
|
{
|
|
37
|
-
latency_ms:
|
|
38
|
-
wall_clock_ms:
|
|
37
|
+
latency_ms: opts.fetch(:latency_ms, 0),
|
|
38
|
+
wall_clock_ms: opts.fetch(:wall_clock_ms, 0),
|
|
39
39
|
routing_reason: opts[:routing_reason],
|
|
40
|
-
recorded_at:
|
|
40
|
+
recorded_at: Time.now.utc.iso8601
|
|
41
41
|
}
|
|
42
42
|
end
|
|
43
43
|
|
|
@@ -61,7 +61,7 @@ module Legion
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def transport_connected?
|
|
64
|
-
!!(defined?(Legion::Transport) &&
|
|
64
|
+
!!(defined?(Legion::Transport) && # rubocop:disable Legion/HelperMigration/DefinedTransportGuard
|
|
65
65
|
Legion::Transport.respond_to?(:connected?) &&
|
|
66
66
|
Legion::Transport.connected?)
|
|
67
67
|
end
|
|
@@ -33,39 +33,39 @@ module Legion
|
|
|
33
33
|
|
|
34
34
|
def identity_fields(payload)
|
|
35
35
|
{
|
|
36
|
-
worker_id:
|
|
37
|
-
task_id:
|
|
38
|
-
provider:
|
|
39
|
-
model_id:
|
|
36
|
+
worker_id: payload[:worker_id],
|
|
37
|
+
task_id: payload[:task_id],
|
|
38
|
+
provider: payload[:provider],
|
|
39
|
+
model_id: payload[:model_id],
|
|
40
40
|
routing_reason: payload[:routing_reason],
|
|
41
|
-
recorded_at:
|
|
41
|
+
recorded_at: payload[:recorded_at] || Time.now.utc
|
|
42
42
|
}
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def trace_fields(payload)
|
|
46
46
|
{
|
|
47
|
-
status:
|
|
48
|
-
event_type:
|
|
49
|
-
extension:
|
|
47
|
+
status: payload[:status],
|
|
48
|
+
event_type: payload[:event_type],
|
|
49
|
+
extension: payload[:extension],
|
|
50
50
|
runner_function: payload[:runner_function]
|
|
51
51
|
}
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def metric_fields(payload)
|
|
55
55
|
{
|
|
56
|
-
input_tokens:
|
|
57
|
-
output_tokens:
|
|
56
|
+
input_tokens: payload[:input_tokens].to_i,
|
|
57
|
+
output_tokens: payload[:output_tokens].to_i,
|
|
58
58
|
thinking_tokens: payload[:thinking_tokens].to_i,
|
|
59
|
-
total_tokens:
|
|
60
|
-
latency_ms:
|
|
61
|
-
wall_clock_ms:
|
|
59
|
+
total_tokens: payload[:total_tokens].to_i,
|
|
60
|
+
latency_ms: payload[:latency_ms].to_i,
|
|
61
|
+
wall_clock_ms: payload[:wall_clock_ms].to_i
|
|
62
62
|
}
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def cost_field(payload)
|
|
66
66
|
cost = payload[:cost_usd] || Helpers::CostEstimator.estimate(
|
|
67
|
-
model_id:
|
|
68
|
-
input_tokens:
|
|
67
|
+
model_id: payload[:model_id],
|
|
68
|
+
input_tokens: payload[:input_tokens].to_i,
|
|
69
69
|
output_tokens: payload[:output_tokens].to_i
|
|
70
70
|
)
|
|
71
71
|
{ cost_usd: cost.to_f }
|
|
@@ -28,9 +28,9 @@ module Legion
|
|
|
28
28
|
tracker = health_tracker
|
|
29
29
|
providers = known_providers
|
|
30
30
|
{
|
|
31
|
-
total:
|
|
32
|
-
closed:
|
|
33
|
-
open:
|
|
31
|
+
total: providers.size,
|
|
32
|
+
closed: providers.count { |p| tracker.circuit_state(p) == :closed },
|
|
33
|
+
open: providers.count { |p| tracker.circuit_state(p) == :open },
|
|
34
34
|
half_open: providers.count { |p| tracker.circuit_state(p) == :half_open }
|
|
35
35
|
}
|
|
36
36
|
end
|
|
@@ -54,16 +54,16 @@ module Legion
|
|
|
54
54
|
providers.select { |_, cfg| cfg.is_a?(Hash) && cfg[:enabled] }
|
|
55
55
|
.keys
|
|
56
56
|
.map(&:to_sym)
|
|
57
|
-
rescue StandardError
|
|
57
|
+
rescue StandardError => _e
|
|
58
58
|
[]
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def provider_entry(name, tracker)
|
|
62
62
|
{
|
|
63
|
-
provider:
|
|
64
|
-
circuit:
|
|
63
|
+
provider: name.to_s,
|
|
64
|
+
circuit: tracker.circuit_state(name).to_s,
|
|
65
65
|
adjustment: tracker.adjustment(name),
|
|
66
|
-
healthy:
|
|
66
|
+
healthy: tracker.circuit_state(name) != :open
|
|
67
67
|
}
|
|
68
68
|
end
|
|
69
69
|
|
|
@@ -55,31 +55,31 @@ module Legion
|
|
|
55
55
|
|
|
56
56
|
def build_summary(dataset, period, since)
|
|
57
57
|
queries.aggregate_totals(dataset).merge(
|
|
58
|
-
period:
|
|
59
|
-
since:
|
|
58
|
+
period: period.to_s,
|
|
59
|
+
since: since.iso8601,
|
|
60
60
|
by_provider: queries.grouped_rows(dataset, :provider),
|
|
61
|
-
by_model:
|
|
61
|
+
by_model: queries.grouped_rows(dataset, :model_id)
|
|
62
62
|
)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def build_worker_summary(dataset, worker_id, period, since)
|
|
66
66
|
queries.aggregate_totals(dataset).merge(
|
|
67
67
|
worker_id: worker_id,
|
|
68
|
-
period:
|
|
69
|
-
since:
|
|
70
|
-
by_model:
|
|
68
|
+
period: period.to_s,
|
|
69
|
+
since: since.iso8601,
|
|
70
|
+
by_model: queries.grouped_rows(dataset, :model_id)
|
|
71
71
|
)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def build_budget_result(budget, spent, alert_at, period)
|
|
75
75
|
ratio = budget.positive? ? (spent / budget) : 0.0
|
|
76
76
|
{
|
|
77
|
-
period:
|
|
78
|
-
budget:
|
|
79
|
-
spent:
|
|
77
|
+
period: period.to_s,
|
|
78
|
+
budget: budget.round(2),
|
|
79
|
+
spent: spent.round(4),
|
|
80
80
|
remaining: [(budget - spent), 0.0].max.round(4),
|
|
81
|
-
ratio:
|
|
82
|
-
status:
|
|
81
|
+
ratio: ratio.round(4),
|
|
82
|
+
status: budget_status(ratio, alert_at)
|
|
83
83
|
}
|
|
84
84
|
end
|
|
85
85
|
|
|
@@ -28,10 +28,10 @@ module Legion
|
|
|
28
28
|
def message
|
|
29
29
|
token_fields.merge(
|
|
30
30
|
correlation_id: @options[:correlation_id],
|
|
31
|
-
response:
|
|
32
|
-
provider:
|
|
33
|
-
model_id:
|
|
34
|
-
error:
|
|
31
|
+
response: @options[:response],
|
|
32
|
+
provider: @options[:provider],
|
|
33
|
+
model_id: @options[:model_id],
|
|
34
|
+
error: @options[:error]
|
|
35
35
|
)
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -39,10 +39,10 @@ module Legion
|
|
|
39
39
|
|
|
40
40
|
def token_fields
|
|
41
41
|
{
|
|
42
|
-
input_tokens:
|
|
43
|
-
output_tokens:
|
|
42
|
+
input_tokens: @options[:input_tokens] || 0,
|
|
43
|
+
output_tokens: @options[:output_tokens] || 0,
|
|
44
44
|
thinking_tokens: @options[:thinking_tokens] || 0,
|
|
45
|
-
latency_ms:
|
|
45
|
+
latency_ms: @options[:latency_ms] || 0
|
|
46
46
|
}
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -34,35 +34,35 @@ module Legion
|
|
|
34
34
|
|
|
35
35
|
def identity_fields
|
|
36
36
|
{
|
|
37
|
-
node_id:
|
|
38
|
-
worker_id:
|
|
39
|
-
agent_id:
|
|
37
|
+
node_id: @options[:node_id],
|
|
38
|
+
worker_id: @options[:worker_id],
|
|
39
|
+
agent_id: @options[:agent_id],
|
|
40
40
|
request_type: @options[:request_type],
|
|
41
|
-
tier:
|
|
42
|
-
provider:
|
|
43
|
-
model_id:
|
|
41
|
+
tier: @options[:tier],
|
|
42
|
+
provider: @options[:provider],
|
|
43
|
+
model_id: @options[:model_id]
|
|
44
44
|
}
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def context_fields
|
|
48
48
|
{
|
|
49
49
|
routing_reason: @options[:routing_reason],
|
|
50
|
-
recorded_at:
|
|
50
|
+
recorded_at: @options[:recorded_at] || Time.now.utc.iso8601
|
|
51
51
|
}
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def token_fields
|
|
55
55
|
{
|
|
56
|
-
input_tokens:
|
|
57
|
-
output_tokens:
|
|
56
|
+
input_tokens: @options[:input_tokens] || 0,
|
|
57
|
+
output_tokens: @options[:output_tokens] || 0,
|
|
58
58
|
thinking_tokens: @options[:thinking_tokens] || 0,
|
|
59
|
-
total_tokens:
|
|
59
|
+
total_tokens: @options[:total_tokens] || 0
|
|
60
60
|
}
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def timing_fields
|
|
64
64
|
{
|
|
65
|
-
latency_ms:
|
|
65
|
+
latency_ms: @options[:latency_ms] || 0,
|
|
66
66
|
wall_clock_ms: @options[:wall_clock_ms] || 0
|
|
67
67
|
}
|
|
68
68
|
end
|
|
@@ -6,7 +6,7 @@ module Legion
|
|
|
6
6
|
module Extensions
|
|
7
7
|
module LLM
|
|
8
8
|
module Gateway
|
|
9
|
-
extend Legion::Extensions::Core if Legion::Extensions.const_defined?(:Core)
|
|
9
|
+
extend Legion::Extensions::Core if Legion::Extensions.const_defined?(:Core, false)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
remove_const(:Llm) if const_defined?(:Llm, false)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lex-llm-gateway
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.13
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Esity
|
|
@@ -149,6 +149,20 @@ dependencies:
|
|
|
149
149
|
- - ">="
|
|
150
150
|
- !ruby/object:Gem::Version
|
|
151
151
|
version: '0'
|
|
152
|
+
- !ruby/object:Gem::Dependency
|
|
153
|
+
name: rubocop-legion
|
|
154
|
+
requirement: !ruby/object:Gem::Requirement
|
|
155
|
+
requirements:
|
|
156
|
+
- - ">="
|
|
157
|
+
- !ruby/object:Gem::Version
|
|
158
|
+
version: '0'
|
|
159
|
+
type: :development
|
|
160
|
+
prerelease: false
|
|
161
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
162
|
+
requirements:
|
|
163
|
+
- - ">="
|
|
164
|
+
- !ruby/object:Gem::Version
|
|
165
|
+
version: '0'
|
|
152
166
|
- !ruby/object:Gem::Dependency
|
|
153
167
|
name: rubocop-rspec
|
|
154
168
|
requirement: !ruby/object:Gem::Requirement
|