MCPcopy Index your code
hub / github.com/going-doer/Paper2Code / print_log_cost

Function print_log_cost

codes/utils.py:287–311  ·  view source on GitHub ↗
(completion_json, gpt_version, current_stage, output_dir, total_accumulated_cost)

Source from the content-addressed store, hash-verified

285 print("============================================\n")
286
287def print_log_cost(completion_json, gpt_version, current_stage, output_dir, total_accumulated_cost):
288 usage_info = cal_cost(completion_json, gpt_version)
289
290 current_cost = usage_info['total_cost']
291 total_accumulated_cost += current_cost
292
293 output_lines = []
294 output_lines.append("🌟 Usage Summary 🌟")
295 output_lines.append(f"{current_stage}")
296 output_lines.append(f"🛠️ Model: {usage_info['model_name']}")
297 output_lines.append(f"📥 Input tokens: {usage_info['actual_input_tokens']} (Cost: ${usage_info['input_cost']:.8f})")
298 output_lines.append(f"📦 Cached input tokens: {usage_info['cached_tokens']} (Cost: ${usage_info['cached_input_cost']:.8f})")
299 output_lines.append(f"📤 Output tokens: {usage_info['output_tokens']} (Cost: ${usage_info['output_cost']:.8f})")
300 output_lines.append(f"💵 Current total cost: ${current_cost:.8f}")
301 output_lines.append(f"🪙 Accumulated total cost so far: ${total_accumulated_cost:.8f}")
302 output_lines.append("============================================\n")
303
304 output_text = "\n".join(output_lines)
305
306 print(output_text)
307
308 with open(f"{output_dir}/cost_info.log", "a", encoding="utf-8") as f:
309 f.write(output_text + "\n")
310
311 return total_accumulated_cost
312
313
314def num_tokens_from_messages(messages, model="gpt-4o-2024-08-06"):

Callers 5

mainFunction · 0.90
3.1_coding_sh.pyFile · 0.90
1_planning.pyFile · 0.90
2_analyzing.pyFile · 0.90
3_coding.pyFile · 0.90

Calls 1

cal_costFunction · 0.85

Tested by

no test coverage detected