Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
refact: fix docker and refactored the project
Browse files Browse the repository at this point in the history
  • Loading branch information
eureka320 committed Mar 27, 2024
1 parent 5e76807 commit a6cf8cc
Show file tree
Hide file tree
Showing 60 changed files with 384 additions and 340 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
OPENAI_API_KEY=
MATHPIX_APP_ID=
MATHPIX_APP_KEY=
Mongo_URI=
MongoDB_USERNAME=
MongoDB_PASSWORD=
MONGODB_CLUSTER_NAME=
137 changes: 136 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,139 @@ 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"
}
}

### 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
```
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
```

### done
host your elastic ip

http://{your elastic ip}:5000/create_api
POST
```
{
"user": "",
"title": "",
"description": "",
"data_id": ""
}
```

http://{your elastic ip}:5000/delete_api
POST
```
{
"api_key": "",
"user": "",
"data_id": ""
}
```

http://{your elastic ip}:5000/check_api
POST
```
{
"api_key": "",
"user": "",
"data_id": ""
}
```

http://{your elastic ip}:5000/finetuning
POST
```
{
"api_key": "",
"user": "",
"data_id": ""
}
```

http://{your elastic ip}:5000/conversation
POST
```
{
"api_key": "",
"user": "",
"data_id": "",
"question": "hi"
}
```
13 changes: 1 addition & 12 deletions chatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import gc
import argparse
from pathlib import Path
from urllib.parse import quote_plus

from src.utils.read_json import read_json
from src.chatting.ChattingClass import ChattingClass
Expand All @@ -16,18 +15,8 @@ def chatting(args):
# Payload
payload_data = read_json(args.payload_dir)

# Your MongoDB Atlas connection details
mongodb_username = payload_data["mongodb_username"]
mongodb_password = payload_data["mongodb_password"]
mongodb_cluster_name = payload_data["mongodb_cluster_name"]
mongodb_database_name = payload_data["mongodb_database_name"]

# Escape the mongodb_username and mongodb_password
mongodb_escaped_username = quote_plus(mongodb_username)
mongodb_escaped_password = quote_plus(mongodb_password)

# Construct the MongoDB Atlas URI
mongo_uri = f"mongodb+srv://{mongodb_escaped_username}:{mongodb_escaped_password}@{mongodb_cluster_name}.mongodb.net/{mongodb_database_name}"
mongo_uri = payload_data["mongo_uri"]

# Call class instance
mongodb = MongoDBClass(
Expand Down
13 changes: 1 addition & 12 deletions check_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import gc
import argparse
from pathlib import Path
from urllib.parse import quote_plus

from src.utils.read_json import read_json
from src.mongodb.MongoDBClass import MongoDBClass
Expand All @@ -17,18 +16,8 @@ def check_api_key(args):
# Payload
payload_data = read_json(args.payload_dir)

# Your MongoDB Atlas connection details
mongodb_username = payload_data["mongodb_username"]
mongodb_password = payload_data["mongodb_password"]
mongodb_cluster_name = payload_data["mongodb_cluster_name"]
mongodb_database_name = payload_data["mongodb_database_name"]

# Escape the mongodb_username and mongodb_password
mongodb_escaped_username = quote_plus(mongodb_username)
mongodb_escaped_password = quote_plus(mongodb_password)

# Construct the MongoDB Atlas URI
mongo_uri = f"mongodb+srv://{mongodb_escaped_username}:{mongodb_escaped_password}@{mongodb_cluster_name}.mongodb.net/{mongodb_database_name}"
mongo_uri = payload_data["mongo_uri"]

# Call class instance
mongodb = MongoDBClass(
Expand Down
13 changes: 1 addition & 12 deletions create_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import argparse
from pathlib import Path
from datetime import datetime
from urllib.parse import quote_plus

from src.utils.read_json import read_json
from src.mongodb.MongoDBClass import MongoDBClass
Expand All @@ -19,18 +18,8 @@ def create_api_key(args):
# Payload
payload_data = read_json(args.payload_dir)

# Your MongoDB Atlas connection details
mongodb_username = payload_data["mongodb_username"]
mongodb_password = payload_data["mongodb_password"]
mongodb_cluster_name = payload_data["mongodb_cluster_name"]
mongodb_database_name = payload_data["mongodb_database_name"]

# Escape the mongodb_username and mongodb_password
mongodb_escaped_username = quote_plus(mongodb_username)
mongodb_escaped_password = quote_plus(mongodb_password)

# Construct the MongoDB Atlas URI
mongo_uri = f"mongodb+srv://{mongodb_escaped_username}:{mongodb_escaped_password}@{mongodb_cluster_name}.mongodb.net/{mongodb_database_name}"
mongo_uri = payload_data["mongo_uri"]

# Call class instance
mongodb = MongoDBClass(
Expand Down
13 changes: 1 addition & 12 deletions delete_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import gc
import argparse
from pathlib import Path
from urllib.parse import quote_plus

from src.utils.read_json import read_json
from src.mongodb.MongoDBClass import MongoDBClass
Expand All @@ -16,18 +15,8 @@ def delete_api_key(args):
# Payload
payload_data = read_json(args.payload_dir)

# Your MongoDB Atlas connection details
mongodb_username = payload_data["mongodb_username"]
mongodb_password = payload_data["mongodb_password"]
mongodb_cluster_name = payload_data["mongodb_cluster_name"]
mongodb_database_name = payload_data["mongodb_database_name"]

# Escape the mongodb_username and mongodb_password
mongodb_escaped_username = quote_plus(mongodb_username)
mongodb_escaped_password = quote_plus(mongodb_password)

# Construct the MongoDB Atlas URI
mongo_uri = f"mongodb+srv://{mongodb_escaped_username}:{mongodb_escaped_password}@{mongodb_cluster_name}.mongodb.net/{mongodb_database_name}"
mongo_uri = payload_data["mongo_uri"]

# Call class instance
mongodb = MongoDBClass(
Expand Down
Binary file added images/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image-9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 1 addition & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import time
import argparse
from pathlib import Path
from urllib.parse import quote_plus
import concurrent.futures
from datetime import datetime
import json
Expand All @@ -24,18 +23,8 @@ def total_process(args):

payload_data = read_json(args.payload_dir)

# Your MongoDB Atlas connection details
mongodb_username = payload_data["mongodb_username"]
mongodb_password = payload_data["mongodb_password"]
mongodb_cluster_name = payload_data["mongodb_cluster_name"]
mongodb_database_name = payload_data["mongodb_database_name"]

# Escape the mongodb_username and mongodb_password
mongodb_escaped_username = quote_plus(mongodb_username)
mongodb_escaped_password = quote_plus(mongodb_password)

# Construct the MongoDB Atlas URI
mongo_uri = f"mongodb+srv://{mongodb_escaped_username}:{mongodb_escaped_password}@{mongodb_cluster_name}.mongodb.net/{mongodb_database_name}"
mongo_uri = payload_data["mongo_uri"]

# Call class instance
mongodb = MongoDBClass(
Expand Down
4 changes: 4 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM python:3.11.0 as base

# Define a build argument named PROJECT with a default value of 'api'.
ARG PROJECT=src
ARG TEST=test

RUN apt-get update && apt-get install -y \
poppler-utils
Expand All @@ -27,6 +28,7 @@ RUN pip install --upgrade llama-index

# Copy the project files into the container.
COPY --chown=user:user ./$PROJECT /home/user/$PROJECT
COPY --chown=user:user ./$TEST /home/user/$TEST

# Copy the .env file into the container.
COPY --chown=user:user .env /home/user/.env
Expand All @@ -48,6 +50,8 @@ RUN pip install --upgrade llama-index
USER root
# Copy the project files into the container.
COPY --chown=user:user ./$PROJECT /home/user/$PROJECT
COPY --chown=user:user ./$TEST /home/user/$TEST

# Create a directory for mypy cache and change its ownership to the non-root user.
RUN mkdir /home/user/.mypy_cache && chown user:user -R /home/user/.mypy_cache
# Install pytest within the test stage
Expand Down
24 changes: 17 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

from utils.total_process import total_process
from utils.create_api import create_api_key
from utils.delete_api_key import delete_api_key
from utils.check_api_key import check_api_key
from src.utils.delete_api import delete_api_key
from src.utils.check_api import check_api_key
from utils.chatting import chatting

# Create a FastAPI application
Expand Down Expand Up @@ -88,7 +88,9 @@ async def finetuning(request_body: MainModel):
'api_key' : api_key
}

total_process(args)
result = total_process(args)

return result


@app.post("/create_api")
Expand All @@ -107,7 +109,9 @@ async def create_api(request_body: CreateAPIModel):
'description' : request_body.description
}

create_api_key(args)
result = create_api_key(args)

return result


@app.post("/delete_api")
Expand All @@ -130,7 +134,9 @@ async def delete_api(request_body: MainModel):
'api_key' : api_key
}

delete_api_key(args)
result = delete_api_key(args)

return result


@app.post("/check_api")
Expand All @@ -153,7 +159,9 @@ async def check_api(request_body: MainModel):
'api_key' : api_key
}

check_api_key(args)
result = check_api_key(args)

return result


@app.post("/conversation")
Expand All @@ -177,4 +185,6 @@ async def conversation(request_body: ChattingModel):
'question' : request_body.question
}

chatting(args)
result = chatting(args)

return result
Loading

0 comments on commit a6cf8cc

Please sign in to comment.