rails_ai 0.1.6 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53d48e7589680a3868fd3f1941a782067cf8a223cd22180776bed4651ef64743
4
- data.tar.gz: 6367732d15ece684b5b80791842e84aae8605c3d285e6984682671f42bcf332b
3
+ metadata.gz: 79cd8a7525dc1139d6d697801f1e24f41d72157d97b1e42a049debce931146c1
4
+ data.tar.gz: abf698a755293a28d98756a5979f69806ea91c5c3fbc25edab0d4ad349cdfb17
5
5
  SHA512:
6
- metadata.gz: cc442b24a76848c614942215d623e74aa1acdf82049c5e100ed2de430a91c79c4539e2be78dd5a26c2691d8e67f9e35629dd5dcee80c7feeb97ba91c6d85fbf5
7
- data.tar.gz: 7d09b4883eb116e951868c0cb88a50bdc4a745112a9769d24003828f497391473f07e531f3accd102b7fa2059191c63df4a903d82325b6d3a31d65487a5f6d48
6
+ metadata.gz: 28f77635e2609dc5aec01c34ee9a3a22e856ac3ef47733f913cc81c993426de7fc7f14e4a3ece60783387b98594122d611306f03ac1d38f085e7a4b1deaff610
7
+ data.tar.gz: 5adcc56daa2903a3cd8969fe1d8be971a41e2beaf277f247b9feda2a25d6c194dd9719cfb1e1a8ac12e13ff06bc519d50494084052776895db0c6fbd69c914c4
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAi
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
data/lib/rails_ai.rb CHANGED
@@ -500,3 +500,35 @@ end
500
500
  def self.handle_security_error(error, context = {})
501
501
  Security::ErrorHandler.handle_security_error(error, context)
502
502
  end
503
+ require_relative "rails_ai/web_search"
504
+
505
+ # Web-enhanced chat with real-time information
506
+ def self.chat_with_web_search(prompt, model: config.default_model, **opts)
507
+ # Check if the prompt needs web search
508
+ web_keywords = ['current', 'latest', 'today', 'now', 'recent', 'weather', 'news', 'stock', 'price']
509
+ needs_web_search = web_keywords.any? { |keyword| prompt.downcase.include?(keyword) }
510
+
511
+ if needs_web_search
512
+ begin
513
+ # Perform web search
514
+ search_results = WebSearch.search(prompt, num_results: 3)
515
+
516
+ # Enhance the prompt with web results
517
+ web_context = "\n\nRecent web search results:\n"
518
+ search_results.each_with_index do |result, index|
519
+ web_context += "#{index + 1}. #{result[:title]}\n #{result[:snippet]}\n Source: #{result[:link]}\n\n"
520
+ end
521
+
522
+ enhanced_prompt = "#{prompt}\n\nPlease use the following web search results to provide current, up-to-date information:#{web_context}"
523
+
524
+ # Get AI response with web context
525
+ chat(enhanced_prompt, model: model, **opts)
526
+ rescue WebSearch::SearchError => e
527
+ # Fallback to regular chat if web search fails
528
+ chat(prompt, model: model, **opts)
529
+ end
530
+ else
531
+ # Regular chat for non-time-sensitive queries
532
+ chat(prompt, model: model, **opts)
533
+ end
534
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Amah