ai_chatbot 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bde3d724e066978fd481402f7aaa899041d85044b8b3ecc10574410ee79946f2
4
- data.tar.gz: 8cc52ee8ec6b7e061fa6c009fdac5886b6b8e1a6e785d50abf70146bf04135ab
3
+ metadata.gz: 44d4375b7617e626f0ece5d48d9951db6cbb29d40fc039ed432f57f95214ff61
4
+ data.tar.gz: b47d32642a89b0a8ee430d210d57fa310616828938e431cf5b9094b1720e9d92
5
5
  SHA512:
6
- metadata.gz: 115664a820b9b5c3da45d3fbb382785bd24dc0a840ad707fd8d1f0e7612d498c377ed12e86e7f997191cc83585a4245cfedda79cc22ee8ecfd44e01c131bb10b
7
- data.tar.gz: f94763913a5cf902b9f940855c9f5a608a47495f776ddd3ab59e223ebad03be2bb0320c9d57317db2435a2f0662e08aca18f3143e56265a3fb7d7e86e018a6ca
6
+ metadata.gz: 2b85bdabf2fcf579a8355ef6b847251b6f1a715ef648a70bdbff1d4807f3615b425c50b80ce54f653477ae4c4caa163c8614e9563364a75145ff346b369077c3
7
+ data.tar.gz: 1fd7b59dde9c05e0ebca46fb472365786e7dbeb6440d2b30c7a0239246343efb8c3cb617aad4a83c48af2c3d18daab3726aaf6f672ea20b33bfbaa012995b94c
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AiChatbot
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
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):
@@ -44,7 +48,7 @@ def get_prediction(query):
44
48
  similarities = cosine_similarity(query_vec, question_vecs)
45
49
  max_similarity = similarities.max()
46
50
 
47
- threshold = 0.85
51
+ threshold = 0.70
48
52
  if max_similarity < threshold:
49
53
  return "No good match found. Please provide the correct answer."
50
54
  else:
@@ -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]
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sanet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-14 00:00:00.000000000 Z
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open3