lex-llm-ollama 0.2.22 → 0.2.24

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: 9105e1f109fd5c83078224391ceb669ea321943a2075d85d5a77cf48b73d16e7
4
- data.tar.gz: 1bd18adb284f8b8fa5c12e0049f310973989efb5a20070dcbb172754f64f941b
3
+ metadata.gz: fe9668a684e60453a26c187e8e5dddfa15835ce18b4b6d627cb32bd17be1fef8
4
+ data.tar.gz: a858a4b969945856c39ba64397067ef1f7c8c776de47b669a1e7b7c8a6704abf
5
5
  SHA512:
6
- metadata.gz: 175570e4fdf0574998741b731718675d643f03c1163183bd41a28a7c90151c71919150060c9d87ff27840f0bcf5203b90dba85e81680f1ec74d3f494b22c85f0
7
- data.tar.gz: 9ebb03d6cdf2078303f8ac674cfe939a73770a0ce7b721e86c6daaeb63169c0039dfca9e7063138e83896322820939b203f68265da9a2125066ee4e05ecefcd4
6
+ metadata.gz: 52b01a8dfa63402561d7e5e9b09ed09d92ac7d01ef9dfa0fa04e15463399da4168f6948f0f23e5d1807d6b2f09f04d103079ff35959077d717bbb2f2889fa7aa
7
+ data.tar.gz: 3fccbb4c70de27e38f87d4809f628819f33ff9ce4a3640b7cf29c67deda5b01ed394797b7c1ddb438f980d680d2bd0c8768b4388a2e57ff8e1d62f1cc4ccc5b5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.24] - 2026-07-24
4
+
5
+ ### Fixed
6
+ - **Translator propagates `done_reason` and usage through content chunks.** When ollama sends `done: true` on a chunk that also has content, the stop_reason and usage were previously lost. Now extracts them before branching and passes through to whatever chunk type is emitted.
7
+
8
+ ## [0.2.23] - 2026-07-05
9
+
10
+ ### Changed
11
+ - Stop_reason mapping now uses the shared `Legion::Extensions::Llm::StopReasonMapping` mixin from lex-llm (>= 0.6.9) instead of a local `OLLAMA_STOP_REASON_MAP` (a copy of the same drifting 3-entry map vLLM carried). The shared vocabulary maps `tool_calls`/`tool_use`/`function_call` to `:tool_use` (plus `stop`/`end_turn`/`eos`, `length`/`max_tokens`, `stop_sequence`, `content_filter`) and is inherited by every provider so it no longer drifts per gem. Ollama's `done_reason`-to-stop_reason resolution is unchanged in behavior.
12
+
3
13
  ## [0.2.22] - 2026-06-20
4
14
 
5
15
  ### Fixed
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency 'legion-logging', '>= 1.3.2'
28
28
  spec.add_dependency 'legion-settings', '>= 1.3.14'
29
29
  spec.add_dependency 'legion-transport', '>= 1.4.14'
30
- spec.add_dependency 'lex-llm', '>= 0.6.0'
30
+ spec.add_dependency 'lex-llm', '>= 0.6.9'
31
31
  end
@@ -21,13 +21,10 @@ module Legion
21
21
  # - assistant_prefill: false — Ollama does not support assistant prefill.
22
22
  class Translator
23
23
  include Legion::Logging::Helper
24
+ # Shared stop_reason vocabulary. Ollama returns structured tool_calls and
25
+ # OpenAI-style done_reason strings; inherits the common map.
26
+ include Legion::Extensions::Llm::StopReasonMapping
24
27
 
25
- # Ollama-specific stop_reason mapping (done_reason field).
26
- OLLAMA_STOP_REASON_MAP = {
27
- 'stop' => :end_turn,
28
- 'tool_use' => :tool_use,
29
- 'length' => :max_tokens
30
- }.freeze
31
28
  FALLBACK_STOP_REASON = :end_turn
32
29
 
33
30
  # G18 parameter mapping: canonical params -> Ollama options keys.
@@ -392,7 +389,7 @@ module Legion
392
389
 
393
390
  def map_stop_reason(done_reason, done = nil)
394
391
  if done_reason
395
- OLLAMA_STOP_REASON_MAP.fetch(done_reason.to_s, FALLBACK_STOP_REASON)
392
+ stop_reason_lookup(done_reason) || FALLBACK_STOP_REASON
396
393
  elsif done
397
394
  FALLBACK_STOP_REASON
398
395
  end
@@ -420,16 +417,24 @@ module Legion
420
417
  done_reason = data[:done_reason] || data['done_reason']
421
418
  request_id = data[:request_id] || data['request_id'] || data[:id] || data['id']
422
419
 
420
+ chunk_stop_reason = done_reason ? map_stop_reason(done_reason, done) : nil
421
+ chunk_usage = done ? build_chunk_usage(data) : nil
422
+
423
423
  # Tool call delta
424
424
  tool_calls = message[:tool_calls] || message['tool_calls']
425
- return build_tool_call_chunk(tool_calls, request_id) unless Array(tool_calls).empty?
425
+ unless Array(tool_calls).empty?
426
+ return build_tool_call_chunk(tool_calls, request_id,
427
+ stop_reason: chunk_stop_reason, usage: chunk_usage)
428
+ end
426
429
 
427
430
  # Thinking delta
428
431
  thinking_content = message[:thinking] || message['thinking']
429
432
  unless thinking_content.to_s.empty?
430
433
  return Canonical::Chunk.thinking_delta(
431
434
  delta: thinking_content.to_s,
432
- request_id: request_id
435
+ request_id: request_id,
436
+ stop_reason: chunk_stop_reason,
437
+ usage: chunk_usage
433
438
  )
434
439
  end
435
440
 
@@ -438,7 +443,9 @@ module Legion
438
443
  unless content.to_s.empty?
439
444
  return Canonical::Chunk.text_delta(
440
445
  delta: content.to_s,
441
- request_id: request_id
446
+ request_id: request_id,
447
+ stop_reason: chunk_stop_reason,
448
+ usage: chunk_usage
442
449
  )
443
450
  end
444
451
 
@@ -448,20 +455,22 @@ module Legion
448
455
  nil
449
456
  end
450
457
 
451
- def build_done_chunk(data, done_reason, request_id)
452
- usage = Canonical::Usage.from_hash({
453
- input_tokens: data[:prompt_eval_count] || data['prompt_eval_count'],
454
- output_tokens: data[:eval_count] || data['eval_count']
455
- })
458
+ def build_chunk_usage(data)
459
+ Canonical::Usage.from_hash({
460
+ input_tokens: data[:prompt_eval_count] || data['prompt_eval_count'],
461
+ output_tokens: data[:eval_count] || data['eval_count']
462
+ })
463
+ end
456
464
 
465
+ def build_done_chunk(data, done_reason, request_id)
457
466
  Canonical::Chunk.done(
458
467
  request_id: request_id,
459
- usage: usage,
468
+ usage: build_chunk_usage(data),
460
469
  stop_reason: map_stop_reason(done_reason, true)
461
470
  )
462
471
  end
463
472
 
464
- def build_tool_call_chunk(tool_calls, request_id)
473
+ def build_tool_call_chunk(tool_calls, request_id, stop_reason: nil, usage: nil)
465
474
  first_call = tool_calls.first
466
475
  first_call = first_call.transform_keys(&:to_sym) if first_call.is_a?(Hash)
467
476
  function = first_call[:function] || first_call['function'] || {}
@@ -476,7 +485,9 @@ module Legion
476
485
 
477
486
  Canonical::Chunk.tool_call_delta(
478
487
  tool_call: tc,
479
- request_id: request_id
488
+ request_id: request_id,
489
+ stop_reason: stop_reason,
490
+ usage: usage
480
491
  )
481
492
  end
482
493
 
@@ -4,7 +4,7 @@ module Legion
4
4
  module Extensions
5
5
  module Llm
6
6
  module Ollama
7
- VERSION = '0.2.22'
7
+ VERSION = '0.2.24'
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-llm-ollama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.22
4
+ version: 0.2.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - LegionIO
@@ -71,14 +71,14 @@ dependencies:
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 0.6.0
74
+ version: 0.6.9
75
75
  type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 0.6.0
81
+ version: 0.6.9
82
82
  description: Ollama provider integration for the LegionIO LLM routing framework.
83
83
  email:
84
84
  - matthewdiverson@gmail.com