ai_chatbot 0.1.3 → 0.1.5
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 +34 -0
- data/lib/ml_model.py +22 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06bf16d383baea57ccc0bdbdcd1e041683130f0ef85120ca5af04b24cf64bbf9
|
4
|
+
data.tar.gz: d98da511ebcfbc645ffd5182db2e3c31703786714f98fb0374ec203386644439
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4e7bf28f9d9b7568aa3dbe736b546018315f1d4dabd5b2d3ceff26dc3e12fc396f8ae35f32236900b8c39f8a1eadf889c93e8ba6bb37cebc14ef7402bcc0606
|
7
|
+
data.tar.gz: 8fdba9ecec76779184a18098395ba4a6d3b173c4e788ed40d0c3f2c2300a4ad2fb4a05a41928e82995fe7ad39d95576b996aa5e78d17dc54826a48243d2bab64
|
data/lib/ai_chatbot/version.rb
CHANGED
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 == "
|
37
|
+
elif action == "update_answer":
|
38
38
|
return update_answer(query, new_answer)
|
39
|
-
elif action == "
|
39
|
+
elif action == "update_question":
|
40
|
+
return update_answer(query, new_question)
|
41
|
+
elif action == "list_questions":
|
40
42
|
return list_questions()
|
41
43
|
|
42
44
|
# Function to predict the response with confidence check
|
@@ -48,7 +50,7 @@ def get_prediction(query):
|
|
48
50
|
similarities = cosine_similarity(query_vec, question_vecs)
|
49
51
|
max_similarity = similarities.max()
|
50
52
|
|
51
|
-
threshold = 0.
|
53
|
+
threshold = 0.65
|
52
54
|
if max_similarity < threshold:
|
53
55
|
return "No good match found. Please provide the correct answer."
|
54
56
|
else:
|
@@ -89,6 +91,23 @@ def update_answer(existing_question, new_answer):
|
|
89
91
|
else:
|
90
92
|
return "Question not found. Please provide a valid question."
|
91
93
|
|
94
|
+
def update_question(existing_question, new_question):
|
95
|
+
global questions, new_question
|
96
|
+
|
97
|
+
if existing_question in questions:
|
98
|
+
# Find the index of the existing question
|
99
|
+
index = questions.index(existing_question)
|
100
|
+
# Update the answer
|
101
|
+
existing_question[index] = new_question
|
102
|
+
# Retrain the model with updated data
|
103
|
+
model.fit(questions, answers)
|
104
|
+
# Save the updated model and data
|
105
|
+
with open("qa_model.pkl", "wb") as f:
|
106
|
+
pickle.dump({"questions": questions, "answers": answers}, f)
|
107
|
+
return f"New question updated for the question: '{existing_question}'"
|
108
|
+
else:
|
109
|
+
return "Question not found. Please provide a valid question."
|
110
|
+
|
92
111
|
def list_questions():
|
93
112
|
global questions
|
94
113
|
return 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.5
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: open3
|
@@ -38,7 +38,8 @@ files:
|
|
38
38
|
homepage: https://github.com/tikhandesanket/ai-chatbot
|
39
39
|
licenses:
|
40
40
|
- MIT
|
41
|
-
metadata:
|
41
|
+
metadata:
|
42
|
+
source_code_uri: https://github.com/tikhandesanket/ai-chatbot
|
42
43
|
post_install_message:
|
43
44
|
rdoc_options: []
|
44
45
|
require_paths:
|