legion-llm 0.6.26 → 0.6.27
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 +5 -0
- data/CLAUDE.md +2 -2
- data/lib/legion/llm/providers.rb +61 -7
- 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: b85e3ef4ae750eb9aa512fcc0ce3b2de89fc13828dcdcef7ef558859a422e8f1
|
|
4
|
+
data.tar.gz: 4617e27eec5e4292146338dc4a593e4e0762838b6c1c24c925fedca472775aae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c93930484d5c716d2429490ca192bd9e758fd291aa81942a43309e8ab72c9accb1e472241a47255c24e590320748b54f8e71b678b4dc204e78ac975a1b0b7188
|
|
7
|
+
data.tar.gz: 62453e4f583641b9c2e4e714f120def689548795baa7609844c8d8069f5b577ee644025ac18b324c2ff029a7163b82bde78426996c5bb6e062573aaa0d74c170
|
data/CHANGELOG.md
CHANGED
data/CLAUDE.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Core LegionIO gem providing LLM capabilities to all extensions. Wraps ruby_llm to provide a consistent interface for chat, embeddings, tool use, and agents across multiple providers (Bedrock, Anthropic, OpenAI, Gemini, Ollama). Includes a dynamic weighted routing engine that dispatches requests across local, fleet, and cloud tiers based on caller intent, priority rules, time schedules, cost multipliers, and real-time provider health.
|
|
9
9
|
|
|
10
10
|
**GitHub**: https://github.com/LegionIO/legion-llm
|
|
11
|
-
**Version**: 0.6.
|
|
11
|
+
**Version**: 0.6.27
|
|
12
12
|
**License**: Apache-2.0
|
|
13
13
|
|
|
14
14
|
## Architecture
|
|
@@ -504,7 +504,7 @@ The legacy `vault_path` per-provider setting was removed in v0.3.1.
|
|
|
504
504
|
Tests run without the full LegionIO stack. `spec/spec_helper.rb` stubs `Legion::Logging` and `Legion::Settings` with in-memory implementations. Each test resets settings to defaults via `before(:each)`.
|
|
505
505
|
|
|
506
506
|
```bash
|
|
507
|
-
bundle exec rspec #
|
|
507
|
+
bundle exec rspec # 1661 examples, 0 failures
|
|
508
508
|
bundle exec rubocop # 0 offenses
|
|
509
509
|
```
|
|
510
510
|
|
data/lib/legion/llm/providers.rb
CHANGED
|
@@ -28,6 +28,9 @@ module Legion
|
|
|
28
28
|
else
|
|
29
29
|
config[:api_key]
|
|
30
30
|
end
|
|
31
|
+
|
|
32
|
+
has_creds ||= broker_has_credential?(provider) unless has_creds
|
|
33
|
+
|
|
31
34
|
next unless has_creds
|
|
32
35
|
|
|
33
36
|
config[:enabled] = true
|
|
@@ -70,6 +73,19 @@ module Legion
|
|
|
70
73
|
def configure_bedrock(config)
|
|
71
74
|
has_sigv4 = config[:api_key] && config[:secret_key]
|
|
72
75
|
has_bearer = config[:bearer_token]
|
|
76
|
+
|
|
77
|
+
unless has_sigv4 || has_bearer
|
|
78
|
+
broker_creds = resolve_broker_aws_credentials
|
|
79
|
+
if broker_creds
|
|
80
|
+
has_sigv4 = true
|
|
81
|
+
config = config.merge(
|
|
82
|
+
api_key: broker_creds.access_key_id,
|
|
83
|
+
secret_key: broker_creds.secret_access_key,
|
|
84
|
+
session_token: (broker_creds.session_token if broker_creds.respond_to?(:session_token))
|
|
85
|
+
)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
73
89
|
return unless has_sigv4 || has_bearer
|
|
74
90
|
|
|
75
91
|
require 'legion/llm/bedrock_bearer_auth' if has_bearer
|
|
@@ -90,35 +106,38 @@ module Legion
|
|
|
90
106
|
end
|
|
91
107
|
|
|
92
108
|
def configure_anthropic(config)
|
|
93
|
-
|
|
109
|
+
api_key = resolve_broker_credential(:anthropic) || config[:api_key]
|
|
110
|
+
return unless api_key
|
|
94
111
|
|
|
95
112
|
RubyLLM.configure do |c|
|
|
96
|
-
c.anthropic_api_key =
|
|
113
|
+
c.anthropic_api_key = api_key
|
|
97
114
|
end
|
|
98
115
|
log.info 'Configured Anthropic provider'
|
|
99
116
|
end
|
|
100
117
|
|
|
101
118
|
def configure_openai(config)
|
|
102
|
-
|
|
119
|
+
api_key = resolve_broker_credential(:openai) || config[:api_key]
|
|
120
|
+
return unless api_key
|
|
103
121
|
|
|
104
122
|
RubyLLM.configure do |c|
|
|
105
|
-
c.openai_api_key =
|
|
123
|
+
c.openai_api_key = api_key
|
|
106
124
|
end
|
|
107
125
|
log.info 'Configured OpenAI provider'
|
|
108
126
|
end
|
|
109
127
|
|
|
110
128
|
def configure_gemini(config)
|
|
111
|
-
|
|
129
|
+
api_key = resolve_broker_credential(:gemini) || config[:api_key]
|
|
130
|
+
return unless api_key
|
|
112
131
|
|
|
113
132
|
RubyLLM.configure do |c|
|
|
114
|
-
c.gemini_api_key =
|
|
133
|
+
c.gemini_api_key = api_key
|
|
115
134
|
end
|
|
116
135
|
log.info 'Configured Gemini provider'
|
|
117
136
|
end
|
|
118
137
|
|
|
119
138
|
def configure_azure(config)
|
|
120
139
|
api_base = config[:api_base]
|
|
121
|
-
api_key = config[:api_key]
|
|
140
|
+
api_key = resolve_broker_credential(:azure) || config[:api_key]
|
|
122
141
|
auth_token = config[:auth_token]
|
|
123
142
|
return unless api_base && (api_key || auth_token)
|
|
124
143
|
|
|
@@ -197,6 +216,41 @@ module Legion
|
|
|
197
216
|
handle_exception(e, level: :debug, operation: 'llm.providers.verify_single_provider', provider: provider, model: model)
|
|
198
217
|
# config[:enabled] = false
|
|
199
218
|
end
|
|
219
|
+
|
|
220
|
+
def resolve_broker_credential(provider_name)
|
|
221
|
+
return nil unless defined?(Legion::Identity::Broker)
|
|
222
|
+
|
|
223
|
+
Legion::Identity::Broker.token_for(provider_name)
|
|
224
|
+
rescue StandardError => e
|
|
225
|
+
handle_exception(e, level: :debug, operation: "llm.providers.broker_resolve.#{provider_name}")
|
|
226
|
+
nil
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def resolve_broker_aws_credentials
|
|
230
|
+
return nil unless defined?(Legion::Identity::Broker)
|
|
231
|
+
|
|
232
|
+
renewer = Legion::Identity::Broker.renewer_for(:aws)
|
|
233
|
+
return renewer.provider.current_credentials if renewer&.provider.respond_to?(:current_credentials)
|
|
234
|
+
|
|
235
|
+
nil
|
|
236
|
+
rescue StandardError => e
|
|
237
|
+
handle_exception(e, level: :debug, operation: 'llm.providers.broker_resolve.aws')
|
|
238
|
+
nil
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def broker_has_credential?(provider)
|
|
242
|
+
return false unless defined?(Legion::Identity::Broker)
|
|
243
|
+
|
|
244
|
+
case provider
|
|
245
|
+
when :bedrock
|
|
246
|
+
renewer = Legion::Identity::Broker.renewer_for(:aws)
|
|
247
|
+
renewer&.provider.respond_to?(:current_credentials) && !renewer.provider.current_credentials.nil?
|
|
248
|
+
else
|
|
249
|
+
!Legion::Identity::Broker.token_for(provider).nil?
|
|
250
|
+
end
|
|
251
|
+
rescue StandardError
|
|
252
|
+
false
|
|
253
|
+
end
|
|
200
254
|
end
|
|
201
255
|
end
|
|
202
256
|
end
|
data/lib/legion/llm/version.rb
CHANGED