Class: Get::Smart::Ai::Verifier
- Inherits:
-
Object
- Object
- Get::Smart::Ai::Verifier
- Defined in:
- lib/get/smart/ai/verifier.rb
Defined Under Namespace
Classes: GeminiClient
Instance Attribute Summary collapse
-
#folder ⇒ Object
readonly
Returns the value of attribute folder.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(folder:) ⇒ Verifier
constructor
A new instance of Verifier.
- #instructions ⇒ Object
Constructor Details
#initialize(folder:) ⇒ Verifier
Returns a new instance of Verifier.
42 43 44 |
# File 'lib/get/smart/ai/verifier.rb', line 42 def initialize(folder:) @folder = folder end |
Instance Attribute Details
#folder ⇒ Object (readonly)
Returns the value of attribute folder.
41 42 43 |
# File 'lib/get/smart/ai/verifier.rb', line 41 def folder @folder end |
Instance Method Details
#call ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/get/smart/ai/verifier.rb', line 46 def call files = Dir.glob("#{folder}/**/*.md") files.each do |file| begin content = File.read(file) response = GeminiClient.new.call(instructions: instructions, prompt: content) json = JSON.parse(JSON.parse(response.body).dig("candidates", 0, "content", "parts", 0, "text")) score_txt = json["score"].to_i >= 8 ? json["score"].to_i.to_s.green : json["score"].to_i.to_s.red puts "#{file}: #{score_txt}" + (json["details"].present? ? " #{json["details"]}".yellow : "") sleep 0.1 if File.size(file) < 10 puts "#{file}: DELETING, size: #{File.size(file)}" File.delete(file) end rescue JSON::ParserError => e puts "#{file}: SKIP" end end end |
#instructions ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/get/smart/ai/verifier.rb', line 66 def instructions " You are a helpful expert in Ruby and Rails, full stack developer with knowledge of Ruby, Rails, HTML, CSS, JavaScript, SQL, Git, and other related technologies.\n Your role is to verify content of the useful tips for Ruby and Rails developers.\n You need to rate the content of the tip from 1 to 10 in order to determine if it is working, useful and helpful for Ruby and Rails developers.\n When 10 is the highest score, it means that the tip is working, useful and helpful for Ruby and Rails developers.\n When 1 is the lowest score, it means that the tip is not working, not useful and not helpful for Ruby and Rails developers.\n You need to return only the score from 1 to 10.\n If file is empty, or no tip return 0.\n If something is wrong with the tip return details about what is wrong and how to fix it, but keep short.\n\n Example of response:\n\n ```json\n {\n \"score\": 10\n }\n ```\n\n or\n\n ```json\n {\n \"score\": 1,\n \"details\": \"The tip is not working, not useful and not helpful for Ruby and Rails developers.\"\n }\n ```\n\n Only reply in JSON format.\n INSTRUCTIONS\nend\n" |