From 37624db9f28021566839c1357525e15aa93fbf8e Mon Sep 17 00:00:00 2001 From: eureka320 Date: Wed, 27 Mar 2024 08:29:28 -0400 Subject: [PATCH] fix: conflict --- README.md | 222 +----------------------------------- src/utils/check_api_key.py | 27 +++++ src/utils/delete_api_key.py | 26 +++++ 3 files changed, 54 insertions(+), 221 deletions(-) create mode 100644 src/utils/check_api_key.py create mode 100644 src/utils/delete_api_key.py diff --git a/README.md b/README.md index df909d9..e9e5775 100644 --- a/README.md +++ b/README.md @@ -83,224 +83,4 @@ py .\check_api_key.py --payload_dir="./test/regression/regression_testxxx/payloa "mongo_uri": "mongodb+srv://{user_name}:{password}@cluster0.ill5gnu.mongodb.net", "db_name": "oridosai", "collection_name": "apis" -} - -### MongoDB Atlas Setting -- Create Account -Sign up with google signup or email. - -- Get the environment data -![Alt text](./images/image-18.png) - -![Alt text](./images/image-19.png) - -![Alt text](./images/image-20.png) - -![Alt text](./images/image-21.png) - -![Alt text](./images/image-22.png) - -Please save mongodb_username, mongodb_pasword and mongodb_cluster_name to your .env file. - -- Update the password -![Alt text](./images/image-23.png) - -![Alt text](./images/image-24.png) - -![Alt text](./images/image-25.png) - -![Alt text](./images/image-26.png) - -Please update mongodb_password to your .env file. - -- Create new User -![Alt text](./images/image-27.png) - -![Alt text](./images/image-28.png) - -Please save mongodb_username and mongodb_pasword to your .env file. - -### AWS EC2 - -- Launch Instance -![Alt text](./images/image.png) - -- Instance Setting -![Alt text](./images/image-1.png) - -![Alt text](./images/image-2.png) - -![Alt text](./images/image-3.png) - -![Alt text](./images/image-4.png) - -![Alt text](./images/image-5.png) - -- Elastic IP Setting -![Alt text](./images/image-7.png) - -![Alt text](./images/image-8.png) - -![Alt text](./images/image-9.png) - -![Alt text](./images/image-10.png) - -![Alt text](./images/image-11.png) - -- Security Group Setting -![Alt text](./images/image-12.png) - -![Alt text](./images/image-13.png) - -![Alt text](./images/image-14.png) - -![Alt text](./images/image-15.png) - -- Connect to Instance -![Alt text](./images/image-16.png) - -![Alt text](./images/image-17.png) - -### Project Setting -- Set the environment and run the project -``` -sudo su -apt update - -apt install apt-transport-https ca-certificates curl software-properties-common -curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - -add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" -apt-cache policy docker-ce -apt install docker-ce - -apt install docker-compose - -apt install make - -apt install nginx - -cd /var/www - -git clone https://github.com/oridosai/img2txt-fine-tuning-api.git - -cd img2txt-fine-tuning-api - -chmod -R 777 /var/www/img2txt-fine-tuning-api - -nano .env - -Please copy your local env data at this file and save. - -OPENAI_API_KEY= -MATHPIX_APP_ID= -MATHPIX_APP_KEY= -MONGODB_USERNAME= -MONGODB_PASSWORD= -MONGODB_CLUSTER_NAME= - -docker-compose up -d -``` - -- update the project and re-run -``` -git pull origin dev - -docker ps - -docker stop container_id - -docker rm container_id - -docker-compose up -d -``` - -### done -host your elastic ip - -http://{your elastic ip}:5000/create_api -- Postman -![Alt text](./images/image-29.png) - -- curl -``` -curl -X 'POST' \ - 'http://18.118.73.220:5000/create_api' \ - -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -d '{ - "user": "", - "title": "", - "description": "", - "data_id": "" -}' -``` - -http://{your elastic ip}:5000/delete_api -- Postman -![Alt text](./images/image-30.png) - -- curl -``` -curl -X 'POST' \ - 'http://18.118.73.220:5000/delete_api' \ - -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -d '{ - "api_key": "", - "user": "", - "data_id": "" -}' -``` - -http://{your elastic ip}:5000/check_api -- postman -![Alt text](./images/image-31.png) - -- curl -``` -curl -X 'POST' \ - 'http://18.118.73.220:5000/check_api' \ - -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -d '{ - "api_key": "", - "user": "", - "data_id": "" -}' - -``` - -http://{your elastic ip}:5000/finetuning -- postman -![Alt text](./images/image-33.png) - -- curl -``` -curl -X 'POST' \ - 'http://18.118.73.220:5000/finetuning' \ - -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -d '{ - "api_key": "", - "user": "", - "data_id": "" -}' -``` - -http://{your elastic ip}:5000/conversation -- postman -![Alt text](./images/image-32.png) - -- curl -``` -curl -X 'POST' \ - 'http://18.118.73.220:5000/conversation' \ - -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -d '{ - "api_key": "", - "user": "", - "data_id": "", - "question": "hi" -}' -``` +} \ No newline at end of file diff --git a/src/utils/check_api_key.py b/src/utils/check_api_key.py new file mode 100644 index 0000000..17a1590 --- /dev/null +++ b/src/utils/check_api_key.py @@ -0,0 +1,27 @@ +import gc +from pathlib import Path + +from src.utils.read_json import read_json +from src.mongodb.MongoDBClass import MongoDBClass + + +def check_api_key(args): + """ + main entry point + """ + + # Payload + payload_data = read_json(args['payload_dir']) + + # Construct the MongoDB Atlas URI + mongo_uri = payload_data["mongo_uri"] + + # Call class instance + mongodb = MongoDBClass( + db_name=payload_data["db_name"], + collection_name=payload_data["collection_name"], + mongo_uri=mongo_uri) + + mongodb.check_validation_api(api_key=str(Path(args['api_key'])), user=str(Path(args['user']))) + + gc.collect() \ No newline at end of file diff --git a/src/utils/delete_api_key.py b/src/utils/delete_api_key.py new file mode 100644 index 0000000..9472a9f --- /dev/null +++ b/src/utils/delete_api_key.py @@ -0,0 +1,26 @@ +import gc +from pathlib import Path + +from src.utils.read_json import read_json +from src.mongodb.MongoDBClass import MongoDBClass + +def delete_api_key(args): + """ + main entry point + """ + + # Payload + payload_data = read_json(args['payload_dir']) + + # Construct the MongoDB Atlas URI + mongo_uri = payload_data["mongo_uri"] + + # Call class instance + mongodb = MongoDBClass( + db_name=payload_data["db_name"], + collection_name=payload_data["collection_name"], + mongo_uri=mongo_uri) + + mongodb.delete_api(api_key=str(Path(args['api_key'])), user=str(Path(args['user']))) + + gc.collect() \ No newline at end of file