add api model
This commit is contained in:
@@ -54,7 +54,7 @@ class AIModel(CoreModel):
|
||||
|
||||
class Meta:
|
||||
db_table = "ai_model"
|
||||
verbose_name = "AI 模型"
|
||||
verbose_name = "模型配置"
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@@ -5,6 +5,8 @@ from . import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'ai_api_key', views.AIApiKeyViewSet)
|
||||
router.register(r'ai_model', views.AIModelViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
__all__ = [
|
||||
'AIApiKeyViewSet'
|
||||
'AIApiKeyViewSet',
|
||||
'AIModelViewSet',
|
||||
]
|
||||
|
||||
from ai.views.ai_api_key import AIApiKeyViewSet
|
||||
from ai.views.ai_api_key import AIApiKeyViewSet
|
||||
from ai.views.ai_model import AIModelViewSet
|
||||
28
backend/ai/views/ai_model.py
Normal file
28
backend/ai/views/ai_model.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from ai.models import AIModel
|
||||
from utils.serializers import CustomModelSerializer
|
||||
from utils.custom_model_viewSet import CustomModelViewSet
|
||||
|
||||
class AIModelSerializer(CustomModelSerializer):
|
||||
api_key_name = serializers.CharField(source='key.name', read_only=True)
|
||||
"""
|
||||
AI 模型 序列化器
|
||||
"""
|
||||
class Meta:
|
||||
model = AIModel
|
||||
fields = '__all__'
|
||||
read_only_fields = ['id', 'create_time', 'update_time']
|
||||
|
||||
class AIModelViewSet(CustomModelViewSet):
|
||||
"""
|
||||
AI 模型 视图集
|
||||
"""
|
||||
queryset = AIModel.objects.filter(is_deleted=False).select_related('key').order_by('-id')
|
||||
serializer_class = AIModelSerializer
|
||||
filterset_fields = ['id', 'remark', 'creator', 'modifier', 'is_deleted', 'name', 'sort', 'status', 'platform',
|
||||
'model', 'max_tokens', 'max_contexts']
|
||||
search_fields = ['name'] # 根据实际字段调整
|
||||
ordering_fields = ['create_time', 'id']
|
||||
ordering = ['-create_time']
|
||||
|
||||
@@ -27,7 +27,6 @@ ${grid_form_fields}
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取表格列配置
|
||||
* @description 使用函数的形式返回列数据而不是直接export一个Array常量,是为了响应语言切换时重新翻译表头
|
||||
|
||||
@@ -133,7 +133,7 @@ function refreshGrid() {
|
||||
v-permission="'${app_name}:${model_name_snake}:create'"
|
||||
>
|
||||
<Plus class="size-5" />
|
||||
{{ $$t('ui.actionTitle.create', [$$t('${app_name}.${model_name_snake}.name')]) }}
|
||||
{{ $t('ui.actionTitle.create') }}
|
||||
</Button>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user