Skip to content

Commit

Permalink
Merge pull request #51 from A-Baji/dev
Browse files Browse the repository at this point in the history
3.0.5
  • Loading branch information
A-Baji authored Jul 9, 2024
2 parents 0d8abb4 + 282768c commit 2977f6e
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 179 deletions.
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
omit =
*/tests/*

[report]
exclude_lines =
if __name__ == "__main__":
fine_tune = client.fine_tuning.jobs.create
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [3.0.5] - 07-9-2024

### Added

- `--force` arg to model deletion
- error handling for when user was not found in logs

### Changed

- Include `tests/` within the package to allow reuse in parent package

## [3.0.4] - 07-1-2024

### Removed
Expand Down Expand Up @@ -109,6 +120,7 @@ Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and

- switched to `pathlib` for file path parsing

[3.0.5]: https://github.com/A-Baji/discordAI-modelizer/compare/3.0.4...3.0.5
[3.0.4]: https://github.com/A-Baji/discordAI-modelizer/compare/3.0.3...3.0.4
[3.0.3]: https://github.com/A-Baji/discordAI-modelizer/compare/3.0.2...3.0.3
[3.0.2]: https://github.com/A-Baji/discordAI-modelizer/compare/3.0.1...3.0.2
Expand Down
4 changes: 3 additions & 1 deletion discordai_modelizer/command_line/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def read_modelizer_args(args, model_subcommand, job_subcommand):
use_existing=args.use_existing,
)
elif args.subcommand == "delete":
display(openai_wrapper.delete_model(args.model_id, args.openai_key))
display(
openai_wrapper.delete_model(args.model_id, args.openai_key, args.force)
)
else:
raise argparse.ArgumentError(
model_subcommand,
Expand Down
11 changes: 11 additions & 0 deletions discordai_modelizer/command_line/subparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ def setup_model_delete(model_subcommand, is_parent=False):
model_delete_required_named = model_delete.add_argument_group(
"required named arguments"
)
model_delete_optional_named = model_delete.add_argument_group(
"optional named arguments"
)

model_delete_required_named.add_argument(
"-o",
Expand All @@ -194,6 +197,14 @@ def setup_model_delete(model_subcommand, is_parent=False):
help="Target model id",
)

model_delete_optional_named.add_argument(
"--force",
action="store_true",
required=False,
dest="force",
help="Skips the deletion confirmation dialogue",
)


def setup_job_list(job_subcommand, is_parent=False):
job_list = job_subcommand.add_parser(
Expand Down
22 changes: 13 additions & 9 deletions discordai_modelizer/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pathlib

from openai import OpenAI
from discordai_modelizer.gen_dataset import parse_logs, get_lines
from discordai_modelizer.gen_dataset import parse_logs, get_lines, UserNotFoundError

MODEL_MAP = {
"davinci": "davinci-002",
Expand Down Expand Up @@ -87,14 +87,18 @@ def create_model(
print("INFO: Using existing dataset... Skipping download and parsing.")
else:
print("INFO: Parsing chat logs into an openAI compatible dataset...")
parse_logs(
full_logs_path,
channel_id,
user_id,
thought_time,
thought_max,
thought_min,
)
try:
parse_logs(
full_logs_path,
channel_id,
user_id,
thought_time,
thought_max,
thought_min,
)
except UserNotFoundError as e:
print(f"ERROR: {e}")
return
get_lines(full_dataset_path, max_entry_count, offset, select_mode, reverse)
if not clean:
print(f"INFO: Dataset saved to {full_dataset_path}")
Expand Down
8 changes: 8 additions & 0 deletions discordai_modelizer/gen_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import pathlib


class UserNotFoundError(Exception):
pass


def parse_logs(
file: str,
channel: str,
Expand Down Expand Up @@ -78,6 +82,10 @@ def add_to_dataset(thought: str):
if msg["author"].get("name") == username
and (user_id is None or msg["author"].get("discriminator") == user_id)
]
if not messages:
raise UserNotFoundError(
f"No messages found in chat logs for user: {username}"
)
thought = build_thought("", messages[0])
for i, msg in enumerate(messages[1::]):
if msg["content"]:
Expand Down
10 changes: 7 additions & 3 deletions discordai_modelizer/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@ def cancel_job(job_id: str, openai_key: str = os.getenv("OPENAI_API_KEY")) -> di


def delete_model(
model_name: str, openai_key: str = os.getenv("OPENAI_API_KEY")
model_name: str, openai_key: str = os.getenv("OPENAI_API_KEY"), force=False
) -> dict:
confirm = input(
"Are you sure you want to delete this model? This action is not reversable. Y/N: "
confirm = (
"yes"
if force
else input(
"Are you sure you want to delete this model? This action is not reversable. Y/N: "
)
)
if confirm.lower() not in ["y", "yes"]:
print("Cancelling model deletion...")
Expand Down
File renamed without changes.
15 changes: 13 additions & 2 deletions tests/conftest.py → discordai_modelizer/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import pathlib
import appdirs
import pytest

from discordai_modelizer import customize
from pytest import fixture

CHANNEL_ID = os.environ["CHANNEL_ID"]
USER = os.environ["USERNAME"]
Expand All @@ -18,7 +18,7 @@ def list_dict_comp(x, y):
assert d1 == d2


@pytest.fixture(scope="session")
@fixture(scope="session")
def default_file_output():
# Ensure a clean start by removing any existing files
if FULL_LOGS_PATH.exists():
Expand All @@ -33,3 +33,14 @@ def default_file_output():
FULL_LOGS_PATH.unlink()
if FULL_DATASET_PATH.exists():
FULL_DATASET_PATH.unlink()


@fixture(scope="function")
def unset_envs():
DISCORD_BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"]
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
del os.environ["DISCORD_BOT_TOKEN"]
del os.environ["OPENAI_API_KEY"]
yield
os.environ["DISCORD_BOT_TOKEN"] = DISCORD_BOT_TOKEN
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
{"id": "dall-e-2", "created": "2023-11-01 00:22:57"},
{"id": "tts-1-hd-1106", "created": "2023-11-03 23:18:53"},
{"id": "tts-1-hd", "created": "2023-11-03 21:13:35"},
{"id": "gpt-4-turbo-2024-04-09", "created": "2024-04-08 18:41:17"},
{"id": "gpt-4-turbo", "created": "2024-04-05 23:57:21"},
{"id": "gpt-3.5-turbo-1106", "created": "2023-11-02 21:15:48"},
{"id": "dall-e-3", "created": "2023-10-31 20:46:29"},
{"id": "gpt-4-0125-preview", "created": "2024-01-23 19:20:12"},
{"id": "gpt-4-turbo-preview", "created": "2024-01-23 19:22:57"},
{"id": "text-embedding-3-small", "created": "2024-01-22 18:43:17"},
{"id": "text-embedding-3-large", "created": "2024-01-22 19:53:00"},
{"id": "gpt-3.5-turbo-16k", "created": "2023-05-10 22:35:02"},
{"id": "gpt-4-1106-preview", "created": "2023-11-02 20:33:26"},
{"id": "gpt-4-turbo-2024-04-09", "created": "2024-04-08 18:41:17"},
{"id": "babbage-002", "created": "2023-08-21 16:16:55"},
{"id": "gpt-4o-2024-05-13", "created": "2024-05-10 19:08:52"},
{"id": "gpt-4-turbo", "created": "2024-04-05 23:57:21"},
{"id": "gpt-4", "created": "2023-06-27 16:13:31"},
{"id": "gpt-4-0613", "created": "2023-06-12 16:54:56"},
{"id": "dall-e-3", "created": "2023-10-31 20:46:29"},
{"id": "gpt-3.5-turbo-0125", "created": "2024-01-23 22:19:18"},
{"id": "tts-1-1106", "created": "2023-11-03 23:14:01"},
{"id": "gpt-3.5-turbo", "created": "2023-02-28 18:56:42"},
Expand Down Expand Up @@ -203,12 +203,30 @@
"object": "model",
"owned_by": "system",
},
{
"id": "gpt-4-turbo-2024-04-09",
"created": "2024-04-08 18:41:17",
"object": "model",
"owned_by": "system",
},
{
"id": "gpt-4-turbo",
"created": "2024-04-05 23:57:21",
"object": "model",
"owned_by": "system",
},
{
"id": "gpt-3.5-turbo-1106",
"created": "2023-11-02 21:15:48",
"object": "model",
"owned_by": "system",
},
{
"id": "dall-e-3",
"created": "2023-10-31 20:46:29",
"object": "model",
"owned_by": "system",
},
{
"id": "gpt-4-0125-preview",
"created": "2024-01-23 19:20:12",
Expand Down Expand Up @@ -245,12 +263,6 @@
"object": "model",
"owned_by": "system",
},
{
"id": "gpt-4-turbo-2024-04-09",
"created": "2024-04-08 18:41:17",
"object": "model",
"owned_by": "system",
},
{
"id": "babbage-002",
"created": "2023-08-21 16:16:55",
Expand All @@ -263,12 +275,6 @@
"object": "model",
"owned_by": "system",
},
{
"id": "gpt-4-turbo",
"created": "2024-04-05 23:57:21",
"object": "model",
"owned_by": "system",
},
{
"id": "gpt-4",
"created": "2023-06-27 16:13:31",
Expand All @@ -281,12 +287,6 @@
"object": "model",
"owned_by": "openai",
},
{
"id": "dall-e-3",
"created": "2023-10-31 20:46:29",
"object": "model",
"owned_by": "system",
},
{
"id": "gpt-3.5-turbo-0125",
"created": "2024-01-23 22:19:18",
Expand Down
Loading

0 comments on commit 2977f6e

Please sign in to comment.