Files
JobRadar/agent_runtime/forms.py
T

33 lines
1.1 KiB
Python

"""模型服务商配置表单。"""
from django import forms
class ProviderConfigurationForm(forms.Form):
"""只接收用户需要决定的密钥和默认模型,不允许覆盖系统预设端点。"""
api_key = forms.CharField(
label="API Key",
max_length=500,
strip=True,
widget=forms.PasswordInput(
attrs={"autocomplete": "new-password", "placeholder": "粘贴服务商 API Key"}
),
)
model_id = forms.CharField(
label="默认模型",
max_length=160,
required=False,
strip=True,
widget=forms.TextInput(attrs={"placeholder": "自动选择推荐模型"}),
)
use_as_default = forms.BooleanField(label="设为 Agent 默认服务商", required=False)
def clean_api_key(self):
"""拒绝明显不完整的值,但不假设各厂商的固定前缀。"""
api_key = self.cleaned_data["api_key"]
if len(api_key) < 8:
raise forms.ValidationError("API Key 长度不足,请检查是否复制完整。")
return api_key