Module: AiHelper
- Defined in:
- app/helpers/ai_helper.rb
Instance Method Summary collapse
-
#ai_analyze_image(image, prompt, **options) ⇒ Object
Multimodal analysis.
-
#ai_analyze_image_with_context(image, prompt, user_context: {}, window_context: {}, image_context: {}, **options) ⇒ Object
Context-aware AI operations.
- #ai_analyze_video(video, prompt, **options) ⇒ Object
-
#ai_chat(prompt, model: nil, **options) ⇒ Object
Text-based AI operations.
- #ai_classify(content, categories, **options) ⇒ Object
- #ai_create_variation(image, **options) ⇒ Object
- #ai_edit_image(image, prompt, **options) ⇒ Object
- #ai_edit_video(video, prompt, **options) ⇒ Object
- #ai_embed(texts, model: nil, **options) ⇒ Object
- #ai_explain_code(code, language: "ruby", **options) ⇒ Object
- #ai_extract_entities(content, **options) ⇒ Object
- #ai_generate_code(prompt, language: "ruby", **options) ⇒ Object
-
#ai_generate_image(prompt, model: "dall-e-3", size: "1024x1024", **options) ⇒ Object
Image generation.
- #ai_generate_image_with_context(prompt, user_context: {}, window_context: {}, **options) ⇒ Object
-
#ai_generate_speech(text, voice: "alloy", **options) ⇒ Object
Audio generation.
-
#ai_generate_video(prompt, model: "sora", duration: 5, **options) ⇒ Object
Video generation.
- #ai_generate_with_context(prompt, user_context: {}, window_context: {}, **options) ⇒ Object
- #ai_image_context(image_data) ⇒ Object
- #ai_redact(text) ⇒ Object
- #ai_safe_content(text) ⇒ Object
- #ai_stream(prompt, model: nil, **options, &block) ⇒ Object
-
#ai_stream_id ⇒ Object
Utility methods.
-
#ai_summarize(content, model: nil, **options) ⇒ Object
Convenience methods for common AI tasks.
- #ai_transcribe_audio(audio, **options) ⇒ Object
- #ai_translate(content, target_language, **options) ⇒ Object
-
#ai_user_context ⇒ Object
Context extraction helpers.
- #ai_window_context ⇒ Object
Instance Method Details
#ai_analyze_image(image, prompt, **options) ⇒ Object
Multimodal analysis
49 50 51 |
# File 'app/helpers/ai_helper.rb', line 49 def ai_analyze_image(image, prompt, **) RailsAi.analyze_image(image, prompt, **) end |
#ai_analyze_image_with_context(image, prompt, user_context: {}, window_context: {}, image_context: {}, **options) ⇒ Object
Context-aware AI operations
58 59 60 61 62 63 64 65 |
# File 'app/helpers/ai_helper.rb', line 58 def ai_analyze_image_with_context(image, prompt, user_context: {}, window_context: {}, image_context: {}, **) RailsAi.analyze_image_with_context(image, prompt, user_context: user_context, window_context: window_context, image_context: image_context, ** ) end |
#ai_analyze_video(video, prompt, **options) ⇒ Object
53 54 55 |
# File 'app/helpers/ai_helper.rb', line 53 def ai_analyze_video(video, prompt, **) RailsAi.analyze_video(video, prompt, **) end |
#ai_chat(prompt, model: nil, **options) ⇒ Object
Text-based AI operations
5 6 7 |
# File 'app/helpers/ai_helper.rb', line 5 def ai_chat(prompt, model: nil, **) RailsAi.chat(prompt, model: model, **) end |
#ai_classify(content, categories, **options) ⇒ Object
92 93 94 |
# File 'app/helpers/ai_helper.rb', line 92 def ai_classify(content, categories, **) RailsAi.classify(content, categories, **) end |
#ai_create_variation(image, **options) ⇒ Object
26 27 28 |
# File 'app/helpers/ai_helper.rb', line 26 def ai_create_variation(image, **) RailsAi.create_variation(image, **) end |
#ai_edit_image(image, prompt, **options) ⇒ Object
22 23 24 |
# File 'app/helpers/ai_helper.rb', line 22 def ai_edit_image(image, prompt, **) RailsAi.edit_image(image, prompt, **) end |
#ai_edit_video(video, prompt, **options) ⇒ Object
35 36 37 |
# File 'app/helpers/ai_helper.rb', line 35 def ai_edit_video(video, prompt, **) RailsAi.edit_video(video, prompt, **) end |
#ai_embed(texts, model: nil, **options) ⇒ Object
13 14 15 |
# File 'app/helpers/ai_helper.rb', line 13 def (texts, model: nil, **) RailsAi.(texts, model: model, **) end |
#ai_explain_code(code, language: "ruby", **options) ⇒ Object
104 105 106 |
# File 'app/helpers/ai_helper.rb', line 104 def ai_explain_code(code, language: "ruby", **) RailsAi.explain_code(code, language: language, **) end |
#ai_extract_entities(content, **options) ⇒ Object
96 97 98 |
# File 'app/helpers/ai_helper.rb', line 96 def ai_extract_entities(content, **) RailsAi.extract_entities(content, **) end |
#ai_generate_code(prompt, language: "ruby", **options) ⇒ Object
100 101 102 |
# File 'app/helpers/ai_helper.rb', line 100 def ai_generate_code(prompt, language: "ruby", **) RailsAi.generate_code(prompt, language: language, **) end |
#ai_generate_image(prompt, model: "dall-e-3", size: "1024x1024", **options) ⇒ Object
Image generation
18 19 20 |
# File 'app/helpers/ai_helper.rb', line 18 def ai_generate_image(prompt, model: "dall-e-3", size: "1024x1024", **) RailsAi.generate_image(prompt, model: model, size: size, **) end |
#ai_generate_image_with_context(prompt, user_context: {}, window_context: {}, **options) ⇒ Object
75 76 77 78 79 80 81 |
# File 'app/helpers/ai_helper.rb', line 75 def ai_generate_image_with_context(prompt, user_context: {}, window_context: {}, **) RailsAi.generate_image_with_context(prompt, user_context: user_context, window_context: window_context, ** ) end |
#ai_generate_speech(text, voice: "alloy", **options) ⇒ Object
Audio generation
40 41 42 |
# File 'app/helpers/ai_helper.rb', line 40 def ai_generate_speech(text, voice: "alloy", **) RailsAi.generate_speech(text, voice: voice, **) end |
#ai_generate_video(prompt, model: "sora", duration: 5, **options) ⇒ Object
Video generation
31 32 33 |
# File 'app/helpers/ai_helper.rb', line 31 def ai_generate_video(prompt, model: "sora", duration: 5, **) RailsAi.generate_video(prompt, model: model, duration: duration, **) end |
#ai_generate_with_context(prompt, user_context: {}, window_context: {}, **options) ⇒ Object
67 68 69 70 71 72 73 |
# File 'app/helpers/ai_helper.rb', line 67 def ai_generate_with_context(prompt, user_context: {}, window_context: {}, **) RailsAi.generate_with_context(prompt, user_context: user_context, window_context: window_context, ** ) end |
#ai_image_context(image_data) ⇒ Object
133 134 135 |
# File 'app/helpers/ai_helper.rb', line 133 def ai_image_context(image_data) RailsAi::ImageContext.new(image_data).to_h end |
#ai_redact(text) ⇒ Object
142 143 144 |
# File 'app/helpers/ai_helper.rb', line 142 def ai_redact(text) RailsAi::Redactor.call(text) end |
#ai_safe_content(text) ⇒ Object
146 147 148 |
# File 'app/helpers/ai_helper.rb', line 146 def ai_safe_content(text) RailsAi::Redactor.call(text) end |
#ai_stream(prompt, model: nil, **options, &block) ⇒ Object
9 10 11 |
# File 'app/helpers/ai_helper.rb', line 9 def ai_stream(prompt, model: nil, **, &block) RailsAi.stream(prompt, model: model, **, &block) end |
#ai_stream_id ⇒ Object
Utility methods
138 139 140 |
# File 'app/helpers/ai_helper.rb', line 138 def ai_stream_id @ai_stream_id ||= SecureRandom.uuid end |
#ai_summarize(content, model: nil, **options) ⇒ Object
Convenience methods for common AI tasks
84 85 86 |
# File 'app/helpers/ai_helper.rb', line 84 def ai_summarize(content, model: nil, **) RailsAi.summarize(content, model: model, **) end |
#ai_transcribe_audio(audio, **options) ⇒ Object
44 45 46 |
# File 'app/helpers/ai_helper.rb', line 44 def ai_transcribe_audio(audio, **) RailsAi.transcribe_audio(audio, **) end |
#ai_translate(content, target_language, **options) ⇒ Object
88 89 90 |
# File 'app/helpers/ai_helper.rb', line 88 def ai_translate(content, target_language, **) RailsAi.translate(content, target_language, **) end |
#ai_user_context ⇒ Object
Context extraction helpers
109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/helpers/ai_helper.rb', line 109 def ai_user_context return {} unless respond_to?(:current_user) && current_user { id: current_user.id, email: current_user.respond_to?(:email) ? current_user.email : nil, role: current_user.respond_to?(:role) ? current_user.role : 'user', created_at: current_user.created_at, preferences: extract_user_preferences }.compact end |
#ai_window_context ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/helpers/ai_helper.rb', line 121 def ai_window_context { controller: controller_name, action: action_name, params: params.except('password', 'password_confirmation', 'token', 'secret', 'key'), user_agent: request.user_agent, referer: request.referer, ip_address: request.remote_ip, timestamp: Time.current.iso8601 } end |