aicmo 0.0.2__tar.gz → 0.0.4__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.
- {aicmo-0.0.2 → aicmo-0.0.4}/PKG-INFO +1 -1
- {aicmo-0.0.2 → aicmo-0.0.4}/aicmo/__init__.py +24 -16
- {aicmo-0.0.2 → aicmo-0.0.4}/aicmo.egg-info/PKG-INFO +1 -1
- {aicmo-0.0.2 → aicmo-0.0.4}/setup.py +1 -1
- {aicmo-0.0.2 → aicmo-0.0.4}/README.md +0 -0
- {aicmo-0.0.2 → aicmo-0.0.4}/aicmo.egg-info/SOURCES.txt +0 -0
- {aicmo-0.0.2 → aicmo-0.0.4}/aicmo.egg-info/dependency_links.txt +0 -0
- {aicmo-0.0.2 → aicmo-0.0.4}/aicmo.egg-info/requires.txt +0 -0
- {aicmo-0.0.2 → aicmo-0.0.4}/aicmo.egg-info/top_level.txt +0 -0
- {aicmo-0.0.2 → aicmo-0.0.4}/setup.cfg +0 -0
|
@@ -134,7 +134,6 @@ class AICMOClient:
|
|
|
134
134
|
tools=tools,
|
|
135
135
|
tool_choice={"type": "function", "function": {"name": tool_name}}
|
|
136
136
|
)
|
|
137
|
-
tokens = self.get_gpt_tokens(completion, model, tokens)
|
|
138
137
|
ret_val['completion'] = completion
|
|
139
138
|
ret_val['status'] = "success"
|
|
140
139
|
ret_val['tokens'] = self.get_gpt_tokens(completion, model, tokens)
|
|
@@ -198,25 +197,34 @@ class AICMOClient:
|
|
|
198
197
|
self,
|
|
199
198
|
data: types.chat.chat_completion.ChatCompletion,
|
|
200
199
|
model: str,
|
|
201
|
-
tokens: dict
|
|
200
|
+
tokens: dict,
|
|
201
|
+
use_openrouter: bool=True
|
|
202
202
|
) -> dict:
|
|
203
203
|
"""
|
|
204
204
|
Calculate the token usage and cost.
|
|
205
205
|
"""
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
tokens[
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
206
|
+
if use_openrouter:
|
|
207
|
+
tokens['total_cost'] += data.usage.cost
|
|
208
|
+
tokens['input_cost'] += data.usage.cost_details['upstream_inference_prompt_cost']
|
|
209
|
+
tokens['output_cost'] += data.usage.cost_details['upstream_inference_completions_cost']
|
|
210
|
+
tokens["prompt_tokens"] += data.usage.prompt_tokens
|
|
211
|
+
tokens["completion_tokens"] += data.usage.completion_tokens
|
|
212
|
+
tokens["total_tokens"] += data.usage.total_tokens
|
|
213
|
+
else:
|
|
214
|
+
prompt_tokens = data.usage.prompt_tokens
|
|
215
|
+
completion_tokens = data.usage.completion_tokens
|
|
216
|
+
cost = self.COST.get('openai', {}).get("texts", {}).get(model, {})
|
|
217
|
+
openai_input_cost = cost.get('input', None)
|
|
218
|
+
openai_output_cost = cost.get('output', None)
|
|
219
|
+
if openai_input_cost and openai_output_cost:
|
|
220
|
+
tokens['input_cost'] += prompt_tokens * openai_input_cost
|
|
221
|
+
tokens['output_cost'] += completion_tokens * openai_output_cost
|
|
222
|
+
tokens['total_cost'] = round(tokens['input_cost'] + tokens['output_cost'], 4)
|
|
223
|
+
tokens['prompt_tokens'] += prompt_tokens
|
|
224
|
+
tokens['completion_tokens'] += completion_tokens
|
|
225
|
+
tokens['total_tokens'] += prompt_tokens + completion_tokens
|
|
226
|
+
tokens['openai_input_cost'] = openai_input_cost
|
|
227
|
+
tokens['openai_output_cost'] = openai_output_cost
|
|
220
228
|
return tokens
|
|
221
229
|
|
|
222
230
|
def s3_upload_pickle(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|