aicmo 0.0.2__py3-none-any.whl → 0.0.3__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.
aicmo/__init__.py
CHANGED
|
@@ -198,25 +198,34 @@ class AICMOClient:
|
|
|
198
198
|
self,
|
|
199
199
|
data: types.chat.chat_completion.ChatCompletion,
|
|
200
200
|
model: str,
|
|
201
|
-
tokens: dict
|
|
201
|
+
tokens: dict,
|
|
202
|
+
use_openrouter: bool=True
|
|
202
203
|
) -> dict:
|
|
203
204
|
"""
|
|
204
205
|
Calculate the token usage and cost.
|
|
205
206
|
"""
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
tokens[
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
207
|
+
if use_openrouter:
|
|
208
|
+
tokens['total_cost'] += data.usage.cost
|
|
209
|
+
tokens['input_cost'] += data.usage.cost_details['upstream_inference_prompt_cost']
|
|
210
|
+
tokens['output_cost'] += data.usage.cost_details['upstream_inference_completions_cost']
|
|
211
|
+
tokens["prompt_tokens"] += data.usage.prompt_tokens
|
|
212
|
+
tokens["completion_tokens"] += data.usage.completion_tokens
|
|
213
|
+
tokens["total_tokens"] += data.usage.total_tokens
|
|
214
|
+
else:
|
|
215
|
+
prompt_tokens = data.usage.prompt_tokens
|
|
216
|
+
completion_tokens = data.usage.completion_tokens
|
|
217
|
+
cost = self.COST.get('openai', {}).get("texts", {}).get(model, {})
|
|
218
|
+
openai_input_cost = cost.get('input', None)
|
|
219
|
+
openai_output_cost = cost.get('output', None)
|
|
220
|
+
if openai_input_cost and openai_output_cost:
|
|
221
|
+
tokens['input_cost'] += prompt_tokens * openai_input_cost
|
|
222
|
+
tokens['output_cost'] += completion_tokens * openai_output_cost
|
|
223
|
+
tokens['total_cost'] = round(tokens['input_cost'] + tokens['output_cost'], 4)
|
|
224
|
+
tokens['prompt_tokens'] += prompt_tokens
|
|
225
|
+
tokens['completion_tokens'] += completion_tokens
|
|
226
|
+
tokens['total_tokens'] += prompt_tokens + completion_tokens
|
|
227
|
+
tokens['openai_input_cost'] = openai_input_cost
|
|
228
|
+
tokens['openai_output_cost'] = openai_output_cost
|
|
220
229
|
return tokens
|
|
221
230
|
|
|
222
231
|
def s3_upload_pickle(
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
aicmo/__init__.py,sha256=mpBZRf4wGqigidr8cLuMW2Z20sWmAhmf3Sduv4zpK5Y,34310
|
|
2
|
+
aicmo-0.0.3.dist-info/METADATA,sha256=R28YKWI7HOuJuJiJPwPOkObVQ4PFK4HpkRocsDT0p7M,1187
|
|
3
|
+
aicmo-0.0.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
4
|
+
aicmo-0.0.3.dist-info/top_level.txt,sha256=uqMJv53xrmaqWkkPb9xI38tTYnSuPoplqyCzyKygG60,6
|
|
5
|
+
aicmo-0.0.3.dist-info/RECORD,,
|
aicmo-0.0.2.dist-info/RECORD
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
aicmo/__init__.py,sha256=4hgGmwqW9btLI6Ik3prZSJ0JrC0jHv0LOEZA1aOns_c,33730
|
|
2
|
-
aicmo-0.0.2.dist-info/METADATA,sha256=PIStOBiJ79wqhgAXEffY0lqcGc4xWyfTi1KGUrkJIQI,1187
|
|
3
|
-
aicmo-0.0.2.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
4
|
-
aicmo-0.0.2.dist-info/top_level.txt,sha256=uqMJv53xrmaqWkkPb9xI38tTYnSuPoplqyCzyKygG60,6
|
|
5
|
-
aicmo-0.0.2.dist-info/RECORD,,
|
|
File without changes
|