hamtaa-texttools 0.1.43__py3-none-any.whl → 0.1.44__py3-none-any.whl

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.

Potentially problematic release.


This version of hamtaa-texttools might be problematic. Click here for more details.

@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hamtaa-texttools
3
- Version: 0.1.43
3
+ Version: 0.1.44
4
4
  Summary: A set of high-level NLP tools
5
5
  Author: Tohidi, Montazer, Givechi, Mousavinezhad
6
6
  Requires-Python: >=3.8
7
7
  Description-Content-Type: text/markdown
8
- Requires-Dist: openai==1.97.1
9
- Requires-Dist: numpy==1.26.4
8
+ Requires-Dist: openai>=1.97.0
9
+ Requires-Dist: numpy>=1.26.4
10
10
 
11
11
  # Text Tools
12
12
 
@@ -20,7 +20,7 @@ Requires-Dist: numpy==1.26.4
20
20
  </p>
21
21
 
22
22
 
23
- ### How to Install
23
+ ## How to Install
24
24
 
25
25
  Install the package using:
26
26
 
@@ -16,7 +16,7 @@ texttools/batch_manager/batch_manager.py,sha256=jAmKskL3OTYwwsO1mWsWAB3VxMlOF07c
16
16
  texttools/batch_manager/batch_runner.py,sha256=kW0IPauI11xpssApMA7b4XI19FePImywym3V7tBaa-o,7404
17
17
  texttools/formatter/__init__.py,sha256=KHz2tFZctbit_HVbQNCTMi46JzmKlg-uB6Ost63IpVU,46
18
18
  texttools/formatter/base.py,sha256=0fiM6E7NdJevAVpL6yyPaUZVJGKWxE3fr-Ay1oqgJqQ,879
19
- texttools/formatter/gemma3_formatter.py,sha256=c7YRj6fIPqhs_nvnSbWRTuguRoNQJvuIvk_bcaVDioM,1634
19
+ texttools/formatter/gemma3_formatter.py,sha256=AmdKBYLj6HMsI2DDX4KHNEEVYJmz_VVNUBOv8ScGjsY,1865
20
20
  texttools/handlers/__init__.py,sha256=sv0JloipQ57AI0xo-3w9k6cK5rYjZP3ltR2EbBhkHTA,121
21
21
  texttools/handlers/handlers.py,sha256=LtC4FBuzRUDy3Jw-Fp21WR-QS1jOcDhsGaMPFQGjfTw,2381
22
22
  texttools/handlers/categorizer/__init__.py,sha256=mE05vt_ma6vcP8pQ37BZ85WVQ8jhcjDS0iZV81_LFCY,127
@@ -35,7 +35,7 @@ texttools/tools/merger/gemma_question_merger.py,sha256=JAC-52kBbabIzEWp0MFi9viiu
35
35
  texttools/tools/ner/__init__.py,sha256=BW84BcItel6Mc2JlaDL6qvAktVMkti67VXceeCnOB1g,70
36
36
  texttools/tools/ner/gemma_ner_extractor.py,sha256=YhyIwX_8bdwkFb4gY8g9mZdYHW_r1jCvbmjjNCK9Wfo,5384
37
37
  texttools/tools/question_detector/__init__.py,sha256=ulArGttooSoxEe0vUDQSxUQrnsxr7gH9l-LjSER2dVI,162
38
- texttools/tools/question_detector/gemma_detector.py,sha256=dHWHcthjMArW42CNPGmk3Xbj1AxjM33A34dOmLUA64U,4141
38
+ texttools/tools/question_detector/gemma_detector.py,sha256=DhlCAA6Hws_OTuYil6UY4sYlbjdQQU6EqHdoTl3a--w,3772
39
39
  texttools/tools/question_detector/llm_detector.py,sha256=zo89eh359hqQGGf83-6M22AaiH7q-m0m91SjTyxZaYs,3862
40
40
  texttools/tools/question_generator/__init__.py,sha256=EAElpB_YeyMoBqvFNjbW2a_j18SLtiKQ7sRmdS58Fww,61
41
41
  texttools/tools/question_generator/gemma_question_generator.py,sha256=V5QcXmHZ5shTvrThOxUrKJ4FqP0P58NIJbsPdyyy5IM,6744
@@ -54,7 +54,7 @@ texttools/tools/summarizer/gemma_summarizer.py,sha256=ikhsBv7AiZD1dT_d12AyjXxojz
54
54
  texttools/tools/summarizer/llm_summerizer.py,sha256=-0rUKbSnl1aDeBfJ5DCSbIlwd2k-9qIaCKgoQJa0hWc,3412
55
55
  texttools/tools/translator/__init__.py,sha256=KO1m08J2BZwRqBGO9ICB4l4cnH1jfHLHL5HbgYFUWM8,72
56
56
  texttools/tools/translator/gemma_translator.py,sha256=57NMfJAZHQjZSr_eCBePE_Pnag8pu3O00Jicxhzn6Jc,7572
57
- hamtaa_texttools-0.1.43.dist-info/METADATA,sha256=GjVLyZZclY4hp29Yd1DpRtqvFDmTAGOoYEOI-FFvbA0,1482
58
- hamtaa_texttools-0.1.43.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
59
- hamtaa_texttools-0.1.43.dist-info/top_level.txt,sha256=5Mh0jIxxZ5rOXHGJ6Mp-JPKviywwN0MYuH0xk5bEWqE,10
60
- hamtaa_texttools-0.1.43.dist-info/RECORD,,
57
+ hamtaa_texttools-0.1.44.dist-info/METADATA,sha256=OImC1zmuJh7p8SY3s3mhm8poOzYOuuqx6vjOeDy5O3k,1481
58
+ hamtaa_texttools-0.1.44.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
59
+ hamtaa_texttools-0.1.44.dist-info/top_level.txt,sha256=5Mh0jIxxZ5rOXHGJ6Mp-JPKviywwN0MYuH0xk5bEWqE,10
60
+ hamtaa_texttools-0.1.44.dist-info/RECORD,,
@@ -1,5 +1,3 @@
1
- from typing import Literal
2
-
3
1
  from texttools.formatter.base import ChatFormatter
4
2
 
5
3
 
@@ -10,14 +8,13 @@ class Gemma3Formatter(ChatFormatter):
10
8
  """
11
9
 
12
10
  ROLE = "role"
11
+ CONTENT = "content"
13
12
  USER_ROLE = "user"
14
13
  ASSISTANT_ROLE = "assistant"
15
- CONTENT = "content"
16
14
  VALID_ROLES = {USER_ROLE, ASSISTANT_ROLE}
15
+ VALID_KEYS = {ROLE, CONTENT}
17
16
 
18
- def format(
19
- self, messages: list[dict[Literal["role", "content"], str]]
20
- ) -> list[dict[str, str]]:
17
+ def format(self, messages: list[dict[str, str]]) -> list[dict[str, str]]:
21
18
  """
22
19
  :param messages: list of {"role": ..., "content": ...}, where role is "user", "assistant", or "system"
23
20
  :return: a new list where consecutive "user" messages are merged into single entries
@@ -25,14 +22,20 @@ class Gemma3Formatter(ChatFormatter):
25
22
 
26
23
  merged: list[dict[str, str]] = []
27
24
 
28
- for msg in messages:
29
- role, content = msg[self.ROLE], msg[self.CONTENT].strip()
25
+ for message in messages:
26
+ # Validate keys strictly
27
+ if set(message.keys()) != self.VALID_KEYS:
28
+ raise ValueError(
29
+ f"Message dict keys must be exactly {self.VALID_KEYS}, got {set(message.keys())}"
30
+ )
31
+
32
+ role, content = message[self.ROLE], message[self.CONTENT].strip()
30
33
 
31
34
  # Replace "system" role with "user" role
32
35
  if role == "system":
33
36
  role = self.USER_ROLE
34
37
 
35
- # Raise value error if msg["role"] wan't a valid role
38
+ # Raise value error if message["role"] wan't a valid role
36
39
  if role not in self.VALID_ROLES:
37
40
  raise ValueError(f"Unexpected role: {role}")
38
41
 
@@ -36,64 +36,48 @@ class GemmaQuestionDetector(BaseQuestionDetector):
36
36
  self.model = model
37
37
  self.temperature = temperature
38
38
  self.client_kwargs = client_kwargs
39
-
40
39
  self.chat_formatter = chat_formatter or Gemma3Formatter()
41
-
42
40
  self.use_reason = use_reason
43
41
  self.prompt_template = prompt_template
44
42
 
45
- self.json_schema = {"is_question": bool}
46
-
47
43
  def _build_messages(self, text: str, reason: str = None) -> list[dict[str, str]]:
48
- clean = self.preprocess(text)
49
- schema_instr = f"respond only in JSON format: {self.json_schema}"
44
+ clean_text = self.preprocess(text)
50
45
  messages: list[dict[str, str]] = []
51
46
 
52
47
  if reason:
53
48
  messages.append({"role": "user", "content": reason})
54
49
 
55
- messages.append({"role": "user", "content": schema_instr})
56
50
  if self.prompt_template:
57
51
  messages.append({"role": "user", "content": self.prompt_template})
58
- messages.append({"role": "user", "content": clean})
52
+ messages.append({"role": "user", "content": clean_text})
59
53
 
60
- # this line will restructure the messages
61
- # based on the formatter that we provided
62
- # some models will require custom settings
54
+ # Restructure the messages based on the formatter; some models will require custom settings
63
55
  restructured = self.chat_formatter.format(messages=messages)
64
56
 
65
57
  return restructured
66
58
 
67
59
  def _reason(self, text: str) -> list:
68
- messages = [
69
- {
70
- "role": "user",
71
- "content": """
72
- we want to analyze this text snippet to see if it contains any question
73
- or request of some kind or not
74
- read the text, and reason about it being a request or not
75
- summerized
76
- short answer
77
- """,
78
- },
79
- {
80
- "role": "user",
81
- "content": f"""
60
+ reason_prompt = f"""
61
+ We want to analyze this text snippet to see if it contains any question
62
+ or request of some kind or not.
63
+ Read the text, and reason about it being a request or not.
64
+ Summerized, Short answer
82
65
  {text}
83
- """,
84
- },
66
+ """
67
+ messages = [
68
+ {"role": "user", "content": reason_prompt},
85
69
  ]
86
70
 
87
71
  restructured = self.chat_formatter.format(messages=messages)
88
72
 
89
- resp = self.client.chat.completions.create(
73
+ response = self.client.chat.completions.create(
90
74
  model=self.model,
91
75
  messages=restructured,
92
76
  temperature=self.temperature,
93
77
  **self.client_kwargs,
94
78
  )
95
79
 
96
- reason = resp.choices[0].message.content.strip()
80
+ reason = response.choices[0].message.content.strip()
97
81
  return reason
98
82
 
99
83
  def detect(self, text: str) -> bool:
@@ -125,6 +109,6 @@ class GemmaQuestionDetector(BaseQuestionDetector):
125
109
  f"Failed to parse the response. Raw content: {message.content}"
126
110
  )
127
111
 
128
- # dispatch and return
112
+ # Dispatch and return
129
113
  self._dispatch({"question": text, "result": result})
130
114
  return result