Module: AiHelper

Defined in:
app/helpers/ai_helper.rb

Instance Method Summary collapse

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, **options)
  RailsAi.analyze_image(image, prompt, **options)
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: {}, **options)
  RailsAi.analyze_image_with_context(image, prompt, 
    user_context: user_context, 
    window_context: window_context, 
    image_context: image_context, 
    **options
  )
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, **options)
  RailsAi.analyze_video(video, prompt, **options)
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, **options)
  RailsAi.chat(prompt, model: model, **options)
end

#ai_classify(content, categories, **options) ⇒ Object



92
93
94
# File 'app/helpers/ai_helper.rb', line 92

def ai_classify(content, categories, **options)
  RailsAi.classify(content, categories, **options)
end

#ai_create_variation(image, **options) ⇒ Object



26
27
28
# File 'app/helpers/ai_helper.rb', line 26

def ai_create_variation(image, **options)
  RailsAi.create_variation(image, **options)
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, **options)
  RailsAi.edit_image(image, prompt, **options)
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, **options)
  RailsAi.edit_video(video, prompt, **options)
end

#ai_embed(texts, model: nil, **options) ⇒ Object



13
14
15
# File 'app/helpers/ai_helper.rb', line 13

def ai_embed(texts, model: nil, **options)
  RailsAi.embed(texts, model: model, **options)
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", **options)
  RailsAi.explain_code(code, language: language, **options)
end

#ai_extract_entities(content, **options) ⇒ Object



96
97
98
# File 'app/helpers/ai_helper.rb', line 96

def ai_extract_entities(content, **options)
  RailsAi.extract_entities(content, **options)
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", **options)
  RailsAi.generate_code(prompt, language: language, **options)
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", **options)
  RailsAi.generate_image(prompt, model: model, size: size, **options)
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: {}, **options)
  RailsAi.generate_image_with_context(prompt, 
    user_context: user_context, 
    window_context: window_context, 
    **options
  )
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", **options)
  RailsAi.generate_speech(text, voice: voice, **options)
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, **options)
  RailsAi.generate_video(prompt, model: model, duration: duration, **options)
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: {}, **options)
  RailsAi.generate_with_context(prompt, 
    user_context: user_context, 
    window_context: window_context, 
    **options
  )
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, **options, &block)
  RailsAi.stream(prompt, model: model, **options, &block)
end

#ai_stream_idObject

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, **options)
  RailsAi.summarize(content, model: model, **options)
end

#ai_transcribe_audio(audio, **options) ⇒ Object



44
45
46
# File 'app/helpers/ai_helper.rb', line 44

def ai_transcribe_audio(audio, **options)
  RailsAi.transcribe_audio(audio, **options)
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, **options)
  RailsAi.translate(content, target_language, **options)
end

#ai_user_contextObject

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_contextObject



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