feat: associate generation calls with devices
This commit is contained in:
@@ -109,6 +109,7 @@ class CallRecordAdmin(ReadOnlyLedgerAdmin):
|
||||
"created_at",
|
||||
"user",
|
||||
"api_key",
|
||||
"client_device",
|
||||
"operation_type",
|
||||
"alias",
|
||||
"model_used",
|
||||
@@ -116,7 +117,7 @@ class CallRecordAdmin(ReadOnlyLedgerAdmin):
|
||||
"status",
|
||||
"upstream_latency_ms",
|
||||
)
|
||||
list_filter = ("operation_type", "status", "created_at")
|
||||
list_filter = ("operation_type", "status", "client_device", "created_at")
|
||||
search_fields = (
|
||||
"user__username",
|
||||
"user__email",
|
||||
@@ -129,7 +130,7 @@ class CallRecordAdmin(ReadOnlyLedgerAdmin):
|
||||
"result_summary",
|
||||
)
|
||||
ordering = ("-created_at", "-id")
|
||||
list_select_related = ("user", "api_key")
|
||||
list_select_related = ("user", "api_key", "client_device")
|
||||
|
||||
|
||||
@admin.register(SignupBonusGrant)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 5.2.15 on 2026-07-21 01:34
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('billing', '0009_signup_bonus_default_ten'),
|
||||
('licensing', '0001_initial'),
|
||||
('users', '0005_alter_apikey_created_at_alter_apikey_key_hash_and_more'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='callrecord',
|
||||
name='client_device',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='call_records', to='licensing.clientdevice', verbose_name='客户端设备'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='callrecord',
|
||||
index=models.Index(fields=['client_device', 'created_at'], name='call_record_client__d5a0fb_idx'),
|
||||
),
|
||||
]
|
||||
@@ -35,6 +35,14 @@ class CallRecord(models.Model):
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="call_records",
|
||||
)
|
||||
client_device = models.ForeignKey(
|
||||
"licensing.ClientDevice",
|
||||
verbose_name="客户端设备",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="call_records",
|
||||
)
|
||||
operation_type = models.CharField("操作类型", max_length=32, choices=OperationType.choices)
|
||||
alias = models.CharField("能力别名", max_length=64, blank=True)
|
||||
model_used = models.CharField("实际模型", max_length=128, blank=True)
|
||||
@@ -68,6 +76,7 @@ class CallRecord(models.Model):
|
||||
indexes = [
|
||||
models.Index(fields=("user", "created_at")),
|
||||
models.Index(fields=("api_key", "created_at")),
|
||||
models.Index(fields=("client_device", "created_at")),
|
||||
models.Index(fields=("operation_type", "status")),
|
||||
models.Index(fields=("alias",)),
|
||||
]
|
||||
|
||||
@@ -504,6 +504,7 @@ def precharge_call(
|
||||
model_used: str = "",
|
||||
resolution: str | None = None,
|
||||
api_key=None,
|
||||
client_device=None,
|
||||
prompt: str = "",
|
||||
) -> CallCharge:
|
||||
points_cost = _validate_positive_points(points_cost)
|
||||
@@ -524,6 +525,7 @@ def precharge_call(
|
||||
call_record = CallRecord.objects.create(
|
||||
user=user,
|
||||
api_key=api_key,
|
||||
client_device=client_device,
|
||||
operation_type=operation_type,
|
||||
alias=normalized_alias,
|
||||
model_used=str(model_used or "").strip(),
|
||||
|
||||
Reference in New Issue
Block a user