speedy-utils 1.1.6__py3-none-any.whl → 1.1.8__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.
llm_utils/__init__.py CHANGED
@@ -10,7 +10,6 @@ from .chat_format import (
10
10
  transform_messages_to_chatml,
11
11
  )
12
12
  from .lm.async_lm import AsyncLLMTask, AsyncLM
13
- from .lm.sync_lm import LM, LLMTask
14
13
 
15
14
  __all__ = [
16
15
  "transform_messages",
@@ -21,10 +20,7 @@ __all__ = [
21
20
  "display_conversations",
22
21
  "build_chatml_input",
23
22
  "format_msgs",
24
- # "group_messages_by_len",
25
- "LM",
26
- "AsyncLM",
27
23
  "display_chat_messages_as_html",
28
- "LLMTask",
24
+ "AsyncLM",
29
25
  "AsyncLLMTask",
30
26
  ]
@@ -16,9 +16,9 @@ def identify_format(item):
16
16
  def _transform_sharegpt_to_chatml(
17
17
  item, default_system_message="You are a helpful assistant.", print_msg=False
18
18
  ):
19
- assert isinstance(
20
- item, dict
21
- ), "The item is not in the correct format. Please check the format of the item."
19
+ assert isinstance(item, dict), (
20
+ "The item is not in the correct format. Please check the format of the item."
21
+ )
22
22
 
23
23
  messages = []
24
24
  system_msg = item.get("system", "")
@@ -116,16 +116,16 @@ def transform_messages_to_chatml(input_data, input_format="auto"):
116
116
  input_data = deepcopy(input_data)
117
117
  if isinstance(input_data, list):
118
118
  input_format = "chatlm"
119
- assert (
120
- input_data[0].get("role") is not None
121
- ), "The input format is not recognized. Please specify the input format."
119
+ assert input_data[0].get("role") is not None, (
120
+ "The input format is not recognized. Please specify the input format."
121
+ )
122
122
  elif isinstance(input_data, dict):
123
123
  input_data = _transform_sharegpt_to_chatml(input_data)
124
124
  input_format = "sharegpt"
125
125
  elif isinstance(input_data, str):
126
- assert (
127
- "<|im_end|>" in input_data
128
- ), "The input format is not recognized. Please specify the input format."
126
+ assert "<|im_end|>" in input_data, (
127
+ "The input format is not recognized. Please specify the input format."
128
+ )
129
129
  input_format = "chatlm"
130
130
  parts = input_data.split("<|im_end|>")
131
131
  input_data = []
@@ -76,7 +76,7 @@ def group_messages_by_len(
76
76
  """
77
77
  if messages is None:
78
78
  raise ValueError("messages parameter cannot be None")
79
- from transformers.models.auto.tokenization_auto import AutoTokenizer # type: ignore
79
+ from transformers.models.auto.tokenization_auto import AutoTokenizer # type: ignore
80
80
 
81
81
  tokenizer = AutoTokenizer.from_pretrained(model_name)
82
82
 
@@ -1,2 +1,7 @@
1
+ from .async_llm_task import AsyncLLMTask
1
2
  from .async_lm import AsyncLM
2
- from .async_llm_task import AsyncLLMTask
3
+
4
+ __all__ = [
5
+ "AsyncLM",
6
+ "AsyncLLMTask",
7
+ ]
@@ -48,13 +48,17 @@ def _yellow(t):
48
48
  return _color(33, t)
49
49
 
50
50
 
51
- TParsed = TypeVar("TParsed", bound=BaseModel)
51
+ # TParsed = TypeVar("TParsed", bound=BaseModel)
52
52
 
53
+ InputModelType = TypeVar("InputModelType", bound=BaseModel)
54
+ OutputModelType = TypeVar("OutputModelType", bound=BaseModel)
53
55
 
54
- class ParsedOutput(TypedDict, Generic[TParsed]):
56
+
57
+ class ParsedOutput(TypedDict, Generic[OutputModelType]):
55
58
  messages: List
56
59
  completion: Any
57
- parsed: TParsed
60
+ parsed: OutputModelType
61
+ model_kwargs: Dict[str, Any]
58
62
 
59
63
 
60
64
  # --------------------------------------------------------------------------- #
@@ -185,7 +189,6 @@ __all__ = [
185
189
  "Messages",
186
190
  "LegacyMsgs",
187
191
  "RawMsgs",
188
- "TParsed",
189
192
  "ParsedOutput",
190
193
  "get_tokenizer",
191
194
  "inspect_word_probs_async",