2023-11-16 05:16:27 +00:00
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
"""
|
|
|
|
|
|
@project: maxkb
|
|
|
|
|
|
@Author:虎
|
|
|
|
|
|
@file: provide_api.py
|
|
|
|
|
|
@date:2023/11/2 14:25
|
|
|
|
|
|
@desc:
|
|
|
|
|
|
"""
|
|
|
|
|
|
from drf_yasg import openapi
|
|
|
|
|
|
|
|
|
|
|
|
from common.mixins.api_mixin import ApiMixin
|
2025-01-13 03:15:51 +00:00
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2023-11-16 05:16:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModelQueryApi(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_params_api():
|
|
|
|
|
|
return [openapi.Parameter(name='name',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=False,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('name')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
openapi.Parameter(name='model_type', in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=False,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('model type')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
openapi.Parameter(name='model_name', in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=False,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('model name')),
|
2023-11-23 08:11:57 +00:00
|
|
|
|
openapi.Parameter(name='provider',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=False,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('provider')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-01 09:30:06 +00:00
|
|
|
|
class ModelEditApi(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_body_api():
|
|
|
|
|
|
return openapi.Schema(type=openapi.TYPE_OBJECT,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('parameters required to call the function'),
|
|
|
|
|
|
description=_('parameters required to call the function'),
|
2023-12-01 09:30:06 +00:00
|
|
|
|
required=['provide', 'model_info'],
|
|
|
|
|
|
properties={
|
|
|
|
|
|
'name': openapi.Schema(type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('name'),
|
|
|
|
|
|
description=_('name')),
|
2023-12-01 09:30:06 +00:00
|
|
|
|
'model_type': openapi.Schema(type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('model type'),
|
|
|
|
|
|
description=_('model type')),
|
2023-12-01 09:30:06 +00:00
|
|
|
|
'model_name': openapi.Schema(type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('model name'),
|
|
|
|
|
|
description=_('model name')),
|
|
|
|
|
|
'provider': openapi.Schema(type=openapi.TYPE_STRING,
|
|
|
|
|
|
title=_('provider'),
|
|
|
|
|
|
description=_('provider')),
|
2023-12-01 09:30:06 +00:00
|
|
|
|
'credential': openapi.Schema(type=openapi.TYPE_OBJECT,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('model certificate information'),
|
|
|
|
|
|
description=_('model certificate information'))
|
2023-12-01 09:30:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-16 05:16:27 +00:00
|
|
|
|
class ModelCreateApi(ApiMixin):
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_body_api():
|
|
|
|
|
|
return openapi.Schema(type=openapi.TYPE_OBJECT,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('parameters required to call the function'),
|
|
|
|
|
|
description=_('parameters required to call the function'),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
required=['provide', 'model_info'],
|
|
|
|
|
|
properties={
|
|
|
|
|
|
'name': openapi.Schema(type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('name'),
|
|
|
|
|
|
description=_('name')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
'provider': openapi.Schema(type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('provider'),
|
|
|
|
|
|
description=_('provider')),
|
|
|
|
|
|
'permission_type': openapi.Schema(type=openapi.TYPE_STRING, title=_('permission'),
|
2024-07-16 08:08:31 +00:00
|
|
|
|
description="PUBLIC|PRIVATE"),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
'model_type': openapi.Schema(type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('model type'),
|
|
|
|
|
|
description=_('model type')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
'model_name': openapi.Schema(type=openapi.TYPE_STRING,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('model name'),
|
|
|
|
|
|
description=_('model name')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
'credential': openapi.Schema(type=openapi.TYPE_OBJECT,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('model certificate information'),
|
|
|
|
|
|
description=_('model certificate information')),
|
2024-07-16 08:08:31 +00:00
|
|
|
|
|
2023-11-16 05:16:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProvideApi(ApiMixin):
|
|
|
|
|
|
class ModelTypeList(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_params_api():
|
|
|
|
|
|
return [openapi.Parameter(name='provider',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=True,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('provider')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_response_body_api():
|
|
|
|
|
|
return openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_OBJECT,
|
|
|
|
|
|
required=['key', 'value'],
|
|
|
|
|
|
properties={
|
2025-01-13 03:15:51 +00:00
|
|
|
|
'key': openapi.Schema(type=openapi.TYPE_STRING, title=_('model type description'),
|
|
|
|
|
|
description=_('model type description'), default=_('large language model')),
|
|
|
|
|
|
'value': openapi.Schema(type=openapi.TYPE_STRING, title=_('model type value'),
|
|
|
|
|
|
description=_('model type value'), default="LLM"),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ModelList(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_params_api():
|
|
|
|
|
|
return [openapi.Parameter(name='provider',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=True,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('provider')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
openapi.Parameter(name='model_type',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=True,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('model type')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_response_body_api():
|
|
|
|
|
|
return openapi.Schema(
|
|
|
|
|
|
type=openapi.TYPE_OBJECT,
|
|
|
|
|
|
required=['name', 'desc', 'model_type'],
|
|
|
|
|
|
properties={
|
2025-01-13 03:15:51 +00:00
|
|
|
|
'name': openapi.Schema(type=openapi.TYPE_STRING, title=_('name'),
|
|
|
|
|
|
description=_('name'), default=_('name')),
|
|
|
|
|
|
'desc': openapi.Schema(type=openapi.TYPE_STRING, title=_('model description'),
|
|
|
|
|
|
description=_('model description')),
|
|
|
|
|
|
'model_type': openapi.Schema(type=openapi.TYPE_STRING, title=_('model type value'),
|
|
|
|
|
|
description=_('model type value'), default="LLM"),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ModelForm(ApiMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_params_api():
|
|
|
|
|
|
return [openapi.Parameter(name='provider',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=True,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('provider')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
openapi.Parameter(name='model_type',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=True,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('model type')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
openapi.Parameter(name='model_name',
|
|
|
|
|
|
in_=openapi.IN_QUERY,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=True,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('model name')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_params_api():
|
|
|
|
|
|
return [openapi.Parameter(name='provider',
|
|
|
|
|
|
in_=openapi.IN_PATH,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=True,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('provider')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
openapi.Parameter(name='method',
|
|
|
|
|
|
in_=openapi.IN_PATH,
|
|
|
|
|
|
type=openapi.TYPE_STRING,
|
|
|
|
|
|
required=True,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
description=_('function that needs to be executed')),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request_body_api():
|
|
|
|
|
|
return openapi.Schema(type=openapi.TYPE_OBJECT,
|
2025-01-13 03:15:51 +00:00
|
|
|
|
title=_('parameters required to call the function'),
|
|
|
|
|
|
description=_('parameters required to call the function'),
|
2023-11-16 05:16:27 +00:00
|
|
|
|
)
|