Class: Assistant::GammaToolBuilder::CreateTool

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
app/services/assistant/gamma_tool_builder.rb

Overview

Create a new Gamma presentation, document, social post, or webpage using AI.

Instance Method Summary collapse

Instance Method Details

#execute(input_text:, format: 'presentation', text_mode: 'generate', theme_id: nil, num_cards: nil, card_split: 'auto', additional_instructions: nil, tone: nil, audience: nil, text_amount: nil, image_source: nil, dimensions: nil, export_as: nil, language: nil, **_) ⇒ String

Returns JSON result payload.

Parameters:

  • input_text (String)

    the content to generate from

  • format (String) (defaults to: 'presentation')

    output format (presentation, document, social)

  • text_mode (String) (defaults to: 'generate')

    text generation mode (e.g. generate)

  • theme_id (String, nil) (defaults to: nil)

    Gamma theme id to apply

  • num_cards (Integer, nil) (defaults to: nil)

    number of cards/slides

  • card_split (String) (defaults to: 'auto')

    card splitting mode

  • additional_instructions (String, nil) (defaults to: nil)

    extra generation instructions

  • tone (String, nil) (defaults to: nil)

    text tone

  • audience (String, nil) (defaults to: nil)

    target audience

  • text_amount (String, nil) (defaults to: nil)

    amount of text per card

  • image_source (String, nil) (defaults to: nil)

    image source preference

  • dimensions (String, nil) (defaults to: nil)

    card/slide aspect ratio

  • export_as (String, nil) (defaults to: nil)

    request a download export (pdf or pptx)

  • language (String, nil) (defaults to: nil)

    language code for generated text

  • _ (Hash)

    a customizable set of options

Options Hash (**_):

  • :ignored (Object)

    extra keyword arguments are accepted and ignored

Returns:

  • (String)

    JSON result payload



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'app/services/assistant/gamma_tool_builder.rb', line 165

def execute(input_text:, format: 'presentation', text_mode: 'generate',
            theme_id: nil, num_cards: nil, card_split: 'auto',
            additional_instructions: nil, tone: nil, audience: nil,
            text_amount: nil, image_source: nil, dimensions: nil,
            export_as: nil, language: nil, **_)
  text_options = {}
  text_options[:amount]   = text_amount if text_amount.present?
  text_options[:tone]     = tone        if tone.present?
  text_options[:audience] = audience    if audience.present?
  text_options[:language] = language    if language.present?

  image_options = {}
  image_options[:source] = image_source if image_source.present?

  card_options = {}
  card_options[:dimensions] = dimensions if dimensions.present?

  client = GammaClient.new
  result = client.create_and_wait(
    input_text:               input_text,
    text_mode:                text_mode,
    format:                   format,
    theme_id:                 theme_id,
    num_cards:                num_cards,
    card_split:               card_split,
    additional_instructions:  additional_instructions,
    export_as:                export_as,
    text_options:             text_options.presence,
    image_options:            image_options.presence,
    card_options:             card_options.presence
  )

  if result.success?
    data = result.data
    response = {
      success:   true,
      gamma_url: data[:gamma_url],
      format:    format,
      message:   "Your #{format} is ready! View and edit it here: #{data[:gamma_url]}"
    }
    response[:export_url] = data[:export_url] if data[:export_url].present?
    response[:credits]    = data[:credits]    if data[:credits].present?
    response.to_json
  else
    { success: false, error: result.error }.to_json
  end
rescue StandardError => e
  Rails.logger.error("[GammaToolBuilder] gamma_create failed: #{e.message}")
  { success: false, error: "Gamma creation failed: #{e.message}" }.to_json
end

#nameObject



147
# File 'app/services/assistant/gamma_tool_builder.rb', line 147

def name = 'gamma_create'