(completion_json, gpt_version, current_stage, output_dir, total_accumulated_cost)
| 285 | print("============================================\n") |
| 286 | |
| 287 | def 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 | |
| 314 | def num_tokens_from_messages(messages, model="gpt-4o-2024-08-06"): |
no test coverage detected