model-library 0.1.6__py3-none-any.whl → 0.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.
Files changed (48) hide show
  1. model_library/base/base.py +237 -62
  2. model_library/base/delegate_only.py +86 -9
  3. model_library/base/input.py +10 -7
  4. model_library/base/output.py +48 -0
  5. model_library/base/utils.py +56 -7
  6. model_library/config/alibaba_models.yaml +44 -57
  7. model_library/config/all_models.json +253 -126
  8. model_library/config/kimi_models.yaml +30 -3
  9. model_library/config/openai_models.yaml +15 -23
  10. model_library/config/zai_models.yaml +24 -3
  11. model_library/exceptions.py +14 -77
  12. model_library/logging.py +6 -2
  13. model_library/providers/ai21labs.py +30 -14
  14. model_library/providers/alibaba.py +17 -8
  15. model_library/providers/amazon.py +119 -64
  16. model_library/providers/anthropic.py +184 -104
  17. model_library/providers/azure.py +22 -10
  18. model_library/providers/cohere.py +7 -7
  19. model_library/providers/deepseek.py +8 -8
  20. model_library/providers/fireworks.py +7 -8
  21. model_library/providers/google/batch.py +17 -13
  22. model_library/providers/google/google.py +130 -73
  23. model_library/providers/inception.py +7 -7
  24. model_library/providers/kimi.py +18 -8
  25. model_library/providers/minimax.py +30 -13
  26. model_library/providers/mistral.py +61 -35
  27. model_library/providers/openai.py +219 -93
  28. model_library/providers/openrouter.py +34 -0
  29. model_library/providers/perplexity.py +7 -7
  30. model_library/providers/together.py +7 -8
  31. model_library/providers/vals.py +16 -9
  32. model_library/providers/xai.py +157 -144
  33. model_library/providers/zai.py +38 -8
  34. model_library/register_models.py +4 -2
  35. model_library/registry_utils.py +39 -15
  36. model_library/retriers/__init__.py +0 -0
  37. model_library/retriers/backoff.py +73 -0
  38. model_library/retriers/base.py +225 -0
  39. model_library/retriers/token.py +427 -0
  40. model_library/retriers/utils.py +11 -0
  41. model_library/settings.py +1 -1
  42. model_library/utils.py +13 -35
  43. {model_library-0.1.6.dist-info → model_library-0.1.8.dist-info}/METADATA +4 -3
  44. model_library-0.1.8.dist-info/RECORD +70 -0
  45. {model_library-0.1.6.dist-info → model_library-0.1.8.dist-info}/WHEEL +1 -1
  46. model_library-0.1.6.dist-info/RECORD +0 -64
  47. {model_library-0.1.6.dist-info → model_library-0.1.8.dist-info}/licenses/LICENSE +0 -0
  48. {model_library-0.1.6.dist-info → model_library-0.1.8.dist-info}/top_level.txt +0 -0
@@ -1,18 +1,36 @@
1
- from typing import Sequence, TypeVar, cast
1
+ import json
2
+ import re
3
+ from datetime import datetime, timedelta
4
+ from typing import Any, Sequence, TypeVar
5
+
6
+ from pydantic import BaseModel
2
7
 
3
8
  from model_library.base.input import (
4
9
  FileBase,
5
10
  InputItem,
6
- RawInputItem,
11
+ RawInput,
12
+ RawResponse,
7
13
  TextInput,
8
14
  ToolResult,
9
15
  )
10
16
  from model_library.utils import truncate_str
11
- from pydantic import BaseModel
12
17
 
13
18
  T = TypeVar("T", bound=BaseModel)
14
19
 
15
20
 
21
+ def serialize_for_tokenizing(content: Any) -> str:
22
+ """
23
+ Serialize parsed content into a string for tokenization
24
+ """
25
+ parts: list[str] = []
26
+ if content:
27
+ if isinstance(content, str):
28
+ parts.append(content)
29
+ else:
30
+ parts.append(json.dumps(content, default=str))
31
+ return "\n".join(parts)
32
+
33
+
16
34
  def add_optional(
17
35
  a: int | float | T | None, b: int | float | T | None
18
36
  ) -> int | float | T | None:
@@ -54,12 +72,43 @@ def get_pretty_input_types(input: Sequence["InputItem"], verbose: bool = False)
54
72
  return repr(item)
55
73
  case ToolResult():
56
74
  return repr(item)
57
- case dict():
58
- item = cast(RawInputItem, item)
75
+ case RawInput():
59
76
  return repr(item)
60
- case _:
61
- # RawResponse
77
+ case RawResponse():
62
78
  return repr(item)
63
79
 
64
80
  processed_items = [f" {process_item(item)}" for item in input]
65
81
  return "\n" + "\n".join(processed_items) if processed_items else ""
82
+
83
+
84
+ TIME_PATTERN = re.compile(r"^(\d+(?:\.\d+)?)([a-zA-Z]+)$")
85
+ UNIT_TO_SECONDS = {
86
+ "ms": 0.001,
87
+ "s": 1,
88
+ "m": 60,
89
+ "h": 3600,
90
+ }
91
+
92
+
93
+ def to_timestamp(input_str: str, server_now: datetime) -> int:
94
+ """Converts a header string into a server-relative Unix timestamp in ms."""
95
+ input_str = input_str.strip()
96
+
97
+ # ISO Timestamp (e.g. 2026-01-09T21:58:01Z)
98
+ if "T" in input_str and "-" in input_str:
99
+ try:
100
+ dt = datetime.fromisoformat(input_str.replace("Z", "+00:00"))
101
+ return int(dt.timestamp() * 1000)
102
+ except ValueError:
103
+ pass
104
+
105
+ # Duration (e.g. 10s, 6ms)
106
+ match = TIME_PATTERN.match(input_str)
107
+ if match:
108
+ value, unit = match.groups()
109
+ offset_seconds = float(value) * UNIT_TO_SECONDS.get(unit.lower(), 0)
110
+ # Add duration to the SERVER'S provided date
111
+ dt = server_now + timedelta(seconds=offset_seconds)
112
+ return int(dt.timestamp() * 1000)
113
+
114
+ raise ValueError(f"Unsupported time format: {input_str}")
@@ -1,17 +1,51 @@
1
- qwen-models:
2
- base-config:
3
- company: Alibaba
4
- open_source: false
1
+ base-config:
2
+ company: Alibaba
3
+ open_source: false
4
+ supports:
5
+ temperature: true
6
+ metadata:
7
+ available_for_everyone: false
8
+ available_as_evaluator: false
9
+ default_parameters:
10
+ temperature: 0.7
11
+ properties:
12
+ reasoning_model: false
5
13
 
14
+ qwen-3-vl-models:
15
+ base-config:
6
16
  supports:
7
- temperature: true
17
+ images: true
18
+
19
+ alibaba/qwen3-vl-plus-2025-09-23:
20
+ label: Qwen 3 VL Plus
21
+ open_source: true
22
+ description: Qwen 3 VL Plus (2025-09-23)
23
+ release_date: 2025-09-23
8
24
  metadata:
9
- available_for_everyone: false
10
- available_as_evaluator: false
11
- default_parameters:
12
- temperature: 0.7
25
+ deprecated: true
13
26
  properties:
27
+ context_window: 262_144
28
+ max_tokens: 32_768
29
+ training_cutoff: ""
14
30
  reasoning_model: false
31
+ costs_per_million_token:
32
+ input: 0.2
33
+ output: 1.6
34
+
35
+ qwen-3-max-models:
36
+ base-config:
37
+ supports:
38
+ tools: true
39
+ images: false
40
+
41
+ alibaba/qwen3-max-2026-01-23:
42
+ label: Qwen 3 Max Thinking
43
+ description: Qwen 3 Max with enhanced reasoning capabilities
44
+ release_date: 2026-01-23
45
+ properties:
46
+ context_window: 256_000
47
+ max_tokens: 32_000
48
+ reasoning_model: true
15
49
 
16
50
  alibaba/qwen3-max-preview:
17
51
  label: Qwen 3 Max Preview
@@ -20,15 +54,7 @@ qwen-models:
20
54
  properties:
21
55
  context_window: 262_144
22
56
  max_tokens: 65_536
23
- training_cutoff: ""
24
- costs_per_million_token:
25
- input: 1.2
26
- output: 6
27
- supports:
28
- images: false
29
- tools: true
30
- metadata:
31
- available_for_everyone: false
57
+ reasoning_model: true
32
58
 
33
59
  alibaba/qwen3-max-2025-09-23:
34
60
  label: Qwen 3 Max 2025-09-23
@@ -39,14 +65,6 @@ qwen-models:
39
65
  max_tokens: 65_536
40
66
  training_cutoff: ""
41
67
  reasoning_model: true
42
- costs_per_million_token:
43
- input: 1.2
44
- output: 6
45
- supports:
46
- images: false
47
- tools: true
48
- metadata:
49
- available_for_everyone: false
50
68
 
51
69
  alibaba/qwen3-max:
52
70
  label: Qwen 3 Max
@@ -57,34 +75,3 @@ qwen-models:
57
75
  max_tokens: 65_536
58
76
  training_cutoff: ""
59
77
  reasoning_model: false
60
- costs_per_million_token:
61
- input: 1.2
62
- output: 6
63
- cache:
64
- read_discount: 0.8
65
- write_markup: 1
66
- context:
67
- threshold: 32_000
68
- input: 2.4
69
- output: 12
70
- supports:
71
- images: false
72
- tools: true
73
- metadata:
74
- available_for_everyone: false
75
-
76
- alibaba/qwen3-vl-plus-2025-09-23:
77
- label: Qwen 3 VL Plus
78
- open_source: true
79
- description: Qwen 3 VL Plus (2025-09-23)
80
- release_date: 2025-09-23
81
- properties:
82
- context_window: 262_144
83
- max_tokens: 32_768
84
- training_cutoff: ""
85
- reasoning_model: false
86
- costs_per_million_token:
87
- input: 0.2
88
- output: 1.6
89
- supports:
90
- images: true