module IsitCore
Constants
- AI_QUESTION
- MAX_WORDS
- MIN_WORDS
- NO_CHANCE
Public Instance Methods
Source
# File lib/isit_core.rb, line 30 def ai_message_triggers?(text) text.to_s.strip.match?(/\Ais it\?\?\z/i) end
Source
# File lib/isit_core.rb, line 98 def ai_reply(channel:, asker:, network:, rand: ->(max) { Random.rand(0...max) }, runner:, store: RabbotDb, yaml_default: nil) resolved_model = AiModel.resolve( network: network, channel: channel, yaml_default: yaml_default ) prompt = build_ai_prompt(channel: channel, asker: asker, network: network, store: store) result = AiAgent.run_agent(prompt, model: resolved_model, runner: runner) final = if result.success? parse_ai_verdict(result.text) || pick_final(rand: rand) else pick_final(rand: rand) end format_reply(pick_sequence(rand: rand, final: final)) end
Source
# File lib/isit_core.rb, line 81 def build_ai_prompt(channel:, asker:, network:, store: RabbotDb) context_lines = AiChatCore.build_context_lines( channel, "is it", network: network, store: store, asker: asker ) AiAgent.build_agent_prompt( question: AI_QUESTION, context_lines: context_lines, chat_history_lines: [], asker: asker, channel: channel ) end
Source
# File lib/isit_core.rb, line 50 def build_sequence(count:, final:) return [] if count <= 0 lead = opposite(final) Array.new(count - 1, lead) + [final] end
Source
# File lib/isit_core.rb, line 34 def channel_triggers?(text) message_triggers?(text) || ai_message_triggers?(text) end
Source
# File lib/isit_core.rb, line 115 def dispatch(text:, ai_allowed:, channel:, asker:, network:, rand: ->(max) { Random.rand(0...max) }, runner:, store: RabbotDb, yaml_default: nil) if ai_message_triggers?(text) unless ai_allowed return { async: false, reply: AiAccess.denial_message } end return { async: true, reply: nil, run: lambda { ai_reply( channel: channel, asker: asker, network: network, rand: rand, runner: runner, store: store, yaml_default: yaml_default ) } } end if message_triggers?(text) return { async: false, reply: random_reply(rand: rand) } end { async: false, reply: nil } end
Source
# File lib/isit_core.rb, line 62 def format_reply(sequence) body = sequence.join(" ") tag = IrcFormat.tag("ISIT") "#{tag} #{body}" end
Source
# File lib/isit_core.rb, line 26 def message_triggers?(text) text.to_s.strip.match?(/\Ais it\??\z/i) && !ai_message_triggers?(text) end
Source
# File lib/isit_core.rb, line 38 def opposite(word) word == "no" ? "yes" : "no" end
Source
# File lib/isit_core.rb, line 76 def parse_ai_verdict(text) match = text.to_s.downcase.match(/\b(yes|no)\b/) match&.[](1) end
Source
# File lib/isit_core.rb, line 46 def pick_final(rand: ->(max) { Random.rand(0...max) }) rand.call(100) < NO_CHANCE ? "no" : "yes" end
Source
# File lib/isit_core.rb, line 57 def pick_sequence(rand: ->(max) { Random.rand(0...max) }, final: nil) resolved_final = final || pick_final(rand: rand) build_sequence(count: word_count(rand: rand), final: resolved_final) end
Source
# File lib/isit_core.rb, line 72 def random_reply(rand: ->(max) { Random.rand(0...max) }) reply(rand: rand) end
Source
# File lib/isit_core.rb, line 68 def reply(rand: ->(max) { Random.rand(0...max) }) format_reply(pick_sequence(rand: rand)) end
Source
# File lib/isit_core.rb, line 42 def word_count(rand: ->(max) { Random.rand(0...max) }) MIN_WORDS + rand.call(MAX_WORDS - MIN_WORDS + 1) end