tokenator 0.1.10__tar.gz → 0.1.11__tar.gz
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.
- {tokenator-0.1.10 → tokenator-0.1.11}/PKG-INFO +57 -4
- {tokenator-0.1.10 → tokenator-0.1.11}/README.md +55 -2
- {tokenator-0.1.10 → tokenator-0.1.11}/pyproject.toml +1 -1
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/anthropic/client_anthropic.py +0 -1
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/base_wrapper.py +1 -1
- {tokenator-0.1.10 → tokenator-0.1.11}/LICENSE +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/__init__.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/anthropic/stream_interceptors.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/create_migrations.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/migrations/env.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/migrations/script.py.mako +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/migrations/versions/f6f1f2437513_initial_migration.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/migrations.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/models.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/openai/client_openai.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/openai/stream_interceptors.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/schemas.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/usage.py +0 -0
- {tokenator-0.1.10 → tokenator-0.1.11}/src/tokenator/utils.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: tokenator
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.11
|
4
4
|
Summary: Token usage tracking wrapper for LLMs
|
5
5
|
License: MIT
|
6
6
|
Author: Ujjwal Maheshwari
|
@@ -20,12 +20,12 @@ Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
20
20
|
Requires-Dist: sqlalchemy (>=2.0.0,<3.0.0)
|
21
21
|
Description-Content-Type: text/markdown
|
22
22
|
|
23
|
-
# Tokenator :
|
23
|
+
# Tokenator : Track and analyze LLM token usage and cost
|
24
24
|
|
25
25
|
Have you ever wondered about :
|
26
26
|
- How many tokens does your AI agent consume?
|
27
27
|
- How much does it cost to do run a complex AI workflow with multiple LLM providers?
|
28
|
-
- How much money did
|
28
|
+
- How much money/tokens did you spend today on developing with LLMs?
|
29
29
|
|
30
30
|
Afraid not, tokenator is here! With tokenator's easy to use API, you can start tracking LLM usage in a matter of minutes.
|
31
31
|
|
@@ -57,6 +57,9 @@ response = client.chat.completions.create(
|
|
57
57
|
)
|
58
58
|
```
|
59
59
|
|
60
|
+
Works with AsyncOpenAI and `streaming=True` as well!
|
61
|
+
Note : When streaming, don't forget to add `stream_options={"include_usage": True}` to the `create()` call!
|
62
|
+
|
60
63
|
### Cost Analysis
|
61
64
|
|
62
65
|
```python
|
@@ -120,6 +123,56 @@ print(cost.last_hour().model_dump_json(indent=4))
|
|
120
123
|
- Minimal memory footprint
|
121
124
|
- Minimal latency footprint
|
122
125
|
|
126
|
+
### Anthropic
|
127
|
+
|
128
|
+
```python
|
129
|
+
from anthropic import Anthropic, AsyncAnthropic
|
130
|
+
from tokenator import tokenator_anthropic
|
131
|
+
|
132
|
+
anthropic_client = AsyncAnthropic(api_key="your-api-key")
|
133
|
+
|
134
|
+
# Wrap it with Tokenator
|
135
|
+
client = tokenator_anthropic(anthropic_client)
|
136
|
+
|
137
|
+
# Use it exactly like the Anthropic client
|
138
|
+
response = await client.messages.create(
|
139
|
+
model="claude-3-5-haiku-20241022",
|
140
|
+
messages=[{"role": "user", "content": "hello how are you"}],
|
141
|
+
max_tokens=20,
|
142
|
+
)
|
143
|
+
|
144
|
+
print(response)
|
145
|
+
|
146
|
+
print(usage.last_execution().model_dump_json(indent=4))
|
147
|
+
"""
|
148
|
+
{
|
149
|
+
"total_cost": 0.0001,
|
150
|
+
"total_tokens": 23,
|
151
|
+
"prompt_tokens": 10,
|
152
|
+
"completion_tokens": 13,
|
153
|
+
"providers": [
|
154
|
+
{
|
155
|
+
"total_cost": 0.0001,
|
156
|
+
"total_tokens": 23,
|
157
|
+
"prompt_tokens": 10,
|
158
|
+
"completion_tokens": 13,
|
159
|
+
"provider": "anthropic",
|
160
|
+
"models": [
|
161
|
+
{
|
162
|
+
"total_cost": 0.0004,
|
163
|
+
"total_tokens": 79,
|
164
|
+
"prompt_tokens": 52,
|
165
|
+
"completion_tokens": 27,
|
166
|
+
"model": "claude-3-5-haiku-20241022"
|
167
|
+
}
|
168
|
+
]
|
169
|
+
}
|
170
|
+
]
|
171
|
+
}
|
172
|
+
"""
|
173
|
+
```
|
174
|
+
---
|
175
|
+
|
123
176
|
Most importantly, none of your data is ever sent to any server.
|
124
177
|
|
125
178
|
## License
|
@@ -1,9 +1,9 @@
|
|
1
|
-
# Tokenator :
|
1
|
+
# Tokenator : Track and analyze LLM token usage and cost
|
2
2
|
|
3
3
|
Have you ever wondered about :
|
4
4
|
- How many tokens does your AI agent consume?
|
5
5
|
- How much does it cost to do run a complex AI workflow with multiple LLM providers?
|
6
|
-
- How much money did
|
6
|
+
- How much money/tokens did you spend today on developing with LLMs?
|
7
7
|
|
8
8
|
Afraid not, tokenator is here! With tokenator's easy to use API, you can start tracking LLM usage in a matter of minutes.
|
9
9
|
|
@@ -35,6 +35,9 @@ response = client.chat.completions.create(
|
|
35
35
|
)
|
36
36
|
```
|
37
37
|
|
38
|
+
Works with AsyncOpenAI and `streaming=True` as well!
|
39
|
+
Note : When streaming, don't forget to add `stream_options={"include_usage": True}` to the `create()` call!
|
40
|
+
|
38
41
|
### Cost Analysis
|
39
42
|
|
40
43
|
```python
|
@@ -98,6 +101,56 @@ print(cost.last_hour().model_dump_json(indent=4))
|
|
98
101
|
- Minimal memory footprint
|
99
102
|
- Minimal latency footprint
|
100
103
|
|
104
|
+
### Anthropic
|
105
|
+
|
106
|
+
```python
|
107
|
+
from anthropic import Anthropic, AsyncAnthropic
|
108
|
+
from tokenator import tokenator_anthropic
|
109
|
+
|
110
|
+
anthropic_client = AsyncAnthropic(api_key="your-api-key")
|
111
|
+
|
112
|
+
# Wrap it with Tokenator
|
113
|
+
client = tokenator_anthropic(anthropic_client)
|
114
|
+
|
115
|
+
# Use it exactly like the Anthropic client
|
116
|
+
response = await client.messages.create(
|
117
|
+
model="claude-3-5-haiku-20241022",
|
118
|
+
messages=[{"role": "user", "content": "hello how are you"}],
|
119
|
+
max_tokens=20,
|
120
|
+
)
|
121
|
+
|
122
|
+
print(response)
|
123
|
+
|
124
|
+
print(usage.last_execution().model_dump_json(indent=4))
|
125
|
+
"""
|
126
|
+
{
|
127
|
+
"total_cost": 0.0001,
|
128
|
+
"total_tokens": 23,
|
129
|
+
"prompt_tokens": 10,
|
130
|
+
"completion_tokens": 13,
|
131
|
+
"providers": [
|
132
|
+
{
|
133
|
+
"total_cost": 0.0001,
|
134
|
+
"total_tokens": 23,
|
135
|
+
"prompt_tokens": 10,
|
136
|
+
"completion_tokens": 13,
|
137
|
+
"provider": "anthropic",
|
138
|
+
"models": [
|
139
|
+
{
|
140
|
+
"total_cost": 0.0004,
|
141
|
+
"total_tokens": 79,
|
142
|
+
"prompt_tokens": 52,
|
143
|
+
"completion_tokens": 27,
|
144
|
+
"model": "claude-3-5-haiku-20241022"
|
145
|
+
}
|
146
|
+
]
|
147
|
+
}
|
148
|
+
]
|
149
|
+
}
|
150
|
+
"""
|
151
|
+
```
|
152
|
+
---
|
153
|
+
|
101
154
|
Most importantly, none of your data is ever sent to any server.
|
102
155
|
|
103
156
|
## License
|
@@ -71,7 +71,6 @@ def _create_usage_callback(execution_id, log_usage_fn):
|
|
71
71
|
usage_data.usage.prompt_tokens += chunk.message.usage.input_tokens
|
72
72
|
usage_data.usage.completion_tokens += chunk.message.usage.output_tokens
|
73
73
|
elif isinstance(chunk, RawMessageDeltaEvent):
|
74
|
-
usage_data.usage.prompt_tokens += chunk.usage.input_tokens
|
75
74
|
usage_data.usage.completion_tokens += chunk.usage.output_tokens
|
76
75
|
|
77
76
|
usage_data.usage.total_tokens = usage_data.usage.prompt_tokens + usage_data.usage.completion_tokens
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|