diff --git a/content/management/commands/gen_lesson_figures.py b/content/management/commands/gen_lesson_figures.py index 071ed90..949a259 100644 --- a/content/management/commands/gen_lesson_figures.py +++ b/content/management/commands/gen_lesson_figures.py @@ -54,7 +54,7 @@ class Command(BaseCommand): raise CommandError('درسی پیدا نشد.') model = chat_model_for('') client = clients.get_openai_client() - spent = 0 + spent = prompt_t = out_t = 0 for lesson in lessons: body = (f'عنوان: {lesson.title}\nتوضیح: {lesson.intro_text}\nمثال: {lesson.example}\n' + '\n'.join(f'قدم {i}: {s}' for i, s in enumerate(lesson.steps or []))) @@ -64,6 +64,8 @@ class Command(BaseCommand): {'role': 'user', 'content': body}]) u = getattr(r, 'usage', None) spent += (getattr(u, 'total_tokens', 0) or 0) + prompt_t += (getattr(u, 'prompt_tokens', 0) or 0) + out_t += (getattr(u, 'completion_tokens', 0) or 0) raw = re.sub(r'^```(?:json)?|```$', '', (r.choices[0].message.content or '').strip()).strip() try: start = raw.index('[') @@ -90,4 +92,4 @@ class Command(BaseCommand): if figures and not o['dry_run']: lesson.figures = figures lesson.save(update_fields=['figures']) - self.stdout.write(f'توکنِ مصرفی: {spent}') + self.stdout.write(f'توکنِ مصرفی: {spent} (ورودی {prompt_t}، خروجی {out_t})')