UnisKB/apps/setting/swagger_api/provide_api.py

193 lines
9.6 KiB
Python
Raw Normal View History

# coding=utf-8
"""
@project: maxkb
@Author
@file provide_api.py
@date2023/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 _
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')),
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')),
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')),
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-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
}
)
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'),
required=['provide', 'model_info'],
properties={
'name': openapi.Schema(type=openapi.TYPE_STRING,
2025-01-13 03:15:51 +00:00
title=_('name'),
description=_('name')),
'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"),
'model_type': openapi.Schema(type=openapi.TYPE_STRING,
2025-01-13 03:15:51 +00:00
title=_('model type'),
description=_('model type')),
'model_name': openapi.Schema(type=openapi.TYPE_STRING,
2025-01-13 03:15:51 +00:00
title=_('model name'),
description=_('model name')),
'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
}
)
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')),
]
@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"),
}
)
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')),
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')),
]
@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"),
}
)
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')),
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')),
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')),
]
@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')),
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')),
]
@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'),
)