aicmo 0.0.2__tar.gz → 0.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aicmo
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: A package for using aicmo functions and tools
5
5
  Author: Jayr Castro
6
6
  Author-email: jayrcastro.py@gmail.com
@@ -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
- prompt_tokens = data.usage.prompt_tokens
207
- completion_tokens = data.usage.completion_tokens
208
- cost = self.COST.get('openai', {}).get("texts", {}).get(model, {})
209
- openai_input_cost = cost.get('input', None)
210
- openai_output_cost = cost.get('output', None)
211
- if openai_input_cost and openai_output_cost:
212
- tokens['input_cost'] += prompt_tokens * openai_input_cost
213
- tokens['output_cost'] += completion_tokens * openai_output_cost
214
- tokens['total_cost'] = round(tokens['input_cost'] + tokens['output_cost'], 4)
215
- tokens['prompt_tokens'] += prompt_tokens
216
- tokens['completion_tokens'] += completion_tokens
217
- tokens['total_tokens'] += prompt_tokens + completion_tokens
218
- tokens['openai_input_cost'] = openai_input_cost
219
- tokens['openai_output_cost'] = openai_output_cost
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(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aicmo
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: A package for using aicmo functions and tools
5
5
  Author: Jayr Castro
6
6
  Author-email: jayrcastro.py@gmail.com
@@ -1,6 +1,6 @@
1
1
  from setuptools import setup, find_packages
2
2
 
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
 
5
5
  # Setting up
6
6
  setup(
File without changes
File without changes
File without changes
File without changes