ai_chatbot 0.1.4 → 0.1.6

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: 12bcba7047f40d05685eec1c6a6714d7b8b6d57b092df1dcf6e382040af48182
4
- data.tar.gz: ede7b3ccff3faecf008c681c649f7ac3732bebbd2a46f7801a313a0d64507ce4
3
+ metadata.gz: 726472f08ac5fcbed289fcd127215efb58823399b4c1e960ef4a9ae35a4ce368
4
+ data.tar.gz: 59cc5bbe59655f7863970fb32ee66279d308208af82b5ca7d3462748146972de
5
5
  SHA512:
6
- metadata.gz: 991397292bed26854442cc630a87539fbb3ccba1cf81f6af673db57b607e56fdf150d4d905b00709b2c81ea6b4510759d7785f6ba16e44d58eab6e371b4ee581
7
- data.tar.gz: f5312f608a08cffac6ef4ad93b4e7aed47191fdf0af0b7337a93bc13a9605e09db4eec91176b7dcc16c155af310d38d359fb03314bdd918b291f008579b56926
6
+ metadata.gz: 4611e846bcb29c1a0f5466a7b9269640ab8bb74ad8bb221e885f0c5fe07d2ec92e9a98aedec1b855fcc8ff6590a885c8f3522e4d8b5863724e7495ebc2a963fe
7
+ data.tar.gz: bb5dfc83841117e9f001d7691fa0fc4a1d439bf53cd7dc535b34a2f5a1f3b24c999d5a34d8cc407af7f4a036128fd280cf8998804c346a07364251bf885176ba
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AiChatbot
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.6"
5
5
  end
data/lib/ai_chatbot.rb CHANGED
@@ -23,5 +23,39 @@ module AiChatbot
23
23
  raise "Error: #{stderr}"
24
24
  end
25
25
  end
26
+
27
+
28
+ # Method to train the model with a new question-answer pair
29
+ def self.update_answer(existing_question, new_answer)
30
+ stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "update_answer", new_question, new_answer)
31
+
32
+ if status.success?
33
+ return stdout.strip
34
+ else
35
+ raise "Error: #{stderr}"
36
+ end
37
+ end
38
+
39
+ def self.update_question(existing_question, new_question)
40
+ stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "update_question", new_question, new_answer)
41
+
42
+ if status.success?
43
+ return stdout.strip
44
+ else
45
+ raise "Error: #{stderr}"
46
+ end
47
+ end
48
+
49
+ def self.list_of_questions
50
+ stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "list_questions")
51
+
52
+ if status.success?
53
+ return stdout.strip
54
+ else
55
+ raise "Error: #{stderr}"
56
+ end
57
+ end
58
+
59
+
26
60
  end
27
61
  end
data/lib/ml_model.py CHANGED
@@ -34,9 +34,11 @@ def main(action, query=None, new_answer=None):
34
34
  return get_prediction(query)
35
35
  elif action == "train":
36
36
  return train_model(query, new_answer)
37
- elif action == "update":
37
+ elif action == "update_answer":
38
38
  return update_answer(query, new_answer)
39
- elif action == "list":
39
+ elif action == "update_question":
40
+ return update_question(query, new_answer) # Corrected here, calling the right function
41
+ elif action == "list_questions":
40
42
  return list_questions()
41
43
 
42
44
  # Function to predict the response with confidence check
@@ -90,21 +92,21 @@ def update_answer(existing_question, new_answer):
90
92
  return "Question not found. Please provide a valid question."
91
93
 
92
94
  def update_question(existing_question, new_question):
93
- global existing_question, new_question
95
+ global questions # Only 'questions' is global, not 'new_question'
94
96
 
95
97
  if existing_question in questions:
96
98
  # Find the index of the existing question
97
99
  index = questions.index(existing_question)
98
- # Update the answer
99
- existing_question[index] = new_question
100
+ # Update the question
101
+ questions[index] = new_question
100
102
  # Retrain the model with updated data
101
103
  model.fit(questions, answers)
102
104
  # Save the updated model and data
103
105
  with open("qa_model.pkl", "wb") as f:
104
106
  pickle.dump({"questions": questions, "answers": answers}, f)
105
- return f"New question updated for the question: '{existing_question}'"
107
+ return f"Question updated from '{existing_question}' to '{new_question}'"
106
108
  else:
107
- return "Question not found. Please provide a valid question."
109
+ return "Question not found. Please provide a valid question."
108
110
 
109
111
  def list_questions():
110
112
  global questions
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai_chatbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sanket