Download apps/core/models/llm_record.py from jun2024/fc: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/core/models/llm_record.py
- Command line
-
hf download hf://spaces/jun2024/fc/apps/core/models/llm_record.py
-
curl -L -o llm_record.py https://huggingface.co/spaces/jun2024/fc/resolve/main/apps/core/models/llm_record.py
1.32 kB
| """ | |
| LLM 调用记录模型 | |
| 记录每次 LLM API 调用的详细信息,用于监控使用量和成本分析. | |
| """ | |
| from typing import ClassVar | |
| from django.db import models | |
| from django.utils.translation import gettext_lazy as _ | |
| class LLMCallRecord(models.Model): | |
| """ | |
| LLM 调用记录(用于成本追踪) | |
| 记录每次 LLM API 调用的详细信息,用于监控使用量和成本分析. | |
| Requirements: 6.1, 6.2 | |
| """ | |
| id: int | |
| model = models.CharField(max_length=100, verbose_name=_("模型")) | |
| prompt_tokens = models.IntegerField(verbose_name=_("输入 Token")) | |
| completion_tokens = models.IntegerField(verbose_name=_("输出 Token")) | |
| total_tokens = models.IntegerField(verbose_name=_("总 Token")) | |
| duration_ms = models.FloatField(verbose_name=_("耗时(ms)")) | |
| created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("调用时间")) | |
| class Meta: | |
| verbose_name = _("LLM 调用记录") | |
| verbose_name_plural = _("LLM 调用记录") | |
| indexes: ClassVar = [ | |
| models.Index(fields=["created_at"], name="core_llmcal_created_830747_idx"), | |
| models.Index(fields=["model"], name="core_llmcal_model_df0279_idx"), | |
| ] | |
| def __str__(self) -> str: | |
| return f"{self.model} - {self.total_tokens} tokens - {self.created_at}" | |