hamtaa-texttools 1.1.12__py3-none-any.whl → 1.1.13__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hamtaa-texttools
3
- Version: 1.1.12
3
+ Version: 1.1.13
4
4
  Summary: A high-level NLP toolkit built on top of modern LLMs.
5
5
  Author-email: Tohidi <the.mohammad.tohidi@gmail.com>, Montazer <montazerh82@gmail.com>, Givechi <mohamad.m.givechi@gmail.com>, MoosaviNejad <erfanmoosavi84@gmail.com>
6
6
  License: MIT License
@@ -1,4 +1,4 @@
1
- hamtaa_texttools-1.1.12.dist-info/licenses/LICENSE,sha256=Hb2YOBKy2MJQLnyLrX37B4ZVuac8eaIcE71SvVIMOLg,1082
1
+ hamtaa_texttools-1.1.13.dist-info/licenses/LICENSE,sha256=Hb2YOBKy2MJQLnyLrX37B4ZVuac8eaIcE71SvVIMOLg,1082
2
2
  texttools/__init__.py,sha256=EZPPNPafVGvBaxjG9anP0piqH3gAC0DdjdAckQeAgNU,251
3
3
  texttools/batch/batch_config.py,sha256=FCDXy9TfH7xjd1PHvn_CtdwEQSq-YO5sktiaMZEId58,740
4
4
  texttools/batch/batch_runner.py,sha256=zzzVIXedmaq-8fqsFtGRR64F7CtYRLlhQeBu8uMwJQg,9385
@@ -18,12 +18,13 @@ texttools/prompts/text_to_question.yaml,sha256=UheKYpDn6iyKI8NxunHZtFpNyfCLZZe5c
18
18
  texttools/prompts/translate.yaml,sha256=mGT2uBCei6uucWqVbs4silk-UV060v3G0jnt0P6sr50,634
19
19
  texttools/tools/async_tools.py,sha256=60VAAZyVRxI2rKVFFiCnbY--F4kNtVxYQticE0RyhOs,24677
20
20
  texttools/tools/sync_tools.py,sha256=F5TN3KQ_vlF7AC9J0vm2NzjIZC19Ox11tpc9K1SMRwQ,24448
21
- texttools/tools/internals/async_operator.py,sha256=aHXhCweEhyl8uP4qTeccAQOmAxVrThFOmdtgtlChQWs,6804
21
+ texttools/tools/internals/async_operator.py,sha256=9OzF5FFXYrXX1C6ZDbad1zw9A6BZsDQ65jQVrpqTlPw,6961
22
+ texttools/tools/internals/formatters.py,sha256=tACNLP6PeoqaRpNudVxBaHA25zyWqWYPZQuYysIu88g,941
22
23
  texttools/tools/internals/operator_utils.py,sha256=w1k0RJ_W_CRbVc_J2w337VuL-opHpHiCxfhEOwtyuOo,1856
23
24
  texttools/tools/internals/output_models.py,sha256=ekpbyocmXj_dee7ieOT1zOkMo9cPHT7xcUFCZoUaXA0,1886
24
25
  texttools/tools/internals/prompt_loader.py,sha256=4g6-U8kqrGN7VpNaRcrBcnF-h03PXjUDBP0lL0_4EZY,1953
25
- texttools/tools/internals/sync_operator.py,sha256=ar1o5apJgDtQEPLCiGBghS_Y3IXfJMEbXOG9EeS7a9Q,6710
26
- hamtaa_texttools-1.1.12.dist-info/METADATA,sha256=iPj8bakwOVrpkdHe0n2sn36ZjphP1gREP7Ud5Z0uNxU,9179
27
- hamtaa_texttools-1.1.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
- hamtaa_texttools-1.1.12.dist-info/top_level.txt,sha256=5Mh0jIxxZ5rOXHGJ6Mp-JPKviywwN0MYuH0xk5bEWqE,10
29
- hamtaa_texttools-1.1.12.dist-info/RECORD,,
26
+ texttools/tools/internals/sync_operator.py,sha256=zbFLbFvaT9hAdIgpbDv17ljuqqu6ZeIOwCquM4gHTI8,6867
27
+ hamtaa_texttools-1.1.13.dist-info/METADATA,sha256=4qkKZKb9DEb1vx2FMD-xRBDj_LCnDeytl-ea3zMVKdc,9179
28
+ hamtaa_texttools-1.1.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
+ hamtaa_texttools-1.1.13.dist-info/top_level.txt,sha256=5Mh0jIxxZ5rOXHGJ6Mp-JPKviywwN0MYuH0xk5bEWqE,10
30
+ hamtaa_texttools-1.1.13.dist-info/RECORD,,
@@ -6,6 +6,7 @@ from pydantic import BaseModel
6
6
 
7
7
  from texttools.tools.internals.output_models import ToolOutput
8
8
  from texttools.tools.internals.operator_utils import OperatorUtils
9
+ from texttools.tools.internals.formatters import Formatter
9
10
  from texttools.tools.internals.prompt_loader import PromptLoader
10
11
 
11
12
  # Base Model type for output models
@@ -92,6 +93,7 @@ class AsyncOperator:
92
93
  Execute the async LLM pipeline with the given input text. (Async)
93
94
  """
94
95
  prompt_loader = PromptLoader()
96
+ formatter = Formatter()
95
97
  output = ToolOutput()
96
98
 
97
99
  try:
@@ -131,6 +133,8 @@ class AsyncOperator:
131
133
  OperatorUtils.build_user_message(prompt_configs["main_template"])
132
134
  )
133
135
 
136
+ messages = formatter.user_merge_format(messages)
137
+
134
138
  parsed, completion = await self._parse_completion(
135
139
  messages, output_model, temperature, logprobs, top_logprobs
136
140
  )
@@ -0,0 +1,24 @@
1
+ class Formatter:
2
+ @staticmethod
3
+ def user_merge_format(messages: list[dict[str, str]]) -> list[dict[str, str]]:
4
+ """
5
+ Merges consecutive user messages into a single message, separated by newlines.
6
+
7
+ This is useful for condensing a multi-turn user input into a single
8
+ message for the LLM. Assistant and system messages are left unchanged and
9
+ act as separators between user message groups.
10
+ """
11
+ merged: list[dict[str, str]] = []
12
+
13
+ for message in messages:
14
+ role, content = message["role"], message["content"].strip()
15
+
16
+ # Merge with previous user turn
17
+ if merged and role == "user" and merged[-1]["role"] == "user":
18
+ merged[-1]["content"] += "\n" + content
19
+
20
+ # Otherwise, start a new turn
21
+ else:
22
+ merged.append({"role": role, "content": content})
23
+
24
+ return merged
@@ -6,6 +6,7 @@ from pydantic import BaseModel
6
6
 
7
7
  from texttools.tools.internals.output_models import ToolOutput
8
8
  from texttools.tools.internals.operator_utils import OperatorUtils
9
+ from texttools.tools.internals.formatters import Formatter
9
10
  from texttools.tools.internals.prompt_loader import PromptLoader
10
11
 
11
12
  # Base Model type for output models
@@ -92,6 +93,7 @@ class Operator:
92
93
  Execute the LLM pipeline with the given input text.
93
94
  """
94
95
  prompt_loader = PromptLoader()
96
+ formatter = Formatter()
95
97
  output = ToolOutput()
96
98
 
97
99
  try:
@@ -131,6 +133,8 @@ class Operator:
131
133
  OperatorUtils.build_user_message(prompt_configs["main_template"])
132
134
  )
133
135
 
136
+ messages = formatter.user_merge_format(messages)
137
+
134
138
  parsed, completion = self._parse_completion(
135
139
  messages, output_model, temperature, logprobs, top_logprobs
136
140
  )