From dd74f281f9952b72721bdb1a6ff95d73ea1f7078 Mon Sep 17 00:00:00 2001 From: Jay Moran Date: Wed, 12 Apr 2023 12:23:15 -0700 Subject: [PATCH] removing temp folder and updated raml and api docs --- docker-compose-doc-builder.yml | 3 +- docs/APIs/execapi.raml | 126 ++++++++++++++++++++++++++++++ docs/APIs/execapi.yaml | 137 +++++++++++++++++++++++++++++++++ docs/source/execapi.rst | 6 ++ docs/source/index.rst | 1 + lab/routes/execapi.js | 26 +++---- 6 files changed, 282 insertions(+), 17 deletions(-) create mode 100644 docs/APIs/execapi.raml create mode 100644 docs/APIs/execapi.yaml create mode 100644 docs/source/execapi.rst diff --git a/docker-compose-doc-builder.yml b/docker-compose-doc-builder.yml index 470645933..7b6e06824 100644 --- a/docker-compose-doc-builder.yml +++ b/docker-compose-doc-builder.yml @@ -20,6 +20,7 @@ services: command: bash -c "npm i -g raml2html && raml2html /appsrc/lab/api.raml > /appsrc/target/ai_docs/html/lab_api_source.html && raml2html /appsrc/docs/APIs/openai.raml > /appsrc/target/ai_docs/html/openai_source.html && - raml2html /appsrc/docs/APIs/chatapi.raml > /appsrc/target/ai_docs/html/chatapi_source.html" + raml2html /appsrc/docs/APIs/chatapi.raml > /appsrc/target/ai_docs/html/chatapi_source.html && + raml2html /appsrc/docs/APIs/execapi.raml > /appsrc/target/ai_docs/html/execapi_source.html" volumes: - "./:/appsrc" diff --git a/docs/APIs/execapi.raml b/docs/APIs/execapi.raml new file mode 100644 index 000000000..4b065986d --- /dev/null +++ b/docs/APIs/execapi.raml @@ -0,0 +1,126 @@ +#%RAML 1.0 +title: Execution API +version: v1 +baseUri: http://localhost:5080/execapi/{version} +mediaType: application/json + +types: + file: + type: object + properties: + _id: + type: string + filename: + type: string + mimetype: + type: string + timestamp: + type: string + execution: + type: object + properties: + _id: + type: string + src_code: + type: string + status: + type: string + enum: [submitted, completed, error] + result: + type: string + files: + type: array + items: file + _dataset_file_id?: + type: string + _dataset_id?: + type: string + _experiment_id?: + type: string + +/executions: + post: + description: Create a new execution + body: + application/json: + properties: + src_code: + type: string + dataset_file_id?: + type: string + dataset_id?: + type: string + experiment_id?: + type: string + example: + { + "src_code": "df_new = df.head(10)\ndf_new.to_csv('example.csv')", + "dataset_id": "444555666", + "experiment_id": "777888999" + } + responses: + 200: + body: + application/json: + type: execution + example: + { + "_id": "987654321", + "src_code": "df_new = df.head(10)\ndf_new.to_csv('example.csv')", + "status": "completed", + "result": "Hello, world!", + "files": [ + { + "_id": "123456789", + "filename": "example.csv", + "mimetype": "text/csv", + "timestamp": "2023-04-11T12:34:56Z" + } + ], + "_dataset_file_id": "111222333", + "_dataset_id": "444555666", + "_experiment_id": "777888999" + } + 400: + body: + application/json: + properties: + message: + type: string + example: { "message": 'No src_code provided' } + /{id}: + uriParameters: + id: + type: string + get: + description: Get execution by id + responses: + 200: + body: + application/json: + type: execution + example: + { + "_id": "987654321", + "src_code": "df_new = df.head(10)\ndf_new.to_csv('example.csv')", + "status": "completed", + "result": "Hello, world!", + "files": [ + { + "_id": "123456789", + "filename": "example.csv", + "mimetype": "text/csv", + "timestamp": "2023-04-11T12:34:56Z" + } + ], + "_dataset_file_id": "111222333", + "_dataset_id": "444555666", + "_experiment_id": "777888999" + } + 404: + body: + application/json: + properties: + message: + type: string + example: { message: 'Cannot find execution: 123456789' } diff --git a/docs/APIs/execapi.yaml b/docs/APIs/execapi.yaml new file mode 100644 index 000000000..a8ef656b2 --- /dev/null +++ b/docs/APIs/execapi.yaml @@ -0,0 +1,137 @@ +swagger: '2.0' +info: + title: Execution API + version: v1 +basePath: /execapi/v1 +consumes: + - application/json +produces: + - application/json + +definitions: + file: + type: object + properties: + _id: + type: string + filename: + type: string + mimetype: + type: string + timestamp: + type: string + execution: + type: object + properties: + _id: + type: string + src_code: + type: string + status: + type: string + enum: + - submitted + - completed + - error + result: + type: string + files: + type: array + items: + $ref: '#/definitions/file' + _dataset_file_id: + type: string + _dataset_id: + type: string + _experiment_id: + type: string + +paths: + /executions: + post: + summary: Create a new execution + consumes: + - application/json + produces: + - application/json + parameters: + - in: body + name: execution + schema: + type: object + properties: + src_code: + type: string + dataset_file_id: + type: string + dataset_id: + type: string + experiment_id: + type: string + example: + src_code: df_new = df.head(10)\ndf_new.to_csv('example.csv') + dataset_id: '444555666' + experiment_id: '777888999' + responses: + 200: + description: Execution created successfully + schema: + $ref: '#/definitions/execution' + examples: + application/json: + _id: '987654321' + src_code: df_new = df.head(10)\ndf_new.to_csv('example.csv') + status: completed + result: Hello, world! + files: + - _id: '123456789' + filename: example.csv + mimetype: text/csv + timestamp: '2023-04-11T12:34:56Z' + _dataset_file_id: '111222333' + _dataset_id: '444555666' + _experiment_id: '777888999' + 400: + description: Bad request + schema: + type: object + properties: + message: + type: string + example: { message: No src_code provided } + /{id}: + get: + summary: Get execution by id + parameters: + - in: path + name: id + description: ID of the execution + type: string + required: true + responses: + 200: + description: Execution found + schema: + $ref: '#/definitions/execution' + examples: + application/json: + _id: '987654321' + src_code: df_new = df.head(10)\ndf_new.to_csv('example.csv') + status: completed + result: Hello, world! + files: + - _id: '123456789' + filename: example.csv + mimetype: text/csv + timestamp: '2023-04-11T12:34:56Z' + _dataset_file_id: '111222333' + _dataset_id: '444555666' + _experiment_id: '777888999' + 404: + description: Execution not found + schema: + type: object + properties: + message: + type: string + example: { message: Cannot find execution 123456789 } diff --git a/docs/source/execapi.rst b/docs/source/execapi.rst new file mode 100644 index 000000000..d731cb5a2 --- /dev/null +++ b/docs/source/execapi.rst @@ -0,0 +1,6 @@ +Code Execution API +======== + +.. raw:: html + + \ No newline at end of file diff --git a/docs/source/index.rst b/docs/source/index.rst index f2da98002..3f3b035ad 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -21,6 +21,7 @@ And, it has an *AI* assistant that can choose the analysis to run for you. lab_api openai_api chatapi + execapi ai recommenders api diff --git a/lab/routes/execapi.js b/lab/routes/execapi.js index 886e676f4..c0dd7bc8f 100644 --- a/lab/routes/execapi.js +++ b/lab/routes/execapi.js @@ -26,9 +26,6 @@ router.post('/executions', async (req, res, next) => { // return res.status(400).json({ message: 'no chatlog_id provided' }); // } - // let request = { - // src_code: req.body.src_code, - // }; // create a new execution let execution = new Execution({ src_code: req.body.src_code, @@ -38,29 +35,21 @@ router.post('/executions', async (req, res, next) => { }); if (req.body.dataset_file_id != null) { - // request.dataset_file_id = req.body.dataset_file_id; execution._dataset_file_id = req.body.dataset_file_id; } else if (req.body.dataset_id != null) { execution._dataset_id = req.body.dataset_id; let dataset = await getDatasetById(req.body.dataset_id); if (dataset != null) { - // request.dataset_file_id = dataset.files[0]._id; execution._dataset_file_id = dataset.files[0]._id; } } - // if (request.dataset_file_id != null) { - // execution._dataset_file_id = request.dataset_file_id; - // } - if (req.body.experiment_id != null) { execution._experiment_id = req.body.experiment_id; - // request.experiment_id = req.body.experiment_id; } try { const newExecution = await execution.save(); - // request.execution_id = newExecution._id; execution._id = newExecution._id; } catch (err) { return res.status(500).json({ message: err.message }); @@ -87,23 +76,29 @@ router.post('/executions', async (req, res, next) => { headers: { 'Content-Type': 'application/json' }, - // body: JSON.stringify(request) body: JSON.stringify(execution) }); result = await result.json(); // update the execution status execution.status = result.exec_results.status; - // execution._dataset_file_id = request.dataset_file_id; execution.result = result.exec_results.result; // add any generated files in tmppath to the execution.files array - // const files = await uploadExecFiles(request.execution_id, tmppath); const files = await uploadExecFiles(execution._id, tmppath); execution.files = files; const updatedExecution = await execution.save(); - // result.files = files; + + // delete the tmp folder + fs.rm(tmppath, { recursive: true }, (err) => { + if (err) { + console.error(err); + } else { + console.log(tmppath + ' folder deleted'); + } + }); + res.send(execution); } catch (err) { @@ -134,5 +129,4 @@ router.patch('/executions/:id', getExecutionById, async (req, res, next) => { } }); - module.exports = router;