dynamic-learning-model 4.0.5__tar.gz → 4.0.6__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dynamic-learning-model
3
- Version: 4.0.5
3
+ Version: 4.0.6
4
4
  Summary: A Dynamic-Learning Model (DLM) chatbot with memory and compute reasoning modes.
5
5
  Author-email: Vignesh Thondikulam <vignesh.tho2006@gmail.com>
6
6
  License: MIT
@@ -24,6 +24,7 @@ from transformers import pipeline
24
24
  from better_profanity import profanity
25
25
  from nltk.corpus import names
26
26
 
27
+
27
28
  class DLM:
28
29
  # for one-time, shared model loaders so that each object won't load a new model (> 2GB)
29
30
  _shared_nlp = None
@@ -372,7 +373,7 @@ class DLM:
372
373
  "Let’s reset. Rephrase your question without the frustration, and I’ll be able to help you effectively."
373
374
  ]
374
375
 
375
- def __init__(self, mode, db_filename="dlm_database.db"): # initializes SQL database & SpaCy NLP
376
+ def __init__(self, mode, db_filename=None): # initializes SQL database & SpaCy NLP
376
377
  """
377
378
  Initialize the Dynamic-Learning Model (DLM) chatbot.
378
379
 
@@ -380,7 +381,7 @@ class DLM:
380
381
  mode (str): The access mode. Options:
381
382
  'learn' for training mode (to train the bot with queries).
382
383
  'apply' for a trained model to choose between compute and memory mode.
383
- db_filename (str): The SQLite database file used to train and retrieve
384
+ db_filename (str, optional): The SQLite database file used to train and retrieve
384
385
  question-answer-category triples.
385
386
 
386
387
  Behavior:
@@ -410,7 +411,16 @@ class DLM:
410
411
  self.__nlp = DLM._shared_nlp
411
412
  self.__hf_classifier = DLM._shared_hf
412
413
 
413
- self.__filename = db_filename
414
+ if db_filename is None:
415
+ # Create an absolute path to a hidden folder in the user's home directory
416
+ home_dir = os.path.expanduser("~")
417
+ dlm_dir = os.path.join(home_dir, ".dlm")
418
+
419
+ # Ensure the directory exists before SQLite tries to connect
420
+ os.makedirs(dlm_dir, exist_ok=True)
421
+ self.__filename = os.path.join(dlm_dir, "dlm_database.db")
422
+ else:
423
+ self.__filename = db_filename
414
424
  self.__mode = mode
415
425
 
416
426
  try:
@@ -292,11 +292,19 @@ def pick_out_names(self, doc, persons_mentioned, filtered_query):
292
292
  if cleaned:
293
293
  persons_mentioned.append(cleaned)
294
294
 
295
- tokens = nltk.word_tokenize(filtered_query)
295
+ # this is to solve a problematic issue with nltk if a certain package is not already downloaded
296
+ try:
297
+ tokens = nltk.word_tokenize(filtered_query)
298
+ except LookupError:
299
+ # silently download the tokenizer if it is missing
300
+ nltk.download('punkt_tab', quiet=True)
301
+ tokens = nltk.word_tokenize(filtered_query)
302
+
296
303
  for tok in tokens:
297
304
  cleaned = re.sub(r"[^a-zA-Z]", "", tok).lower()
298
305
  if cleaned in self._DLM__nltk_names:
299
306
  persons_mentioned.append(cleaned.capitalize())
307
+
300
308
  persons_mentioned = {name for name in set(persons_mentioned) if len(name.split()) == 1}
301
309
  persons_mentioned = set(persons_mentioned)
302
310
 
@@ -1,5 +1,3 @@
1
- import sqlite3
2
-
3
1
  def get_category(self, exact_question): # returns category as a string or None
4
2
  """
5
3
  Retrieve the category (question type) associated with a specific question from the SQLite knowledge base.
@@ -71,6 +69,7 @@ def get_specific_question(self, exact_answer): # returns question as a string o
71
69
  def learn(self, expectation, category): # no return, void
72
70
  """
73
71
  Store a new question-answer-category entry in the SQLite knowledge base.
72
+ If the question already exists and the trainer gives a new response, it updates the answer and category of that existing question
74
73
 
75
74
  Parameters:
76
75
  expectation (str): The expected answer or response to the current user query.
@@ -88,7 +87,13 @@ def learn(self, expectation, category): # no return, void
88
87
 
89
88
  try:
90
89
  self._DLM__cursor.execute(
91
- "INSERT OR IGNORE INTO knowledge_base (question, answer, category) VALUES (?, ?, ?)",
90
+ """
91
+ INSERT INTO knowledge_base (question, answer, category)
92
+ VALUES (?, ?, ?)
93
+ ON CONFLICT(question) DO UPDATE SET
94
+ answer = excluded.answer,
95
+ category = excluded.category
96
+ """,
92
97
  (self._DLM__special_stripped_query, expectation, category)
93
98
  )
94
99
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dynamic-learning-model
3
- Version: 4.0.5
3
+ Version: 4.0.6
4
4
  Summary: A Dynamic-Learning Model (DLM) chatbot with memory and compute reasoning modes.
5
5
  Author-email: Vignesh Thondikulam <vignesh.tho2006@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dynamic-learning-model"
7
- version = "4.0.5"
7
+ version = "4.0.6"
8
8
  description = "A Dynamic-Learning Model (DLM) chatbot with memory and compute reasoning modes."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"