5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/open_ai/dalle.rb', line 5
def dalle(prompt = nil)
return unless allowed_chat?
attempt(3) do
puts "Received a /dalle command"
prompt ||= @replies_to&.text || @text_without_command
send_chat_action(:upload_photo)
puts "Sending request"
response = open_ai.images.generate(parameters: { prompt: prompt })
send_chat_action(:upload_photo)
url = response.dig("data", 0, "url")
puts "DALL-E finished, sending photo to Telegram..."
if response["error"]
reply_code(response)
else
send_photo(url, reply_to_message_id: @msg.message_id)
end
end
end
|