unique_toolkit 0.8.50__py3-none-any.whl → 0.8.52__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.
- unique_toolkit/_common/token/token_counting.py +26 -6
- {unique_toolkit-0.8.50.dist-info → unique_toolkit-0.8.52.dist-info}/METADATA +7 -1
- {unique_toolkit-0.8.50.dist-info → unique_toolkit-0.8.52.dist-info}/RECORD +5 -5
- {unique_toolkit-0.8.50.dist-info → unique_toolkit-0.8.52.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.8.50.dist-info → unique_toolkit-0.8.52.dist-info}/WHEEL +0 -0
@@ -71,11 +71,25 @@ def num_tokens_per_messages(
|
|
71
71
|
for message in messages:
|
72
72
|
num_tokens = 3 # extra_tokens_per_message
|
73
73
|
for key, value in message.items():
|
74
|
-
if
|
74
|
+
if key == "content":
|
75
|
+
if message.get("role") == "tool":
|
76
|
+
"""
|
77
|
+
We have observed a general difference in the way tool response messages are handled.
|
78
|
+
Specifically, if we take a list of tool responses and artificially transform them into user messages (content field stays the same)
|
79
|
+
the token consumption goes does drastically, this seems to scale with the number of tokens in the tool responses.
|
80
|
+
|
81
|
+
the json.dumps() method was found by trial and error. It will give a conservative estimate, but seems to be close to the token count
|
82
|
+
returned from the openai call.
|
83
|
+
"""
|
84
|
+
num_tokens += len(encode(json.dumps(value)))
|
85
|
+
elif isinstance(value, list):
|
86
|
+
# NOTE: The result returned by the function below is not 100% accurate.
|
87
|
+
num_tokens += handle_message_with_images(value, encode)
|
88
|
+
else:
|
89
|
+
num_tokens += len(encode(value))
|
90
|
+
elif isinstance(value, str):
|
75
91
|
num_tokens += len(encode(value))
|
76
|
-
|
77
|
-
# NOTE: The result returned by the function below is not 100% accurate.
|
78
|
-
num_tokens += handle_message_with_images(value, encode)
|
92
|
+
|
79
93
|
if key == "name":
|
80
94
|
num_tokens += 1 # extra_tokens_per_name
|
81
95
|
|
@@ -163,8 +177,14 @@ def messages_to_openai_messages(
|
|
163
177
|
messages = LanguageModelMessages(messages)
|
164
178
|
|
165
179
|
return [
|
166
|
-
{
|
167
|
-
|
180
|
+
{
|
181
|
+
k: v
|
182
|
+
for k, v in m.items()
|
183
|
+
if (
|
184
|
+
k in ["content", "role", "name"] and v is not None
|
185
|
+
) # Ignore tool_calls for now
|
186
|
+
}
|
187
|
+
for m in messages.model_dump(mode="json")
|
168
188
|
]
|
169
189
|
|
170
190
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: unique_toolkit
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.52
|
4
4
|
Summary:
|
5
5
|
License: Proprietary
|
6
6
|
Author: Cedric Klinkert
|
@@ -118,6 +118,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
118
118
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
119
119
|
|
120
120
|
|
121
|
+
## [0.8.52] - 2025-09-06
|
122
|
+
- Fix import error in token counting
|
123
|
+
|
124
|
+
## [0.8.51] - 2025-09-06
|
125
|
+
- Update token counter to latest version of monorepo.
|
126
|
+
|
121
127
|
## [0.8.50] - 2025-09-08
|
122
128
|
- Minor fix in documentation
|
123
129
|
- Updated examples
|
@@ -14,7 +14,7 @@ unique_toolkit/_common/exception.py,sha256=caQIE1btsQnpKCHqL2cgWUSbHup06enQu_Pt7
|
|
14
14
|
unique_toolkit/_common/feature_flags/schema.py,sha256=3JpTuld8kK-UQ5B0sbYTu0yqhyFPnChXG2Iv4BNqHdg,539
|
15
15
|
unique_toolkit/_common/pydantic_helpers.py,sha256=4a8LPey31k4dCztYag1OBhYnGHREN08-l3NEjbFD1ok,743
|
16
16
|
unique_toolkit/_common/token/image_token_counting.py,sha256=VpFfZyY0GIH27q_Wy4YNjk2algqvbCtJyzuuROoFQPw,2189
|
17
|
-
unique_toolkit/_common/token/token_counting.py,sha256=
|
17
|
+
unique_toolkit/_common/token/token_counting.py,sha256=gM4B_aUqKqEPvmStFNcvCWNMNNNNKbVaywBDxlbgIps,7121
|
18
18
|
unique_toolkit/_common/utils/structured_output/schema.py,sha256=Tp7kDYcmKtnUhcuRkH86TSYhylRff0ZZJYb2dLkISts,131
|
19
19
|
unique_toolkit/_common/validate_required_values.py,sha256=Y_M1ub9gIKP9qZ45F6Zq3ZHtuIqhmOjl8Z2Vd3avg8w,588
|
20
20
|
unique_toolkit/_common/validators.py,sha256=aZwbMho7XszN7lT5RtemaiXgC0WJ4u40oeVgsNGhF4U,2803
|
@@ -118,7 +118,7 @@ unique_toolkit/tools/utils/execution/execution.py,sha256=vjG2Y6awsGNtlvyQAGCTthQ
|
|
118
118
|
unique_toolkit/tools/utils/source_handling/schema.py,sha256=vzAyf6ZWNexjMO0OrnB8y2glGkvAilmGGQXd6zcDaKw,870
|
119
119
|
unique_toolkit/tools/utils/source_handling/source_formatting.py,sha256=C7uayNbdkNVJdEARA5CENnHtNY1SU6etlaqbgHNyxaQ,9152
|
120
120
|
unique_toolkit/tools/utils/source_handling/tests/test_source_formatting.py,sha256=oM5ZxEgzROrnX1229KViCAFjRxl9wCTzWZoinYSHleM,6979
|
121
|
-
unique_toolkit-0.8.
|
122
|
-
unique_toolkit-0.8.
|
123
|
-
unique_toolkit-0.8.
|
124
|
-
unique_toolkit-0.8.
|
121
|
+
unique_toolkit-0.8.52.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
|
122
|
+
unique_toolkit-0.8.52.dist-info/METADATA,sha256=J8YuIbp62ytep2HtiI5cgDpbQGKNxsiys_xMAdUEZEg,31321
|
123
|
+
unique_toolkit-0.8.52.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
124
|
+
unique_toolkit-0.8.52.dist-info/RECORD,,
|
File without changes
|
File without changes
|