ai_chatbot 0.1.5 → 0.1.6.1
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/ai_chatbot.rb +4 -4
- data/lib/ml_model.py +29 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63e218e69731be19e33a2b260fa04382dd1f3da77d9a8e20f0ee1bd8eac4fc97
|
4
|
+
data.tar.gz: bb380d89a7d15f29b426b33df682421412f62a41e9f1891858121dbb9c8b2de2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55d0946bd34c6009ac0029a6f4c183d6059b75eef2552b9eaa6c3905277209a13bf1e6e43b5b27dbabb1e5cf5a972f13ad1ae73902465bbc0256f6b09ebcf8ab
|
7
|
+
data.tar.gz: 397a9e37b9c225a25eb4765e5ad5e2377e7c64566cb623f131fc1bfe8d3fd298b8f0a3214fe9661d56d2a7fd2db94fc6a26cd357bc9036ad4d22407d9dd291e7
|
data/lib/ai_chatbot/version.rb
CHANGED
data/lib/ai_chatbot.rb
CHANGED
@@ -27,7 +27,7 @@ module AiChatbot
|
|
27
27
|
|
28
28
|
# Method to train the model with a new question-answer pair
|
29
29
|
def self.update_answer(existing_question, new_answer)
|
30
|
-
stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "update_answer",
|
30
|
+
stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "update_answer", existing_question, new_answer)
|
31
31
|
|
32
32
|
if status.success?
|
33
33
|
return stdout.strip
|
@@ -36,8 +36,8 @@ module AiChatbot
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def self.
|
40
|
-
stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "
|
39
|
+
def self.update_or_delete_question(existing_question, new_question)
|
40
|
+
stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "update_or_delete_question", existing_question, new_answer)
|
41
41
|
|
42
42
|
if status.success?
|
43
43
|
return stdout.strip
|
@@ -46,7 +46,7 @@ module AiChatbot
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.
|
49
|
+
def self.list_questions
|
50
50
|
stdout, stderr, status = Open3.capture3("python3", "#{__dir__}/ml_model.py", "list_questions")
|
51
51
|
|
52
52
|
if status.success?
|
data/lib/ml_model.py
CHANGED
@@ -36,8 +36,8 @@ def main(action, query=None, new_answer=None):
|
|
36
36
|
return train_model(query, new_answer)
|
37
37
|
elif action == "update_answer":
|
38
38
|
return update_answer(query, new_answer)
|
39
|
-
elif action == "
|
40
|
-
return
|
39
|
+
elif action == "update_or_delete_question":
|
40
|
+
return update_or_delete_question(query, new_answer) # Corrected here, calling the right function
|
41
41
|
elif action == "list_questions":
|
42
42
|
return list_questions()
|
43
43
|
|
@@ -91,22 +91,35 @@ def update_answer(existing_question, new_answer):
|
|
91
91
|
else:
|
92
92
|
return "Question not found. Please provide a valid question."
|
93
93
|
|
94
|
-
def
|
95
|
-
global questions, new_question
|
96
|
-
|
94
|
+
def update_or_delete_question(existing_question, new_question=None):
|
95
|
+
global questions # Only 'questions' is global, not 'new_question'
|
96
|
+
|
97
97
|
if existing_question in questions:
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
98
|
+
if new_question:
|
99
|
+
# Find the index of the existing question
|
100
|
+
index = questions.index(existing_question)
|
101
|
+
# Update the question
|
102
|
+
questions[index] = new_question
|
103
|
+
# Retrain the model with updated data
|
104
|
+
model.fit(questions, answers)
|
105
|
+
# Save the updated model and data
|
106
|
+
with open("qa_model.pkl", "wb") as f:
|
107
|
+
pickle.dump({"questions": questions, "answers": answers}, f)
|
108
|
+
return f"Question updated from '{existing_question}' to '{new_question}'"
|
109
|
+
else:
|
110
|
+
# Remove the question if no new question is provided
|
111
|
+
index = questions.index(existing_question)
|
112
|
+
del questions[index]
|
113
|
+
del answers[index] # Ensure you also delete the corresponding answer
|
114
|
+
# Retrain the model with updated data
|
115
|
+
model.fit(questions, answers)
|
116
|
+
# Save the updated model and data
|
117
|
+
with open("qa_model.pkl", "wb") as f:
|
118
|
+
pickle.dump({"questions": questions, "answers": answers}, f)
|
119
|
+
return f"Question '{existing_question}' deleted successfully."
|
108
120
|
else:
|
109
|
-
return "Question not found. Please provide a valid question."
|
121
|
+
return "Question not found. Please provide a valid question."
|
122
|
+
|
110
123
|
|
111
124
|
def list_questions():
|
112
125
|
global questions
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ai_chatbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sanket
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: open3
|