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

Commit

Permalink
refactor: add comment
Browse files Browse the repository at this point in the history
Co-authored-by: loyal812 <jh.chan0812@gmail.com>
  • Loading branch information
eureka320 and loyal812 committed Mar 27, 2024
1 parent ea1f6a7 commit 1ad9d46
Show file tree
Hide file tree
Showing 43 changed files with 576 additions and 248 deletions.
32 changes: 17 additions & 15 deletions chatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,36 @@

def chatting(args):
"""
main entry point
Main entry point for the chatting process
Args:
args: Command line arguments
"""

# Payload
# Load payload data from the provided directory
payload_data = read_json(args.payload_dir)

# Construct the MongoDB Atlas URI
# Extract MongoDB URI from payload data
mongo_uri = payload_data["mongo_uri"]

# Call class instance
# Create an instance of MongoDBClass for database operations
mongodb = MongoDBClass(
db_name=payload_data["db_name"],
collection_name=payload_data["collection_name"],
mongo_uri=mongo_uri)

# Check if the API key is valid using MongoDB
is_available = mongodb.check_validation_api(api_key=str(Path(args.api_key)), user=str(Path(args.user)))

if is_available:
print("valid api key")
# Call class instance
# Initialize the ChattingClass instance for conversation
chatting = ChattingClass(
data_path=payload_data["data_path"],
api_key=payload_data["api_key"],
model_id=payload_data["model_id"],
temperature=payload_data["temperature"])


# Ask a question using the ChattingClass instance and get the response
response = chatting.ask_question(args.question)
print(response)
else:
Expand All @@ -43,12 +47,10 @@ def chatting(args):
gc.collect()

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

# Default values for command line arguments
# Current directory
current_dir = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -60,13 +62,13 @@ def chatting(args):
user = "user@gmail.com"
api_key = "AMEYbpdcmrUxNu_Fb80qutukUZdlsmYiH4g7As5LzNA1"

# Add options
p = argparse.ArgumentParser()
# Set up command line argument parser
p = argparse.ArgumentParser(description="Conversational Agent.")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="payload directory to the test example")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="Data directory")
p.add_argument("--question", type=str)
p.add_argument("--user", type=Path, default=user, help="user")
p.add_argument("--api_key", type=Path, default=api_key, help="title")
p.add_argument("--user", type=Path, default=user, help="User Email")
p.add_argument("--api_key", type=Path, default=api_key, help="API key")
args = p.parse_args()

# Call the chatting function with the parsed arguments
chatting(args)
32 changes: 17 additions & 15 deletions check_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,34 @@

def check_api_key(args):
"""
main entry point
Main function to check the validation of an API key
Args:
- args (argparse.Namespace): Parsed command-line arguments
"""

# Payload
# Load payload data from a JSON file
payload_data = read_json(args.payload_dir)

# Construct the MongoDB Atlas URI
# Extract MongoDB URI from payload data
mongo_uri = payload_data["mongo_uri"]

# Call class instance
# Create an instance of MongoDBClass to interact with the database
mongodb = MongoDBClass(
db_name=payload_data["db_name"],
collection_name=payload_data["collection_name"],
mongo_uri=mongo_uri)

# Check the validation of the API key and the user
mongodb.check_validation_api(api_key=str(Path(args.api_key)), user=str(Path(args.user)))

# Perform garbage collection to free up memory
gc.collect()

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

# Default values for command line arguments
# Current directory
current_dir = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -47,12 +49,12 @@ def check_api_key(args):
user = "user@gmail.com"
api_key = "AMEYbpdcmrUxNu_Fb80qutukUZdlsmYiH4g7As5LzNA"

# Add options
p = argparse.ArgumentParser()
p = argparse.ArgumentParser(description="Translate text within an image.")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="payload directory to the test example")
p.add_argument("--user", type=Path, default=user, help="user")
p.add_argument("--api_key", type=Path, default=api_key, help="title")
# Set up command line argument parser
p = argparse.ArgumentParser(description="Check the API key.")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="Data directory")
p.add_argument("--user", type=Path, default=user, help="User Email")
p.add_argument("--api_key", type=Path, default=api_key, help="API key")
args = p.parse_args()

# Call the check_api_key function with the parsed arguments
check_api_key(args)
35 changes: 20 additions & 15 deletions create_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@

def create_api_key(args):
"""
main entry point
Main function to create an API key and store it in a MongoDB database.
Args:
- args (argparse.Namespace): Parsed command-line arguments
"""

# Payload
# Load payload data from a JSON file
payload_data = read_json(args.payload_dir)

# Construct the MongoDB Atlas URI
# Extract MongoDB URI from payload data
mongo_uri = payload_data["mongo_uri"]

# Call class instance
# Create an instance of MongoDBClass to interact with the database
mongodb = MongoDBClass(
db_name=payload_data["db_name"],
collection_name=payload_data["collection_name"],
mongo_uri=mongo_uri)

# Generate a new API key
api_key = generate_api_key()

# Prepare the data for the new API using APIModel
data:APIModel = {
"user": str(Path(args.user)),
"api": api_key,
Expand All @@ -39,17 +44,17 @@ def create_api_key(args):
"updated_at": datetime.now(),
}

# Store the API key data in the MongoDB database
mongodb.create_api(data)

# Perform garbage collection to free up memory
gc.collect()

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

# Default values for command line arguments
# Current directory
current_dir = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -62,13 +67,13 @@ def create_api_key(args):
title = "title"
description = "description"

# Add options
p = argparse.ArgumentParser()
p = argparse.ArgumentParser(description="Translate text within an image.")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="payload directory to the test example")
p.add_argument("--user", type=Path, default=user, help="user")
p.add_argument("--title", type=Path, default=title, help="title")
p.add_argument("--description", type=Path, default=description, help="title")
# Set up command line argument parser
p = argparse.ArgumentParser(description="Create API key.")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="Data directory")
p.add_argument("--user", type=Path, default=user, help="User Email")
p.add_argument("--title", type=Path, default=title, help="Title")
p.add_argument("--description", type=Path, default=description, help="Description")
args = p.parse_args()

# Call the create_api_key function with the parsed arguments
create_api_key(args)
30 changes: 16 additions & 14 deletions delete_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,35 @@

def delete_api_key(args):
"""
main entry point
Main function to delete an API key from the MongoDB database collection.
Args:
- args (argparse.Namespace): Parsed command-line arguments
"""

# Payload
# Load payload data from a JSON file
payload_data = read_json(args.payload_dir)

# Construct the MongoDB Atlas URI
# Extract MongoDB URI from payload data
mongo_uri = payload_data["mongo_uri"]

# Call class instance
# Create an instance of MongoDBClass to interact with the database
mongodb = MongoDBClass(
db_name=payload_data["db_name"],
collection_name=payload_data["collection_name"],
mongo_uri=mongo_uri)

# Delete the API key identified by the user and the API key value
mongodb.delete_api(api_key=str(Path(args.api_key)), user=str(Path(args.user)))

# Perform garbage collection to free up memory
gc.collect()

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

# Default values for command line arguments
# Current directory
current_dir = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -46,12 +49,11 @@ def delete_api_key(args):
user = "user@gmail.com"
api_key = "AMEYbpdcmrUxNu_Fb80qutukUZdlsmYiH4g7As5LzNA"

# Add options
p = argparse.ArgumentParser()
p = argparse.ArgumentParser(description="Translate text within an image.")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="payload directory to the test example")
p.add_argument("--user", type=Path, default=user, help="user")
p.add_argument("--api_key", type=Path, default=api_key, help="title")
# Set up command line argument parser
p = argparse.ArgumentParser(description="Delete API key.")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="Data directory")
p.add_argument("--user", type=Path, default=user, help="User Email")
p.add_argument("--api_key", type=Path, default=api_key, help="API key")
args = p.parse_args()

delete_api_key(args)
22 changes: 12 additions & 10 deletions finetuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

def run_fine_tuning(args):
"""
main entry point
Main function to execute the fine-tuning process using the provided payload.
Args:
- args (argparse.Namespace): Parsed command-line arguments
"""

# Payload
# Load payload data from a JSON file
payload_data = read_json(args.payload_dir)

# Call class instance
# Create an instance of FineTuningClass to handle the fine-tuning process
fine_tune = FineTuningClass(
data_path=payload_data["data_path"],
parent_path=payload_data["parent_path"],
Expand All @@ -32,15 +35,14 @@ def run_fine_tuning(args):
# Fine tuning
fine_tune.finetune()

# Perform garbage collection to free up memory
gc.collect()

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

# Default values for command line arguments
# Current directory
current_dir = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -49,10 +51,10 @@ def run_fine_tuning(args):
payload_name = "finetuning_payload.json"
payload_dir = os.path.join(current_dir, "test", "regression", test_name, "payload", payload_name)

# Add options
p = argparse.ArgumentParser()
# Set up command line argument parser
p = argparse.ArgumentParser(description="Fine tuning.")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="payload directory to the test example")
p.add_argument("--payload_dir", type=Path, default=payload_dir, help="Data directory")
args = p.parse_args()

# Call the run_fine_tuning function with the parsed arguments
run_fine_tuning(args)
Loading

0 comments on commit 1ad9d46

Please sign in to comment.