149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
|
# File 'app/services/assistant/gamma_tool_builder.rb', line 149
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
|