Skip to content

Commit 981024f

Browse files
committed
feat: Swagger document response for adding OpenAI interface
1 parent ac5a9d0 commit 981024f

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

apps/application/swagger_api/chat_api.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,85 @@ def get_request_body_api():
5353

5454

5555
class OpenAIChatApi(ApiMixin):
56+
@staticmethod
57+
def get_response_body_api():
58+
return openapi.Responses(responses={
59+
200: openapi.Response(description=_('response parameters'),
60+
schema=openapi.Schema(type=openapi.TYPE_OBJECT,
61+
required=['id',
62+
'choices'],
63+
properties={
64+
'id': openapi.Schema(
65+
type=openapi.TYPE_STRING,
66+
title=_(
67+
"Conversation ID")),
68+
'choices': openapi.Schema(
69+
type=openapi.TYPE_ARRAY,
70+
items=openapi.Schema(
71+
type=openapi.TYPE_OBJECT,
72+
required=[
73+
'message'],
74+
properties={
75+
'finish_reason': openapi.Schema(
76+
type=openapi.TYPE_STRING, ),
77+
'index': openapi.Schema(
78+
type=openapi.TYPE_INTEGER),
79+
'answer_list': openapi.Schema(
80+
type=openapi.TYPE_ARRAY,
81+
items=openapi.Schema(
82+
type=openapi.TYPE_OBJECT,
83+
required=[
84+
'content'],
85+
properties={
86+
'content': openapi.Schema(
87+
type=openapi.TYPE_STRING),
88+
'view_type': openapi.Schema(
89+
type=openapi.TYPE_STRING),
90+
'runtime_node_id': openapi.Schema(
91+
type=openapi.TYPE_STRING),
92+
'chat_record_id': openapi.Schema(
93+
type=openapi.TYPE_STRING),
94+
'reasoning_content': openapi.Schema(
95+
type=openapi.TYPE_STRING),
96+
}
97+
)),
98+
'message': openapi.Schema(
99+
type=openapi.TYPE_OBJECT,
100+
required=[
101+
'content'],
102+
properties={
103+
'content': openapi.Schema(
104+
type=openapi.TYPE_STRING),
105+
'role': openapi.Schema(
106+
type=openapi.TYPE_STRING)
107+
108+
}),
109+
110+
}
111+
)),
112+
'created': openapi.Schema(
113+
type=openapi.TYPE_INTEGER),
114+
'model': openapi.Schema(
115+
type=openapi.TYPE_STRING),
116+
'object': openapi.Schema(
117+
type=openapi.TYPE_STRING),
118+
'usage': openapi.Schema(
119+
type=openapi.TYPE_OBJECT,
120+
required=[
121+
'completion_tokens',
122+
'prompt_tokens',
123+
'total_tokens'],
124+
properties={
125+
'completion_tokens': openapi.Schema(
126+
type=openapi.TYPE_INTEGER),
127+
'prompt_tokens': openapi.Schema(
128+
type=openapi.TYPE_INTEGER),
129+
'total_tokens': openapi.Schema(
130+
type=openapi.TYPE_INTEGER)
131+
})
132+
133+
}))})
134+
56135
@staticmethod
57136
def get_request_body_api():
58137
return openapi.Schema(type=openapi.TYPE_OBJECT,

apps/application/views/chat_views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Openai(APIView):
3737
@swagger_auto_schema(operation_summary=_("OpenAI Interface Dialogue"),
3838
operation_id=_("OpenAI Interface Dialogue"),
3939
request_body=OpenAIChatApi.get_request_body_api(),
40+
responses=OpenAIChatApi.get_response_body_api(),
4041
tags=[_("OpenAI Dialogue")])
4142
def post(self, request: Request, application_id: str):
4243
return OpenAIChatSerializer(data={'application_id': application_id, 'client_id': request.auth.client_id,

apps/setting/serializers/provider_serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def one_meta(self, with_valid=False):
320320
raise AppApiException(500, _('Model does not exist'))
321321
if model.permission_type == 'PRIVATE' and str(model.user_id) != str(self.data.get("user_id")):
322322
raise Exception(_('No permission to use this model') + f"{model.name}")
323-
model = QuerySet(Model).get(id=self.data.get('id'), user_id=self.data.get('user_id'))
323+
model = QuerySet(Model).get(id=self.data.get('id'))
324324
return {'id': str(model.id), 'provider': model.provider, 'name': model.name, 'model_type': model.model_type,
325325
'model_name': model.model_name,
326326
'status': model.status,

0 commit comments

Comments
 (0)