Module: LittleGhost::StructuredOutput
- Defined in:
- lib/little_ghost/structured_output.rb
Overview
:nodoc: all
Defined Under Namespace
Classes: ProviderStrategy, Strategy, ToolStrategy
Constant Summary collapse
- STRATEGIES =
%i[auto provider tool].freeze
Class Method Summary collapse
- .resolve(configuration, model:, ordinary_tools:) ⇒ Object
- .validate_tool_collision!(strategy, ordinary_tools) ⇒ Object
Class Method Details
.resolve(configuration, model:, ordinary_tools:) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/little_ghost/structured_output.rb', line 55 def resolve(configuration, model:, ordinary_tools:) return unless configuration requested = configuration.fetch(:strategy, :auto).to_sym capabilities = if model.respond_to?(:capabilities) model.capabilities else ModelCapabilities.legacy end strategy = case requested when :auto then automatic_strategy(model, capabilities, ordinary_tools) when :provider validate_explicit_provider!(model, capabilities) ProviderStrategy when :tool validate_explicit_tool!(model, capabilities) ToolStrategy else raise ConfigurationError, "Unknown structured output strategy: #{requested}" end resolved = strategy.new(configuration) validate_tool_collision!(resolved, ordinary_tools) resolved end |
.validate_tool_collision!(strategy, ordinary_tools) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/little_ghost/structured_output.rb', line 80 def validate_tool_collision!(strategy, ordinary_tools) return unless strategy.tool? return unless ordinary_tools.any? { |tool| tool.fetch(:name).to_s == strategy.schema_name } raise ConfigurationError, "Structured result tool name collides with an agent tool: #{strategy.schema_name}" end |