Class: AiChatbot::Chatbot
- Inherits:
-
Object
- Object
- AiChatbot::Chatbot
- Defined in:
- lib/ai_chatbot.rb
Class Method Summary collapse
-
.ask_question(question) ⇒ Object
Method to ask a question and get prediction from Python.
- .list_answers ⇒ Object
- .list_questions ⇒ Object
-
.train_model(new_question, new_answer) ⇒ Object
Method to train the model with a new question-answer pair.
-
.update_answer(existing_question, new_answer) ⇒ Object
Method to train the model with a new question-answer pair.
- .update_or_delete_question(existing_question, new_question = nil) ⇒ Object
Class Method Details
.ask_question(question) ⇒ Object
Method to ask a question and get prediction from Python
6 7 8 9 10 11 12 13 14 |
# File 'lib/ai_chatbot.rb', line 6 def self.ask_question(question) stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "predict", question) if status.success? return stdout.strip else raise "Error: #{stderr}" end end |
.list_answers ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/ai_chatbot.rb', line 59 def self.list_answers stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "list_answers") if status.success? return stdout.strip else raise "Error: #{stderr}" end end |
.list_questions ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/ai_chatbot.rb', line 49 def self.list_questions stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "list_questions") if status.success? return stdout.strip else raise "Error: #{stderr}" end end |
.train_model(new_question, new_answer) ⇒ Object
Method to train the model with a new question-answer pair
17 18 19 20 21 22 23 24 25 |
# File 'lib/ai_chatbot.rb', line 17 def self.train_model(new_question, new_answer) stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "train_model", new_question, new_answer) if status.success? return stdout.strip else raise "Error: #{stderr}" end end |
.update_answer(existing_question, new_answer) ⇒ Object
Method to train the model with a new question-answer pair
29 30 31 32 33 34 35 36 37 |
# File 'lib/ai_chatbot.rb', line 29 def self.update_answer(existing_question, new_answer) stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "update_answer", existing_question, new_answer) if status.success? return stdout.strip else raise "Error: #{stderr}" end end |
.update_or_delete_question(existing_question, new_question = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/ai_chatbot.rb', line 39 def self.update_or_delete_question(existing_question, new_question=nil) stdout, stderr, status = new_question == nil ? Open3.capture3("python3", "#{__dir__}/ml_model.py", "update_or_delete_question", existing_question,"None") : Open3.capture3("python3", "#{__dir__}/ml_model.py", "update_or_delete_question", existing_question, new_question) if status.success? return stdout.strip else raise "Error: #{stderr}" end end |