Class: DSPy::LM::Strategies::AnthropicExtractionStrategy

Inherits:
BaseStrategy
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dspy/lm/strategies/anthropic_extraction_strategy.rb

Overview

Strategy for using Anthropic’s enhanced JSON extraction patterns

Instance Method Summary collapse

Methods inherited from BaseStrategy

#handle_error, #initialize

Constructor Details

This class inherits a constructor from DSPy::LM::Strategies::BaseStrategy

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/dspy/lm/strategies/anthropic_extraction_strategy.rb', line 13

def available?
  adapter.is_a?(DSPy::LM::AnthropicAdapter)
end

#extract_json(response) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/dspy/lm/strategies/anthropic_extraction_strategy.rb', line 34

def extract_json(response)
  # Use Anthropic's specialized extraction method if available
  if adapter.respond_to?(:extract_json_from_response)
    adapter.extract_json_from_response(response.content)
  else
    # Fallback to basic extraction
    extract_json_fallback(response.content)
  end
end

#nameObject



23
24
25
# File 'lib/dspy/lm/strategies/anthropic_extraction_strategy.rb', line 23

def name
  "anthropic_extraction"
end

#prepare_request(messages, request_params) ⇒ Object



28
29
30
31
# File 'lib/dspy/lm/strategies/anthropic_extraction_strategy.rb', line 28

def prepare_request(messages, request_params)
  # Anthropic adapter already handles JSON optimization in prepare_messages_for_json
  # No additional preparation needed here
end

#priorityObject



18
19
20
# File 'lib/dspy/lm/strategies/anthropic_extraction_strategy.rb', line 18

def priority
  90 # High priority - Anthropic's extraction is very reliable
end