- Furter refinement of the API, adding functionality for refreshing documents and returning Token expiration time when retrieving token

- Implementation of a first version of a Wordpress plugin
- Adding api service to nginx.conf
This commit is contained in:
Josako
2024-09-11 16:31:13 +02:00
parent 76cb825660
commit 9e14824249
17 changed files with 997 additions and 19 deletions

View File

@@ -10,7 +10,8 @@ from werkzeug.utils import secure_filename
from common.utils.document_utils import (
create_document_stack, process_url, start_embedding_task,
validate_file_type, EveAIInvalidLanguageException, EveAIDoubleURLException, EveAIUnsupportedFileType,
process_multiple_urls, get_documents_list, edit_document, refresh_document, edit_document_version
process_multiple_urls, get_documents_list, edit_document, refresh_document, edit_document_version,
refresh_document_with_info
)
@@ -238,3 +239,75 @@ class DocumentVersionResource(Resource):
return {'message': f'Document Version {updated_version.id} updated successfully'}, 200
else:
return {'message': f'Error updating document version: {error}'}, 400
# Define the model for the request body of refresh_with_info
refresh_document_model = document_ns.model('RefreshDocument', {
'name': fields.String(required=False, description='New name for the document'),
'language': fields.String(required=False, description='Language of the document'),
'user_context': fields.String(required=False, description='User context for the document'),
'user_metadata': fields.Raw(required=False, description='User metadata for the document')
})
@document_ns.route('/<int:document_id>/refresh')
class RefreshDocument(Resource):
@jwt_required()
@document_ns.response(200, 'Document refreshed successfully')
@document_ns.response(404, 'Document not found')
def post(self, document_id):
"""
Refresh a document without additional information
"""
tenant_id = get_jwt_identity()
current_app.logger.info(f'Refreshing document {document_id} for tenant {tenant_id}')
try:
new_version, result = refresh_document(document_id)
if new_version:
return {
'message': f'Document refreshed successfully. New version: {new_version.id}. Task ID: {result}',
'document_id': document_id,
'document_version_id': new_version.id,
'task_id': result
}, 200
else:
return {'message': f'Error refreshing document: {result}'}, 400
except Exception as e:
current_app.logger.error(f'Error refreshing document: {str(e)}')
return {'message': 'Internal server error'}, 500
@document_ns.route('/<int:document_id>/refresh_with_info')
class RefreshDocumentWithInfo(Resource):
@jwt_required()
@document_ns.expect(refresh_document_model)
@document_ns.response(200, 'Document refreshed successfully')
@document_ns.response(400, 'Validation Error')
@document_ns.response(404, 'Document not found')
def post(self, document_id):
"""
Refresh a document with new information
"""
tenant_id = get_jwt_identity()
current_app.logger.info(f'Refreshing document {document_id} with info for tenant {tenant_id}')
try:
api_input = request.json
new_version, result = refresh_document_with_info(document_id, api_input)
if new_version:
return {
'message': f'Document refreshed successfully with new info. New version: {new_version.id}. Task ID: {result}',
'document_id': document_id,
'document_version_id': new_version.id,
'task_id': result
}, 200
else:
return {'message': f'Error refreshing document with info: {result}'}, 400
except Exception as e:
current_app.logger.error(f'Error refreshing document with info: {str(e)}')
return {'message': 'Internal server error'}, 500