feat: Swagger document response for adding OpenAI interface (#2786)
This commit is contained in:
parent
927f0c784a
commit
add1cba8cb
@ -53,6 +53,85 @@ class ChatClientHistoryApi(ApiMixin):
|
|||||||
|
|
||||||
|
|
||||||
class OpenAIChatApi(ApiMixin):
|
class OpenAIChatApi(ApiMixin):
|
||||||
|
@staticmethod
|
||||||
|
def get_response_body_api():
|
||||||
|
return openapi.Responses(responses={
|
||||||
|
200: openapi.Response(description=_('response parameters'),
|
||||||
|
schema=openapi.Schema(type=openapi.TYPE_OBJECT,
|
||||||
|
required=['id',
|
||||||
|
'choices'],
|
||||||
|
properties={
|
||||||
|
'id': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING,
|
||||||
|
title=_(
|
||||||
|
"Conversation ID")),
|
||||||
|
'choices': openapi.Schema(
|
||||||
|
type=openapi.TYPE_ARRAY,
|
||||||
|
items=openapi.Schema(
|
||||||
|
type=openapi.TYPE_OBJECT,
|
||||||
|
required=[
|
||||||
|
'message'],
|
||||||
|
properties={
|
||||||
|
'finish_reason': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING, ),
|
||||||
|
'index': openapi.Schema(
|
||||||
|
type=openapi.TYPE_INTEGER),
|
||||||
|
'answer_list': openapi.Schema(
|
||||||
|
type=openapi.TYPE_ARRAY,
|
||||||
|
items=openapi.Schema(
|
||||||
|
type=openapi.TYPE_OBJECT,
|
||||||
|
required=[
|
||||||
|
'content'],
|
||||||
|
properties={
|
||||||
|
'content': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING),
|
||||||
|
'view_type': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING),
|
||||||
|
'runtime_node_id': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING),
|
||||||
|
'chat_record_id': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING),
|
||||||
|
'reasoning_content': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING),
|
||||||
|
}
|
||||||
|
)),
|
||||||
|
'message': openapi.Schema(
|
||||||
|
type=openapi.TYPE_OBJECT,
|
||||||
|
required=[
|
||||||
|
'content'],
|
||||||
|
properties={
|
||||||
|
'content': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING),
|
||||||
|
'role': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING)
|
||||||
|
|
||||||
|
}),
|
||||||
|
|
||||||
|
}
|
||||||
|
)),
|
||||||
|
'created': openapi.Schema(
|
||||||
|
type=openapi.TYPE_INTEGER),
|
||||||
|
'model': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING),
|
||||||
|
'object': openapi.Schema(
|
||||||
|
type=openapi.TYPE_STRING),
|
||||||
|
'usage': openapi.Schema(
|
||||||
|
type=openapi.TYPE_OBJECT,
|
||||||
|
required=[
|
||||||
|
'completion_tokens',
|
||||||
|
'prompt_tokens',
|
||||||
|
'total_tokens'],
|
||||||
|
properties={
|
||||||
|
'completion_tokens': openapi.Schema(
|
||||||
|
type=openapi.TYPE_INTEGER),
|
||||||
|
'prompt_tokens': openapi.Schema(
|
||||||
|
type=openapi.TYPE_INTEGER),
|
||||||
|
'total_tokens': openapi.Schema(
|
||||||
|
type=openapi.TYPE_INTEGER)
|
||||||
|
})
|
||||||
|
|
||||||
|
}))})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_request_body_api():
|
def get_request_body_api():
|
||||||
return openapi.Schema(type=openapi.TYPE_OBJECT,
|
return openapi.Schema(type=openapi.TYPE_OBJECT,
|
||||||
|
|||||||
@ -37,6 +37,7 @@ class Openai(APIView):
|
|||||||
@swagger_auto_schema(operation_summary=_("OpenAI Interface Dialogue"),
|
@swagger_auto_schema(operation_summary=_("OpenAI Interface Dialogue"),
|
||||||
operation_id=_("OpenAI Interface Dialogue"),
|
operation_id=_("OpenAI Interface Dialogue"),
|
||||||
request_body=OpenAIChatApi.get_request_body_api(),
|
request_body=OpenAIChatApi.get_request_body_api(),
|
||||||
|
responses=OpenAIChatApi.get_response_body_api(),
|
||||||
tags=[_("OpenAI Dialogue")])
|
tags=[_("OpenAI Dialogue")])
|
||||||
def post(self, request: Request, application_id: str):
|
def post(self, request: Request, application_id: str):
|
||||||
return OpenAIChatSerializer(data={'application_id': application_id, 'client_id': request.auth.client_id,
|
return OpenAIChatSerializer(data={'application_id': application_id, 'client_id': request.auth.client_id,
|
||||||
|
|||||||
@ -320,7 +320,7 @@ class ModelSerializer(serializers.Serializer):
|
|||||||
raise AppApiException(500, _('Model does not exist'))
|
raise AppApiException(500, _('Model does not exist'))
|
||||||
if model.permission_type == 'PRIVATE' and str(model.user_id) != str(self.data.get("user_id")):
|
if model.permission_type == 'PRIVATE' and str(model.user_id) != str(self.data.get("user_id")):
|
||||||
raise Exception(_('No permission to use this model') + f"{model.name}")
|
raise Exception(_('No permission to use this model') + f"{model.name}")
|
||||||
model = QuerySet(Model).get(id=self.data.get('id'), user_id=self.data.get('user_id'))
|
model = QuerySet(Model).get(id=self.data.get('id'))
|
||||||
return {'id': str(model.id), 'provider': model.provider, 'name': model.name, 'model_type': model.model_type,
|
return {'id': str(model.id), 'provider': model.provider, 'name': model.name, 'model_type': model.model_type,
|
||||||
'model_name': model.model_name,
|
'model_name': model.model_name,
|
||||||
'status': model.status,
|
'status': model.status,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user