Module: Legion::Extensions::Llm::Responses::ThinkingExtractor

Defined in:
lib/legion/extensions/llm/responses/thinking_extractor.rb

Overview

Separates provider thinking markup from caller-visible text.

Defined Under Namespace

Classes: Extraction

Constant Summary collapse

THINK_OPEN =
'<think>'
THINK_CLOSE =
'</think>'
THINK_PATTERN =
%r{<think>(.*?)</think>}m
THINKING_METADATA_KEYS =
%i[
  reasoning_content reasoning thinking thinking_text thinking_signature reasoning_signature thought_signature
].freeze
RAW_METADATA_KEYS =
%i[
  raw raw_response response_body provider_body provider_response
].freeze

Class Method Summary collapse

Class Method Details

.extract(content, metadata: {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/legion/extensions/llm/responses/thinking_extractor.rb', line 23

def extract(content, metadata: {})
   = ()
  content, extracted_thinking = extract_from_content(content)
   = ()
   = ()

  Extraction.new(
    content: content,
    thinking: compact_thinking([, extracted_thinking]),
    signature: ,
    metadata: ()
  )
end