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 #12 from loyal812/feat/script
Browse files Browse the repository at this point in the history
Feat/script
  • Loading branch information
loyal812 committed Mar 27, 2024
2 parents 1105f57 + 37624db commit c286179
Show file tree
Hide file tree
Showing 32 changed files with 371 additions and 18 deletions.
Binary file added images/image-18.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-19.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-20.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-21.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-22.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-23.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-24.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-25.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-26.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-27.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-28.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-29.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-30.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-31.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-32.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-33.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions script/chatting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import gc
import argparse

from send_request import send_request

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

data = {
"api_key": str(args.api_key),
"user": str(args.user),
"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 = "[email protected]"
api_key = "AMEYbpdcmrUxNu_Fb80qutukUZdlsmYiH4g7As5LzNA"
data_id = ""
api_url = "http://localhost:8000/conversation"
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("--question", type=str, default=question, help="user's question")
p.add_argument("--api_key", type=str, default=api_key, help="api key")
args = p.parse_args()


chatting(args)
44 changes: 44 additions & 0 deletions script/check_api_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import gc
import argparse

from send_request import send_request

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

data = {
"api_key": str(args.api_key),
"user": str(args.user),
"data_id": str(args.data_id)
}

result = send_request(args.api_url, data)

gc.collect()

print(result)

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

user = "[email protected]"
api_key = "AMEYbpdcmrUxNu_Fb80qutukUZdlsmYiH4g7As5LzNA"
data_id = ""
api_url = "http://localhost:8000/check_api"

# 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("--api_key", type=str, default=api_key, help="api key")
args = p.parse_args()

check_api_key(args)
47 changes: 47 additions & 0 deletions script/create_api_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import gc
import argparse

from send_request import send_request

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

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

result = send_request(args.api_url, data)

gc.collect()

print(result)

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

user = "[email protected]"
title = "title"
description = "description"
data_id = ""
api_url = "http://localhost:8000/create_api"

# 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")
args = p.parse_args()

create_api_key(args)
45 changes: 45 additions & 0 deletions script/delete_api_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import gc
import argparse

from send_request import send_request

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

data = {
"api_key": str(args.api_key),
"user": str(args.user),
"data_id": str(args.data_id)
}

result = send_request(args.api_url, data)

gc.collect()

print(result)

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

user = "[email protected]"
api_key = "AMEYbpdcmrUxNu_Fb80qutukUZdlsmYiH4g7As5LzNA"
data_id = ""
api_url = "http://localhost:8000/delete_api"

# 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("--api_key", type=str, default=api_key, help="api key")
args = p.parse_args()


delete_api_key(args)
44 changes: 44 additions & 0 deletions script/finetuning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import gc
import argparse

from send_request import send_request

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

data = {
"api_key": str(args.api_key),
"user": str(args.user),
"data_id": str(args.data_id)
}

result = send_request(args.api_url, data)

gc.collect()

print(result)

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

user = "[email protected]"
api_key = "AMEYbpdcmrUxNu_Fb80qutukUZdlsmYiH4g7As5LzNA"
data_id = ""
api_url = "http://localhost:8000/finetuning"

# 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("--api_key", type=str, default=api_key, help="api key")
args = p.parse_args()

run_fine_tuning(args)
23 changes: 23 additions & 0 deletions script/send_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import requests
import json
import os

def send_request(api_url, data):
"""Sends a POST request to the specified URL with the provided data."""
headers = {
'accept': 'application/json',
'Content-Type': 'application/json'
}

try:
# Convert WindowsPath to string in the data dictionary
data = {key: str(val) if isinstance(val, os.PathLike) else val for key, val in data.items()}

response = requests.post(api_url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
return response.json()
else:
raise Exception(f"Request failed with status code: {response.status_code}")
except Exception as e:
raise Exception(f"An error occurred while sending the request: {e}")

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
16 changes: 9 additions & 7 deletions src/mongodb/MongoDBClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ def create_api(self, data:APIModel):
# Check if the insertion was successful
if result.inserted_id:
print("New item has been added to the collection with ID:", result.inserted_id)
return True
return {"status": "success", "api_key": data['api'], "message": f"New item has been added to the collection with ID: {result.inserted_id}"}
else:
print("Failed to add a new item to the collection")
return False
return {"status": "failed", "message": "Failed to add a new item to the collection"}
else:
return db
return {"status": "failed", "message": "Failed to add a new item to the collection"}

def delete_api(self, api_key, user):
# Connect to MongoDB
Expand All @@ -149,10 +149,12 @@ def delete_api(self, api_key, user):
result = collection.update_one(filter_condition, update_operation)
if result.modified_count == 1:
print("Document updated successfully")
return {"status": "success", "message": "Successfully deleted"}
else:
print("No matching document found")
return {"status": "failed", "message": "No matching document found"}
else:
return db
return {"status": "failed", "message": "No matching document found"}

def check_validation_api(self, api_key, user):
# Connect to MongoDB
Expand All @@ -168,9 +170,9 @@ def check_validation_api(self, api_key, user):
existing_document = collection.find_one(filter_condition)
if existing_document:
print("Document exists in the collection")
return True
return {"status": "success", "message": "Document exists in the collection"}
else:
print("Document does not exist in the collection")
return False
return {"status": "failed", "message": "Document does not exist in the collection"}
else:
return db
return {"status": "failed", "message": "Document does not exist in the collection"}
Loading

0 comments on commit c286179

Please sign in to comment.