legion-llm 0.3.4 → 0.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd0b530095616abc383dcd06473a6c435753f021458c76c981da1d4e98583a5f
4
- data.tar.gz: 21d8645355c14d591891c3484ca90957e99b0cb376b115eb61dd61f3e0721800
3
+ metadata.gz: e3e10dfcd60fe722290bec30017671fb261f3baf151b416c82defb082d4445f4
4
+ data.tar.gz: 0c0b062649f8ede281fada374681d551d437126a2efa0e604a069610e14b7069
5
5
  SHA512:
6
- metadata.gz: 53f3b6bd09f86625986e6f9d5c53f665e000e71d78dc5db36d599f1b5e5d7267d40ca1a2fe1e9f2b48cc54fb7ab6d272108869a02b327ff9669f978b83280e71
7
- data.tar.gz: 381d707e3bdb75a1cf87d82404dc842140f98fa4bb5091e5a837685235327684b800de977efcd24857bb0ab8ab5bc75d42fdc22364aa4b024d6adf8f27cdab65
6
+ metadata.gz: eeb2cd074c2eb1c3b63ccb7644adbcf7cac6bab62f8d5cc966e318b2185267ab73fae920726b83e1f72cbf8753ba1245ab84ae914baa092aebdbef08e0548cd3
7
+ data.tar.gz: ccc52360f869421100f0bbda503570168f2f7eb86c5fda9069e6ee29bdaa4c60553d202a1ad2e2109e98ba451b9abf9c00dc8210b50cf5d0a925192cada2ab9d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Legion LLM Changelog
2
2
 
3
+ ## [0.3.5] - 2026-03-18
4
+
5
+ ### Added
6
+ - Gateway integration: `chat`, `embed`, `structured` delegate to `lex-llm-gateway` when loaded for automatic metering and fleet dispatch
7
+ - `chat_direct`, `embed_direct`, `structured_direct` methods bypass gateway (used by gateway runners to avoid recursion)
8
+ - Gateway integration spec (8 examples)
9
+
3
10
  ## [0.3.4] - 2026-03-18
4
11
 
5
12
  ### Added
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
+ gem 'lex-llm-gateway', path: '../extensions-core/lex-llm-gateway' if File.directory?('../extensions-core/lex-llm-gateway')
8
+
7
9
  group :test do
8
10
  gem 'rake'
9
11
  gem 'rspec'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Legion
4
4
  module LLM
5
- VERSION = '0.3.4'
5
+ VERSION = '0.3.5'
6
6
  end
7
7
  end
data/lib/legion/llm.rb CHANGED
@@ -9,6 +9,12 @@ require 'legion/llm/compressor'
9
9
  require 'legion/llm/quality_checker'
10
10
  require 'legion/llm/escalation_history'
11
11
 
12
+ begin
13
+ require 'legion/extensions/llm/gateway'
14
+ rescue LoadError
15
+ nil
16
+ end
17
+
12
18
  module Legion
13
19
  module LLM
14
20
  class EscalationExhausted < StandardError; end
@@ -50,20 +56,24 @@ module Legion
50
56
  end
51
57
  end
52
58
 
53
- # Create a new chat session
54
- # @param model [String] model ID (e.g., "us.anthropic.claude-sonnet-4-6-v1")
55
- # @param provider [Symbol] provider slug (e.g., :bedrock, :anthropic)
56
- # @param intent [Hash, nil] routing intent (capability, privacy, etc.)
57
- # @param tier [Symbol, nil] explicit tier override — skips rule matching
58
- # @param escalate [Boolean, nil] enable escalation retry loop (nil = auto from settings)
59
- # @param max_escalations [Integer, nil] max escalation attempts override
60
- # @param quality_check [Proc, nil] custom quality check callable
61
- # @param message [String, nil] message to send (required for escalation)
62
- # @param kwargs [Hash] additional options passed to RubyLLM.chat
63
- # @return [RubyLLM::Chat]
64
- # TODO: fleet tier dispatch via Transport (Phase 3)
59
+ # Create a new chat session — delegates to lex-llm-gateway when available
60
+ # for automatic metering and fleet dispatch
65
61
  def chat(model: nil, provider: nil, intent: nil, tier: nil, escalate: nil,
66
62
  max_escalations: nil, quality_check: nil, message: nil, **)
63
+ if gateway_loaded? && message
64
+ return gateway_chat(model: model, provider: provider, intent: intent,
65
+ tier: tier, message: message, escalate: escalate,
66
+ max_escalations: max_escalations, quality_check: quality_check, **)
67
+ end
68
+
69
+ chat_direct(model: model, provider: provider, intent: intent, tier: tier,
70
+ escalate: escalate, max_escalations: max_escalations,
71
+ quality_check: quality_check, message: message, **)
72
+ end
73
+
74
+ # Direct chat bypassing gateway — used by gateway runners to avoid recursion
75
+ def chat_direct(model: nil, provider: nil, intent: nil, tier: nil, escalate: nil,
76
+ max_escalations: nil, quality_check: nil, message: nil, **)
67
77
  escalate = escalation_enabled? if escalate.nil?
68
78
 
69
79
  if escalate && message
@@ -77,11 +87,15 @@ module Legion
77
87
  end
78
88
  end
79
89
 
80
- # Generate embeddings via Embeddings module
81
- # @param text [String, Array<String>] text to embed
82
- # @param model [String] embedding model ID
83
- # @return [Hash] { vector:, model:, dimensions:, tokens: }
90
+ # Generate embeddings delegates to gateway when available
84
91
  def embed(text, **)
92
+ return Legion::Extensions::LLM::Gateway::Runners::Inference.embed(text: text, **) if gateway_loaded?
93
+
94
+ embed_direct(text, **)
95
+ end
96
+
97
+ # Direct embed bypassing gateway
98
+ def embed_direct(text, **)
85
99
  require 'legion/llm/embeddings'
86
100
  Embeddings.generate(text: text, **)
87
101
  end
@@ -94,11 +108,19 @@ module Legion
94
108
  Embeddings.generate_batch(texts: texts, **)
95
109
  end
96
110
 
97
- # Generate structured JSON output from LLM
98
- # @param messages [Array<Hash>] conversation messages
99
- # @param schema [Hash] JSON schema to enforce
100
- # @return [Hash] { data:, raw:, model:, valid: }
111
+ # Generate structured JSON output delegates to gateway when available
101
112
  def structured(messages:, schema:, **)
113
+ if gateway_loaded?
114
+ return Legion::Extensions::LLM::Gateway::Runners::Inference.structured(
115
+ messages: messages, schema: schema, **
116
+ )
117
+ end
118
+
119
+ structured_direct(messages: messages, schema: schema, **)
120
+ end
121
+
122
+ # Direct structured bypassing gateway
123
+ def structured_direct(messages:, schema:, **)
102
124
  require 'legion/llm/structured_output'
103
125
  StructuredOutput.generate(messages: messages, schema: schema, **)
104
126
  end
@@ -113,6 +135,14 @@ module Legion
113
135
 
114
136
  private
115
137
 
138
+ def gateway_loaded?
139
+ defined?(Legion::Extensions::LLM::Gateway::Runners::Inference)
140
+ end
141
+
142
+ def gateway_chat(**)
143
+ Legion::Extensions::LLM::Gateway::Runners::Inference.chat(**)
144
+ end
145
+
116
146
  def chat_single(model:, provider:, intent:, tier:, **kwargs)
117
147
  if (intent || tier) && Router.routing_enabled?
118
148
  resolution = Router.resolve(intent: intent, tier: tier, model: model, provider: provider)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-llm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity