Class: Ace::LLM::Molecules::FormatHandlers::JSON

Inherits:
Base
  • Object
show all
Defined in:
lib/ace/llm/molecules/format_handlers.rb

Overview

JSON format handler

Instance Method Summary collapse

Methods inherited from Base

#build_cost_summary, #format_cost, #generate_summary

Instance Method Details

#format(response, **_options) ⇒ String

Format response as JSON with full metadata

Parameters:

  • response (Hash)

    Response with :text and normalized metadata

  • options (Hash)

    Additional formatting options

Returns:

  • (String)

    JSON formatted output



113
114
115
116
117
118
119
120
121
122
# File 'lib/ace/llm/molecules/format_handlers.rb', line 113

def format(response, **_options)
  validate_response(response)

  output = {
    text: response[:text],
    metadata: response[:metadata] || {}
  }

  ::JSON.pretty_generate(output)
end