fix: auto repair bugs #30
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 2m33s
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 2m33s
This commit is contained in:
parent
7a6a519fbe
commit
d421677518
@ -59,6 +59,24 @@ class DeviceViewSet(viewsets.ViewSet):
|
||||
status_code=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
|
||||
@action(detail=False, methods=['get'])
|
||||
def latest(self, request):
|
||||
"""
|
||||
获取用户最近使用的设备
|
||||
GET /api/v1/devices/latest
|
||||
"""
|
||||
devices = list(
|
||||
UserDevice.objects.filter(
|
||||
user=request.user,
|
||||
is_active=True
|
||||
).select_related('device', 'device__device_type', 'spirit')
|
||||
.order_by('-bind_time')[:1]
|
||||
)
|
||||
if not devices:
|
||||
return error(code=ErrorCode.DEVICE_NOT_FOUND, message='暂无绑定设备')
|
||||
latest = devices[0]
|
||||
return success(data=UserDeviceSerializer(latest).data)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def verify(self, request):
|
||||
"""
|
||||
|
||||
@ -21,6 +21,11 @@ class CreateSpiritSerializer(serializers.ModelSerializer):
|
||||
model = Spirit
|
||||
fields = ['name', 'avatar', 'prompt', 'memory', 'voice_id']
|
||||
|
||||
def validate_prompt(self, value):
|
||||
if value and len(value) > 5000:
|
||||
raise serializers.ValidationError('提示词不能超过5000个字符')
|
||||
return value
|
||||
|
||||
|
||||
class SpiritListSerializer(serializers.ModelSerializer):
|
||||
"""智能体列表序列化器(不含memory等大字段)"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user