Class: Ollama::Handlers::DumpJSON

Inherits:
Object
  • Object
show all
Includes:
Concern
Defined in:
lib/ollama/handlers/dump_json.rb

Overview

A handler that outputs JSON representations of responses to the specified output stream.

This class is designed to serialize and display API responses in JSON format, making it easy to inspect the raw data returned by Ollama commands. It implements the standard handler interface and can be used with any command that supports response processing.

Examples:

Using the DumpJSON handler to output response data as JSON

ollama.generate(model: 'llama3.1', prompt: 'Hello World', &DumpJSON)

Instance Attribute Summary

Attributes included from Concern

#output, #result

Instance Method Summary collapse

Methods included from Concern

#initialize, #to_proc

Instance Method Details

#call(response) ⇒ self

The call method processes a response by outputting its JSON representation.

This method takes a response object and serializes it into a formatted JSON string, which is then written to the specified output stream. It is designed to provide detailed inspection of API responses in a human-readable format.

Parameters:

  • response (Ollama::Response)

    the response object to be serialized and output

Returns:

  • (self)

    returns the handler instance itself after processing the response



24
25
26
27
# File 'lib/ollama/handlers/dump_json.rb', line 24

def call(response)
  @output.puts JSON::pretty_generate(response, allow_nan: true, max_nesting: false)
  self
end