- 后端·可插拔 Provider 层:通用 OpenAICompatibleProvider(tokenssr 等中转站,base_url+api_key,零改代码换站)+ ModelProvider.api_key - 后端·脚本 agent:结构化 ScriptDraft 契约 + 加载电商 skill + 出稿/改稿一体对话 agent(3模式/多模型)+ 流式 SSE 端点(DRF SSE renderer) - 后端·图像:gpt-image-2 参考图出图 + 故事板 @图1@图2@图3 多锚点合成(锁脸锁商品);Seedance 打开 generate_audio - 后端·模特库:gpt-image-2 生成器(9:16氛围图→16:9白底三视图)+ seed_demo_models 管理命令 - DB·迁移:tokenssr 中转站 + 多模型 seed(豆包/GPT-5.5/Gemini + gpt-image-2);ScriptSegment 结构化字段 - 前端·脚本趴:接真 SSE(工具卡 + 思考流)+ 模型下拉 + 3模式 + 改稿;agentScriptStream - skills/ecommerce-video-script 电商脚本技能(运行时依赖) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
108 lines
4.4 KiB
Python
108 lines
4.4 KiB
Python
from django.db import models
|
|
|
|
from apps.common.models import TeamOwnedModel, TimeStampedModel
|
|
|
|
|
|
class ModelProvider(TimeStampedModel):
|
|
class Status(models.TextChoices):
|
|
ACTIVE = "active", "Active"
|
|
DISABLED = "disabled", "Disabled"
|
|
|
|
name = models.CharField(max_length=64, unique=True)
|
|
display_name = models.CharField(max_length=128)
|
|
status = models.CharField(max_length=24, choices=Status.choices, default=Status.ACTIVE)
|
|
base_url = models.URLField(blank=True)
|
|
# 站级 API Key(中转站)。可插拔:换站 = 改这一行的 base_url + api_key,零改代码。
|
|
# 留空则 services 层按 provider.name 回退 settings.PROVIDER_KEYS(.env),避免密钥写死/进库。
|
|
api_key = models.CharField(max_length=255, blank=True)
|
|
metadata = models.JSONField(default=dict, blank=True)
|
|
|
|
def __str__(self) -> str:
|
|
return self.display_name
|
|
|
|
|
|
class ModelConfig(TimeStampedModel):
|
|
class Capability(models.TextChoices):
|
|
TEXT = "text", "Text"
|
|
IMAGE = "image", "Image"
|
|
VIDEO = "video", "Video"
|
|
VISION = "vision", "Vision"
|
|
AUDIO = "audio", "Audio"
|
|
EXPORT = "export", "Export"
|
|
|
|
class Status(models.TextChoices):
|
|
ACTIVE = "active", "Active"
|
|
DISABLED = "disabled", "Disabled"
|
|
|
|
provider = models.ForeignKey(ModelProvider, on_delete=models.CASCADE, related_name="models")
|
|
name = models.CharField(max_length=128)
|
|
display_name = models.CharField(max_length=128)
|
|
capability = models.CharField(max_length=32, choices=Capability.choices)
|
|
endpoint = models.CharField(max_length=255, blank=True)
|
|
unit_price = models.DecimalField(max_digits=12, decimal_places=4, default=0)
|
|
status = models.CharField(max_length=24, choices=Status.choices, default=Status.ACTIVE)
|
|
rate_limit_per_minute = models.PositiveIntegerField(default=60)
|
|
metadata = models.JSONField(default=dict, blank=True)
|
|
|
|
class Meta:
|
|
unique_together = [("provider", "name", "capability")]
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.provider.name}:{self.name}:{self.capability}"
|
|
|
|
|
|
class AITask(TeamOwnedModel):
|
|
class Type(models.TextChoices):
|
|
SCRIPT_GENERATION = "script_generation", "Script Generation"
|
|
SCRIPT_OPTIMIZATION = "script_optimization", "Script Optimization"
|
|
PRODUCT_IMAGE = "product_image", "Product Image"
|
|
PERSON_IMAGE = "person_image", "Person Image"
|
|
SCENE_IMAGE = "scene_image", "Scene Image"
|
|
STORYBOARD = "storyboard", "Storyboard"
|
|
VIDEO_SEGMENT = "video_segment", "Video Segment"
|
|
VOICEOVER = "voiceover", "Voiceover"
|
|
EXPORT = "export", "Export"
|
|
|
|
class Status(models.TextChoices):
|
|
CREATED = "created", "Created"
|
|
RESERVED = "reserved", "Reserved"
|
|
SUBMITTED = "submitted", "Submitted"
|
|
POLLING = "polling", "Polling"
|
|
POSTPROCESSING = "postprocessing", "Postprocessing"
|
|
SUCCEEDED = "succeeded", "Succeeded"
|
|
FAILED = "failed", "Failed"
|
|
COMPENSATING = "compensating", "Compensating"
|
|
CANCELLED = "cancelled", "Cancelled"
|
|
|
|
project = models.ForeignKey(
|
|
"projects.Project",
|
|
on_delete=models.CASCADE,
|
|
null=True,
|
|
blank=True,
|
|
related_name="ai_tasks",
|
|
)
|
|
task_type = models.CharField(max_length=48, choices=Type.choices)
|
|
status = models.CharField(max_length=32, choices=Status.choices, default=Status.CREATED)
|
|
model_config = models.ForeignKey(ModelConfig, on_delete=models.PROTECT, related_name="tasks")
|
|
idempotency_key = models.CharField(max_length=128, unique=True)
|
|
provider_task_id = models.CharField(max_length=255, blank=True)
|
|
request_payload = models.JSONField(default=dict, blank=True)
|
|
response_payload = models.JSONField(default=dict, blank=True)
|
|
estimated_cost = models.DecimalField(max_digits=12, decimal_places=4, default=0)
|
|
actual_cost = models.DecimalField(max_digits=12, decimal_places=4, default=0)
|
|
error_code = models.CharField(max_length=64, blank=True)
|
|
error_message = models.TextField(blank=True)
|
|
submitted_at = models.DateTimeField(null=True, blank=True)
|
|
completed_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
class Meta:
|
|
indexes = [
|
|
models.Index(fields=["team", "status"]),
|
|
models.Index(fields=["project", "task_type"]),
|
|
models.Index(fields=["provider_task_id"]),
|
|
]
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.task_type}:{self.status}:{self.id}"
|
|
|