rails_ai 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec_status +96 -0
- data/AGENT_GUIDE.md +513 -0
- data/Appraisals +49 -0
- data/COMMERCIAL_LICENSE_TEMPLATE.md +92 -0
- data/FEATURES.md +204 -0
- data/LEGAL_PROTECTION_GUIDE.md +222 -0
- data/LICENSE +62 -0
- data/LICENSE_SUMMARY.md +74 -0
- data/MIT-LICENSE +62 -0
- data/PERFORMANCE.md +300 -0
- data/PROVIDERS.md +495 -0
- data/README.md +454 -0
- data/Rakefile +11 -0
- data/SPEED_OPTIMIZATIONS.md +217 -0
- data/STRUCTURE.md +139 -0
- data/USAGE_GUIDE.md +288 -0
- data/app/channels/ai_stream_channel.rb +33 -0
- data/app/components/ai/prompt_component.rb +25 -0
- data/app/controllers/concerns/ai/context_aware.rb +77 -0
- data/app/controllers/concerns/ai/streaming.rb +41 -0
- data/app/helpers/ai_helper.rb +164 -0
- data/app/jobs/ai/generate_embedding_job.rb +25 -0
- data/app/jobs/ai/generate_summary_job.rb +25 -0
- data/app/models/concerns/ai/embeddable.rb +38 -0
- data/app/views/rails_ai/dashboard/index.html.erb +51 -0
- data/config/routes.rb +19 -0
- data/lib/generators/rails_ai/install/install_generator.rb +38 -0
- data/lib/rails_ai/agents/agent_manager.rb +258 -0
- data/lib/rails_ai/agents/agent_team.rb +243 -0
- data/lib/rails_ai/agents/base_agent.rb +331 -0
- data/lib/rails_ai/agents/collaboration.rb +238 -0
- data/lib/rails_ai/agents/memory.rb +116 -0
- data/lib/rails_ai/agents/message_bus.rb +95 -0
- data/lib/rails_ai/agents/specialized_agents.rb +391 -0
- data/lib/rails_ai/agents/task_queue.rb +111 -0
- data/lib/rails_ai/cache.rb +14 -0
- data/lib/rails_ai/config.rb +40 -0
- data/lib/rails_ai/context.rb +7 -0
- data/lib/rails_ai/context_analyzer.rb +86 -0
- data/lib/rails_ai/engine.rb +48 -0
- data/lib/rails_ai/events.rb +9 -0
- data/lib/rails_ai/image_context.rb +110 -0
- data/lib/rails_ai/performance.rb +231 -0
- data/lib/rails_ai/provider.rb +8 -0
- data/lib/rails_ai/providers/anthropic_adapter.rb +256 -0
- data/lib/rails_ai/providers/base.rb +60 -0
- data/lib/rails_ai/providers/dummy_adapter.rb +29 -0
- data/lib/rails_ai/providers/gemini_adapter.rb +509 -0
- data/lib/rails_ai/providers/openai_adapter.rb +535 -0
- data/lib/rails_ai/providers/secure_anthropic_adapter.rb +206 -0
- data/lib/rails_ai/providers/secure_openai_adapter.rb +284 -0
- data/lib/rails_ai/railtie.rb +48 -0
- data/lib/rails_ai/redactor.rb +12 -0
- data/lib/rails_ai/security/api_key_manager.rb +82 -0
- data/lib/rails_ai/security/audit_logger.rb +46 -0
- data/lib/rails_ai/security/error_handler.rb +62 -0
- data/lib/rails_ai/security/input_validator.rb +176 -0
- data/lib/rails_ai/security/secure_file_handler.rb +45 -0
- data/lib/rails_ai/security/secure_http_client.rb +177 -0
- data/lib/rails_ai/security.rb +0 -0
- data/lib/rails_ai/version.rb +5 -0
- data/lib/rails_ai/window_context.rb +103 -0
- data/lib/rails_ai.rb +502 -0
- data/monitoring/ci_setup_guide.md +214 -0
- data/monitoring/enhanced_monitoring_script.rb +237 -0
- data/monitoring/google_alerts_setup.md +42 -0
- data/monitoring_log_20250921.txt +0 -0
- data/monitoring_script.rb +161 -0
- data/rails_ai.gemspec +54 -0
- data/scripts/security_scanner.rb +353 -0
- data/setup_monitoring.sh +163 -0
- data/wiki/API-Documentation.md +734 -0
- data/wiki/Architecture-Overview.md +672 -0
- data/wiki/Contributing-Guide.md +407 -0
- data/wiki/Development-Setup.md +532 -0
- data/wiki/Home.md +278 -0
- data/wiki/Installation-Guide.md +527 -0
- data/wiki/Quick-Start.md +186 -0
- data/wiki/README.md +135 -0
- data/wiki/Release-Process.md +467 -0
- metadata +385 -0
data/wiki/Home.md
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
# Rails AI Wiki
|
2
|
+
|
3
|
+
Welcome to the Rails AI documentation! This wiki provides comprehensive guides for developers working with Rails AI.
|
4
|
+
|
5
|
+
## ๐ Quick Start
|
6
|
+
|
7
|
+
- **[Installation Guide](Installation-Guide.md)** - Get Rails AI up and running
|
8
|
+
- **[Quick Start](Quick-Start.md)** - Your first AI-powered Rails app
|
9
|
+
- **[API Documentation](API-Documentation.md)** - Complete API reference
|
10
|
+
|
11
|
+
## ๐ Core Documentation
|
12
|
+
|
13
|
+
### Getting Started
|
14
|
+
- **[Installation Guide](Installation-Guide.md)** - Step-by-step installation
|
15
|
+
- **[Quick Start](Quick-Start.md)** - Build your first AI app
|
16
|
+
- **[Configuration](Configuration.md)** - Configure Rails AI for your needs
|
17
|
+
|
18
|
+
### API Reference
|
19
|
+
- **[API Documentation](API-Documentation.md)** - Complete method reference
|
20
|
+
- **[Provider Support](Provider-Support.md)** - Multi-provider configuration
|
21
|
+
- **[Context System](Context-System.md)** - Context-aware AI operations
|
22
|
+
|
23
|
+
### Architecture
|
24
|
+
- **[Architecture Overview](Architecture-Overview.md)** - System design and components
|
25
|
+
- **[Performance Guide](Performance-Guide.md)** - Optimization strategies
|
26
|
+
- **[Security Guide](Security-Guide.md)** - Security best practices
|
27
|
+
|
28
|
+
## ๐ค AI Providers
|
29
|
+
|
30
|
+
Rails AI supports multiple AI providers with a unified interface:
|
31
|
+
|
32
|
+
### OpenAI
|
33
|
+
- **Models**: GPT-4, GPT-3.5, DALL-E, Whisper, TTS
|
34
|
+
- **Features**: Text generation, image generation, audio processing
|
35
|
+
- **Best for**: General AI tasks, image generation, audio processing
|
36
|
+
|
37
|
+
### Anthropic (Claude)
|
38
|
+
- **Models**: Claude 3 Sonnet, Haiku, Opus
|
39
|
+
- **Features**: Text generation, image analysis
|
40
|
+
- **Best for**: Code analysis, text generation, reasoning tasks
|
41
|
+
|
42
|
+
### Google Gemini
|
43
|
+
- **Models**: Gemini 1.5 Pro, Flash, Vision
|
44
|
+
- **Features**: Text generation, image analysis
|
45
|
+
- **Best for**: Multimodal analysis, Google ecosystem integration
|
46
|
+
|
47
|
+
### Dummy (Testing)
|
48
|
+
- **Models**: Mock models
|
49
|
+
- **Features**: All operations with mock responses
|
50
|
+
- **Best for**: Testing and development
|
51
|
+
|
52
|
+
## ๐ฏ Use Cases
|
53
|
+
|
54
|
+
### Content Generation
|
55
|
+
```ruby
|
56
|
+
# Blog posts
|
57
|
+
RailsAi.chat("Write a technical blog post about Rails 8")
|
58
|
+
|
59
|
+
# Social media content
|
60
|
+
RailsAi.chat("Create engaging Twitter posts about AI")
|
61
|
+
|
62
|
+
# Product descriptions
|
63
|
+
RailsAi.chat("Write product descriptions for an e-commerce site")
|
64
|
+
```
|
65
|
+
|
66
|
+
### Code Assistance
|
67
|
+
```ruby
|
68
|
+
# Code generation
|
69
|
+
RailsAi.generate_code("Create a user authentication system", language: "ruby")
|
70
|
+
|
71
|
+
# Code explanation
|
72
|
+
RailsAi.explain_code("def authenticate_user; end")
|
73
|
+
|
74
|
+
# Code review
|
75
|
+
RailsAi.chat("Review this code for security issues: #{code}")
|
76
|
+
```
|
77
|
+
|
78
|
+
### Image Processing
|
79
|
+
```ruby
|
80
|
+
# Image analysis
|
81
|
+
RailsAi.analyze_image(image_file, "Extract text from this document")
|
82
|
+
|
83
|
+
# Image generation (OpenAI only)
|
84
|
+
RailsAi.generate_image("A modern website homepage design")
|
85
|
+
|
86
|
+
# Image editing (OpenAI only)
|
87
|
+
RailsAi.edit_image(image_file, "Add a company logo to the top right")
|
88
|
+
```
|
89
|
+
|
90
|
+
### Multimodal Applications
|
91
|
+
```ruby
|
92
|
+
# Document analysis
|
93
|
+
RailsAi.analyze_image_with_context(
|
94
|
+
document_image,
|
95
|
+
"Summarize this contract",
|
96
|
+
user_context: { role: "lawyer" },
|
97
|
+
image_context: { format: "pdf" }
|
98
|
+
)
|
99
|
+
|
100
|
+
# Content moderation
|
101
|
+
RailsAi.analyze_image(
|
102
|
+
user_uploaded_image,
|
103
|
+
"Check if this image contains inappropriate content"
|
104
|
+
)
|
105
|
+
```
|
106
|
+
|
107
|
+
## โก Performance Features
|
108
|
+
|
109
|
+
### Smart Caching
|
110
|
+
```ruby
|
111
|
+
# Automatic caching with compression
|
112
|
+
RailsAi.chat("Expensive AI operation") # Cached automatically
|
113
|
+
|
114
|
+
# Clear cache when needed
|
115
|
+
RailsAi.clear_cache!
|
116
|
+
```
|
117
|
+
|
118
|
+
### Batch Processing
|
119
|
+
```ruby
|
120
|
+
# Process multiple requests efficiently
|
121
|
+
requests = [
|
122
|
+
{ prompt: "Write a title" },
|
123
|
+
{ prompt: "Write a summary" },
|
124
|
+
{ prompt: "Write a conclusion" }
|
125
|
+
]
|
126
|
+
results = RailsAi.batch_chat(requests)
|
127
|
+
```
|
128
|
+
|
129
|
+
### Performance Monitoring
|
130
|
+
```ruby
|
131
|
+
# Get performance metrics
|
132
|
+
metrics = RailsAi.metrics
|
133
|
+
# => { chat: { count: 100, avg_duration: 0.5 }, ... }
|
134
|
+
|
135
|
+
# Warmup for faster first requests
|
136
|
+
RailsAi.warmup!
|
137
|
+
```
|
138
|
+
|
139
|
+
## ๐ง Advanced Features
|
140
|
+
|
141
|
+
### Multi-Provider Support
|
142
|
+
```ruby
|
143
|
+
# Switch providers dynamically
|
144
|
+
RailsAi.configure { |c| c.provider = :openai }
|
145
|
+
openai_result = RailsAi.chat("Generate code")
|
146
|
+
|
147
|
+
RailsAi.configure { |c| c.provider = :anthropic }
|
148
|
+
anthropic_result = RailsAi.chat("Analyze this code")
|
149
|
+
|
150
|
+
RailsAi.configure { |c| c.provider = :gemini }
|
151
|
+
gemini_result = RailsAi.chat("Explain this code")
|
152
|
+
```
|
153
|
+
|
154
|
+
### Context-Aware Operations
|
155
|
+
```ruby
|
156
|
+
# User-specific context
|
157
|
+
user_context = {
|
158
|
+
id: 1,
|
159
|
+
name: "John Doe",
|
160
|
+
role: "admin",
|
161
|
+
preferences: { theme: "dark" }
|
162
|
+
}
|
163
|
+
|
164
|
+
# Application context
|
165
|
+
window_context = {
|
166
|
+
controller: "PostsController",
|
167
|
+
action: "show",
|
168
|
+
params: { id: 123 }
|
169
|
+
}
|
170
|
+
|
171
|
+
# Context-aware generation
|
172
|
+
RailsAi.generate_with_context(
|
173
|
+
"Create personalized content",
|
174
|
+
user_context: user_context,
|
175
|
+
window_context: window_context
|
176
|
+
)
|
177
|
+
```
|
178
|
+
|
179
|
+
### Provider Fallback
|
180
|
+
```ruby
|
181
|
+
def robust_ai_operation(prompt)
|
182
|
+
providers = [:openai, :anthropic, :gemini]
|
183
|
+
|
184
|
+
providers.each do |provider|
|
185
|
+
begin
|
186
|
+
RailsAi.configure { |c| c.provider = provider }
|
187
|
+
return RailsAi.chat(prompt)
|
188
|
+
rescue => e
|
189
|
+
Rails.logger.warn("#{provider} failed: #{e.message}")
|
190
|
+
next
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
raise "All providers failed"
|
195
|
+
end
|
196
|
+
```
|
197
|
+
|
198
|
+
## ๐งช Testing
|
199
|
+
|
200
|
+
### Using Dummy Provider
|
201
|
+
```ruby
|
202
|
+
# In your tests
|
203
|
+
RSpec.describe "AI Features" do
|
204
|
+
before do
|
205
|
+
RailsAi.configure do |config|
|
206
|
+
config.provider = :dummy
|
207
|
+
config.stub_responses = true
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
it "generates content" do
|
212
|
+
result = RailsAi.chat("Hello")
|
213
|
+
expect(result).to include("Hello")
|
214
|
+
end
|
215
|
+
end
|
216
|
+
```
|
217
|
+
|
218
|
+
### Testing Multiple Providers
|
219
|
+
```ruby
|
220
|
+
RSpec.describe "Provider Compatibility" do
|
221
|
+
%i[openai anthropic gemini dummy].each do |provider|
|
222
|
+
context "with #{provider} provider" do
|
223
|
+
before do
|
224
|
+
RailsAi.configure { |c| c.provider = provider }
|
225
|
+
end
|
226
|
+
|
227
|
+
it "generates text" do
|
228
|
+
result = RailsAi.chat("Test")
|
229
|
+
expect(result).to be_a(String)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
```
|
235
|
+
|
236
|
+
## ๐ Rails Compatibility
|
237
|
+
|
238
|
+
- **Rails 8.0** โ
(Primary target)
|
239
|
+
- **Rails 7.x** โ
(Fully supported)
|
240
|
+
- **Rails 6.x** โ
(Fully supported)
|
241
|
+
- **Rails 5.2+** โ
(Supported)
|
242
|
+
|
243
|
+
## ๐ฆ Dependencies
|
244
|
+
|
245
|
+
### Required
|
246
|
+
- Rails >= 5.2
|
247
|
+
- Ruby >= 2.7
|
248
|
+
|
249
|
+
### Optional (for specific providers)
|
250
|
+
- `ruby-anthropic` - For Anthropic (Claude) support
|
251
|
+
- `gemini-ai` - For Google Gemini support
|
252
|
+
|
253
|
+
## ๐ค Contributing
|
254
|
+
|
255
|
+
1. Fork the repository
|
256
|
+
2. Create a feature branch
|
257
|
+
3. Make your changes
|
258
|
+
4. Add tests
|
259
|
+
5. Submit a pull request
|
260
|
+
|
261
|
+
See [Contributing Guide](Contributing-Guide.md) for details.
|
262
|
+
|
263
|
+
## ๐ License
|
264
|
+
|
265
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
266
|
+
|
267
|
+
## ๐ Acknowledgments
|
268
|
+
|
269
|
+
- OpenAI for GPT and DALL-E models
|
270
|
+
- Anthropic for Claude models
|
271
|
+
- Google for Gemini models
|
272
|
+
- The Rails community for inspiration
|
273
|
+
|
274
|
+
---
|
275
|
+
|
276
|
+
**Built with โค๏ธ for the Rails community**
|
277
|
+
|
278
|
+
[Documentation](wiki/) โข [Features](FEATURES.md) โข [Usage](USAGE_GUIDE.md) โข [Providers](PROVIDERS.md) โข [Contributing](wiki/Contributing-Guide.md)
|