Class: PromptBuilder::Serializers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt_builder/serializers/base.rb

Overview

Base class for format serializers. Provides a common interface for exporting sessions and parsing responses in alternate API formats.

Class Method Summary collapse

Class Method Details

.parse_response(hash, headers: nil) ⇒ Response

Parse a response from the target format into an PromptBuilder::Response. Format classes that define a nested Response parser delegate to it.

Parameters:

  • hash (Hash)

    the response hash in the target format

  • headers (Hash, #each, nil) (defaults to: nil)

    the HTTP response headers, for formats that return response metadata in headers rather than in the body

Returns:

Raises:



26
27
28
29
30
31
32
33
# File 'lib/prompt_builder/serializers/base.rb', line 26

def parse_response(hash, headers: nil)
  if const_defined?(:Response, false)
    return const_get(:Response, false).parse_response(hash, headers: headers)
  end

  check_error_response!(hash)
  deserialize_response(hash)
end

.request_payload(session) ⇒ Hash

Export a session to the target format's request payload.

Parameters:

  • session (Session)

    the session to export

Returns:

  • (Hash)

    the serialized request payload



13
14
15
# File 'lib/prompt_builder/serializers/base.rb', line 13

def request_payload(session)
  serialize_request(session)
end