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

Commit

Permalink
Merge pull request #13 from loyal812/feat/refactor-project-with-one
Browse files Browse the repository at this point in the history
refactor: project as one
  • Loading branch information
loyal812 authored Mar 27, 2024
2 parents c286179 + e9d8a13 commit b46d02c
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 97 deletions.
130 changes: 115 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,41 @@ py .\check_api_key.py --payload_dir="./test/regression/regression_testxxx/payloa
"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
Expand Down Expand Up @@ -127,6 +162,7 @@ py .\check_api_key.py --payload_dir="./test/regression/regression_testxxx/payloa
![Alt text](./images/image-17.png)

### Project Setting
- Set the environment and run the project
```
sudo su
apt update
Expand Down Expand Up @@ -165,57 +201,121 @@ 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
POST
```
{
py .\script\create_api_key.py --api_url "api_url" --data_id "regression013" --user "user email" --title "title" --description "description"
```
- 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
POST
```
{
py .\script\delete_api_key.py --api_url "api_url" --data_id "regression013" --user "user email" --api_key "api key"
```
- 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
POST
```
{
py .\script\check_api_key.py --api_url "api_url" --data_id "regression013" --user "user email" --api_key "api key"
```
- 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
POST
```
{
py .\script\finetuning.py --api_url "api_url" --data_id "regression013" --user "user email" --api_key "api key"
```
- 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
POST
```
{
py .\script\conversation.py --api_url "api_url" --data_id "regression013" --user "user email" --api_key "api key" --question "hi"
```
- 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"
}
}'
```
50 changes: 50 additions & 0 deletions script/total_process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import gc
import argparse

from send_request import send_request

def total_process(args):
"""
main entry point
"""

data = {
"user": str(args.user),
"title": str(args.title),
"description": str(args.description),
"data_id": str(args.data_id),
"question": str(args.question)
}

result = send_request(args.api_url, data)

gc.collect()

print(result)

if __name__ == "__main__":
"""
Form command lines
"""
# Clean up buffer memory
gc.collect()

user = "user@gmail.com"
title = "title"
description = "description"
data_id = ""
api_url = "http://localhost:5000/total"
question = "hi"

# Add options
p = argparse.ArgumentParser()
p = argparse.ArgumentParser(description="Translate text within an image.")
p.add_argument("--api_url", type=str, default=api_url, help="URL to send the POST request to")
p.add_argument("--data_id", type=str, default=data_id, help="payload directory to the test example")
p.add_argument("--user", type=str, default=user, help="user")
p.add_argument("--title", type=str, default=title, help="title")
p.add_argument("--description", type=str, default=description, help="title")
p.add_argument("--question", type=str, default=question, help="user's question")
args = p.parse_args()

total_process(args)
58 changes: 54 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
from starlette.responses import RedirectResponse
from starlette.status import HTTP_201_CREATED

from src.models.main_model import MainModel
from src.models.basic_model import BasicModel
from src.models.create_api_model import CreateAPIModel
from src.models.chatting_model import ChattingModel
from src.models.main_model import MainModel

from utils.total_process import total_process
from utils.create_api import create_api_key
Expand Down Expand Up @@ -68,8 +69,57 @@ def get_payload_dir(data_id: str):

return payload_dir

@app.post("/total")
async def total(request_body: MainModel):
print("jeere")
payload_dir = get_payload_dir(request_body.data_id)

if request_body.user == "":
user = "user@gmail.com"
else:
user = request_body.user

args = {
'payload_dir' : payload_dir,
'user' : user,
'title' : request_body.title,
'description' : request_body.description,
'question': request_body.question
}

result_create_api = create_api_key(args)

if result_create_api['status'] == 'success':
print(result_create_api)

args = {
'payload_dir' : payload_dir,
'user' : user,
'title' : request_body.title,
'description' : request_body.description,
'question': request_body.question,
"api_key": result_create_api['api_key']
}

result_finetuning = total_process(args)

if result_finetuning['status'] == 'success':
print(result_finetuning)

result_chatting = chatting(args)
print(result_chatting)

return result_chatting
else:
print(result_finetuning)
return result_finetuning
else:
print(result_create_api)
return result_create_api


@app.post("/finetuning")
async def finetuning(request_body: MainModel):
async def finetuning(request_body: BasicModel):
payload_dir = get_payload_dir(request_body.data_id)

if request_body.user == "":
Expand Down Expand Up @@ -115,7 +165,7 @@ async def create_api(request_body: CreateAPIModel):


@app.post("/delete_api")
async def delete_api(request_body: MainModel):
async def delete_api(request_body: BasicModel):
payload_dir = get_payload_dir(request_body.data_id)

if request_body.user == "":
Expand All @@ -140,7 +190,7 @@ async def delete_api(request_body: MainModel):


@app.post("/check_api")
async def check_api(request_body: MainModel):
async def check_api(request_body: BasicModel):
payload_dir = get_payload_dir(request_body.data_id)

if request_body.user == "":
Expand Down
7 changes: 7 additions & 0 deletions src/models/basic_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import BaseModel
from typing import Optional

class BasicModel(BaseModel):
api_key: Optional[str] = ""
user: Optional[str] = ""
data_id: Optional[str] = ""
4 changes: 3 additions & 1 deletion src/models/main_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import Optional

class MainModel(BaseModel):
api_key: Optional[str] = ""
user: Optional[str] = ""
title: Optional[str] = ""
description: Optional[str] = ""
data_id: Optional[str] = ""
question: Optional[str] = "hi"
27 changes: 0 additions & 27 deletions src/utils/check_api_key.py

This file was deleted.

Loading

0 comments on commit b46d02c

Please sign in to comment.