ai_chatbot 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ai_chatbot/version.rb +1 -1
- data/lib/ml_model.py +25 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44d4375b7617e626f0ece5d48d9951db6cbb29d40fc039ed432f57f95214ff61
|
4
|
+
data.tar.gz: b47d32642a89b0a8ee430d210d57fa310616828938e431cf5b9094b1720e9d92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b85bdabf2fcf579a8355ef6b847251b6f1a715ef648a70bdbff1d4807f3615b425c50b80ce54f653477ae4c4caa163c8614e9563364a75145ff346b369077c3
|
7
|
+
data.tar.gz: 1fd7b59dde9c05e0ebca46fb472365786e7dbeb6440d2b30c7a0239246343efb8c3cb617aad4a83c48af2c3d18daab3726aaf6f672ea20b33bfbaa012995b94c
|
data/lib/ai_chatbot/version.rb
CHANGED
data/lib/ml_model.py
CHANGED
@@ -34,6 +34,10 @@ 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":
|
38
|
+
return update_answer(query, new_answer)
|
39
|
+
elif action == "list":
|
40
|
+
return list_questions()
|
37
41
|
|
38
42
|
# Function to predict the response with confidence check
|
39
43
|
def get_prediction(query):
|
@@ -68,6 +72,27 @@ def train_model(new_question, new_answer):
|
|
68
72
|
|
69
73
|
return f"Model retrained with the new question: '{new_question}' and answer: '{new_answer}'"
|
70
74
|
|
75
|
+
def update_answer(existing_question, new_answer):
|
76
|
+
global questions, answers
|
77
|
+
|
78
|
+
if existing_question in questions:
|
79
|
+
# Find the index of the existing question
|
80
|
+
index = questions.index(existing_question)
|
81
|
+
# Update the answer
|
82
|
+
answers[index] = new_answer
|
83
|
+
# Retrain the model with updated data
|
84
|
+
model.fit(questions, answers)
|
85
|
+
# Save the updated model and data
|
86
|
+
with open("qa_model.pkl", "wb") as f:
|
87
|
+
pickle.dump({"questions": questions, "answers": answers}, f)
|
88
|
+
return f"Answer updated for the question: '{existing_question}'"
|
89
|
+
else:
|
90
|
+
return "Question not found. Please provide a valid question."
|
91
|
+
|
92
|
+
def list_questions():
|
93
|
+
global questions
|
94
|
+
return questions
|
95
|
+
|
71
96
|
if __name__ == "__main__":
|
72
97
|
# Expecting action (predict/train), question, and answer (if training)
|
73
98
|
action = sys.argv[1]
|