-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Swagger document response for adding OpenAI interface #2786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ class Openai(APIView): | |
@swagger_auto_schema(operation_summary=_("OpenAI Interface Dialogue"), | ||
operation_id=_("OpenAI Interface Dialogue"), | ||
request_body=OpenAIChatApi.get_request_body_api(), | ||
responses=OpenAIChatApi.get_response_body_api(), | ||
tags=[_("OpenAI Dialogue")]) | ||
def post(self, request: Request, application_id: str): | ||
return OpenAIChatSerializer(data={'application_id': application_id, 'client_id': request.auth.client_id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code appears to be correct and does not contain any irregularities, potential issues, or optimization suggestions. It defines an API view withSwagger documentation that outlines the |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,7 +320,7 @@ def one_meta(self, with_valid=False): | |
raise AppApiException(500, _('Model does not exist')) | ||
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}") | ||
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, | ||
'model_name': model.model_name, | ||
'status': model.status, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code appears mostly correct, but I have some minor suggestions for improvement:
Here's an improved version of the code with these considerations: def one_meta(self, with_valid=False):
# Step 1: Validate input data integrity
id = self.data.get('id')
user_id = self.data.get('user_id')
if not id or not user_id:
raise AppApiException(
400, _("ID and User ID must be provided")
)
try:
# Step 2: Retrieve model based on given ID
model = QuerySet(Model).get(id=id)
# Step 3: Check permission
if model.permission_type == 'PRIVATE':
if str(user_id) != str(model.user_id):
raise Exception(_('No permission to use this model') + f" {model.name}")
# Return model metadata
return {
'id': str(model.id),
'provider': model.provider,
'name': model.name,
'model_type': model.model_type,
'model_name': model.model_name,
'status': model.status,
}
except Model.DoesNotExist:
raise AppApiException(500, _('Model does not exist')) Make sure to adjust variable names and other components according to your specific project requirements. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code seems mostly clean with some improvements for clarity and readability:
Docstring: Add more detailed docstrings to describe what
get_response_body_api
does, especially since it's using placeholders like_
. This can help maintainers understand its purpose.Type Annotations: Consider adding type annotations to improve code quality. However, given Python 3.7+, you already have PEP 526 support which allows the use of typing aliases without explicit import statements.
Variable Naming: Variable names could be improved for better understanding. For example,
id
,answer_list
, etc., are common variables that might not clearly indicate their purpose without additional context.Documentation Consistency: Ensure consistency in documentation throughout the function if applicable (e.g., using consistent naming conventions).
Here is an optimized version with minor changes:
These changes should make the code cleaner and potentially easier to maintain. If there are specific parts of the function or other areas where further optimization or clarification might be needed, feel free to let me know!