Class: RubyAmazonBedrock::PayloadBuilders::StabilityAi::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/bedrock_runtime/payload_builders/stability_ai/base.rb

Overview

Builds and returns a payload hash suitable for the Stability AI model processing. This method constructs a payload with specific parameters like ‘model_id`, `content_type`, `accept`, and a `body` that includes various AI-related settings.

Returns:

  • (Hash)

    The constructed payload containing AI model parameters and settings.

Direct Known Subclasses

StableDiffusionXlV0, StableDiffusionXlV1

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from RubyAmazonBedrock::PayloadBuilders::Base

Instance Method Details

#buildHash

Constructs and returns a structured payload for processing by an AI model. This method assembles data in a format suitable for tasks requiring configurable prompts, such as text or image generation, with control over creativity and randomness.

Returns:

  • (Hash)

    A hash containing the necessary details for the AI model to process:

    • :model_id [String] Identifier for the AI model to which the request is directed.

    • :content_type [String] Specifies the content type of the payload, typically set to ‘application/json’.

    • :accept [String] Indicates the MIME type that the response should conform to.

    • :body [String] A JSON string including:

      • :text_prompts [Array<Hash>] An array of hashes, each containing a ‘text’ key with a string value representing a prompt.

      • :cfg_scale [Integer] A parameter influencing the level of control versus freedom in content generation.

      • :seed [Integer] Seed value for deterministic outputs, enabling reproducibility of results.

      • :steps [Integer] Specifies the number of steps the model should take in generating the output.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bedrock_runtime/payload_builders/stability_ai/base.rb', line 26

def build
  {
    model_id: model_id,
    content_type: 'application/json',
    accept: '*/*',
    body: {
      text_prompts: [
        { text: @prompt }
      ],
      cfg_scale: parameters[:cfg_scale],
      seed: parameters[:seed],
      steps: parameters[:steps]
    }.to_json
  }
end

#model_idObject



42
43
44
# File 'lib/bedrock_runtime/payload_builders/stability_ai/base.rb', line 42

def model_id
  # noop
end

#parametersObject



46
47
48
49
50
51
52
# File 'lib/bedrock_runtime/payload_builders/stability_ai/base.rb', line 46

def parameters
  {
    cfg_scale: @options[:cfg_scale] || 10,
    seed: @options[:seed] || 0,
    steps: @options[:steps] || 30
  }
end

#typeObject



54
55
56
# File 'lib/bedrock_runtime/payload_builders/stability_ai/base.rb', line 54

def type
  :image
end