Skip to content

Commit 2977f6e

Browse files
authored
Merge pull request #51 from A-Baji/dev
3.0.5
2 parents 0d8abb4 + 282768c commit 2977f6e

18 files changed

+291
-179
lines changed

.coveragerc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[run]
2+
omit =
3+
*/tests/*
4+
5+
[report]
6+
exclude_lines =
7+
if __name__ == "__main__":
8+
fine_tune = client.fine_tuning.jobs.create

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

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

5+
## [3.0.5] - 07-9-2024
6+
7+
### Added
8+
9+
- `--force` arg to model deletion
10+
- error handling for when user was not found in logs
11+
12+
### Changed
13+
14+
- Include `tests/` within the package to allow reuse in parent package
15+
516
## [3.0.4] - 07-1-2024
617

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

110121
- switched to `pathlib` for file path parsing
111122

123+
[3.0.5]: https://github.com/A-Baji/discordAI-modelizer/compare/3.0.4...3.0.5
112124
[3.0.4]: https://github.com/A-Baji/discordAI-modelizer/compare/3.0.3...3.0.4
113125
[3.0.3]: https://github.com/A-Baji/discordAI-modelizer/compare/3.0.2...3.0.3
114126
[3.0.2]: https://github.com/A-Baji/discordAI-modelizer/compare/3.0.1...3.0.2

discordai_modelizer/command_line/command_line.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def read_modelizer_args(args, model_subcommand, job_subcommand):
5555
use_existing=args.use_existing,
5656
)
5757
elif args.subcommand == "delete":
58-
display(openai_wrapper.delete_model(args.model_id, args.openai_key))
58+
display(
59+
openai_wrapper.delete_model(args.model_id, args.openai_key, args.force)
60+
)
5961
else:
6062
raise argparse.ArgumentError(
6163
model_subcommand,

discordai_modelizer/command_line/subparsers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ def setup_model_delete(model_subcommand, is_parent=False):
177177
model_delete_required_named = model_delete.add_argument_group(
178178
"required named arguments"
179179
)
180+
model_delete_optional_named = model_delete.add_argument_group(
181+
"optional named arguments"
182+
)
180183

181184
model_delete_required_named.add_argument(
182185
"-o",
@@ -194,6 +197,14 @@ def setup_model_delete(model_subcommand, is_parent=False):
194197
help="Target model id",
195198
)
196199

200+
model_delete_optional_named.add_argument(
201+
"--force",
202+
action="store_true",
203+
required=False,
204+
dest="force",
205+
help="Skips the deletion confirmation dialogue",
206+
)
207+
197208

198209
def setup_job_list(job_subcommand, is_parent=False):
199210
job_list = job_subcommand.add_parser(

discordai_modelizer/customize.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pathlib
66

77
from openai import OpenAI
8-
from discordai_modelizer.gen_dataset import parse_logs, get_lines
8+
from discordai_modelizer.gen_dataset import parse_logs, get_lines, UserNotFoundError
99

1010
MODEL_MAP = {
1111
"davinci": "davinci-002",
@@ -87,14 +87,18 @@ def create_model(
8787
print("INFO: Using existing dataset... Skipping download and parsing.")
8888
else:
8989
print("INFO: Parsing chat logs into an openAI compatible dataset...")
90-
parse_logs(
91-
full_logs_path,
92-
channel_id,
93-
user_id,
94-
thought_time,
95-
thought_max,
96-
thought_min,
97-
)
90+
try:
91+
parse_logs(
92+
full_logs_path,
93+
channel_id,
94+
user_id,
95+
thought_time,
96+
thought_max,
97+
thought_min,
98+
)
99+
except UserNotFoundError as e:
100+
print(f"ERROR: {e}")
101+
return
98102
get_lines(full_dataset_path, max_entry_count, offset, select_mode, reverse)
99103
if not clean:
100104
print(f"INFO: Dataset saved to {full_dataset_path}")

discordai_modelizer/gen_dataset.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import pathlib
1010

1111

12+
class UserNotFoundError(Exception):
13+
pass
14+
15+
1216
def parse_logs(
1317
file: str,
1418
channel: str,
@@ -78,6 +82,10 @@ def add_to_dataset(thought: str):
7882
if msg["author"].get("name") == username
7983
and (user_id is None or msg["author"].get("discriminator") == user_id)
8084
]
85+
if not messages:
86+
raise UserNotFoundError(
87+
f"No messages found in chat logs for user: {username}"
88+
)
8189
thought = build_thought("", messages[0])
8290
for i, msg in enumerate(messages[1::]):
8391
if msg["content"]:

discordai_modelizer/openai.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,14 @@ def cancel_job(job_id: str, openai_key: str = os.getenv("OPENAI_API_KEY")) -> di
9898

9999

100100
def delete_model(
101-
model_name: str, openai_key: str = os.getenv("OPENAI_API_KEY")
101+
model_name: str, openai_key: str = os.getenv("OPENAI_API_KEY"), force=False
102102
) -> dict:
103-
confirm = input(
104-
"Are you sure you want to delete this model? This action is not reversable. Y/N: "
103+
confirm = (
104+
"yes"
105+
if force
106+
else input(
107+
"Are you sure you want to delete this model? This action is not reversable. Y/N: "
108+
)
105109
)
106110
if confirm.lower() not in ["y", "yes"]:
107111
print("Cancelling model deletion...")
File renamed without changes.

tests/conftest.py renamed to discordai_modelizer/tests/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
import pathlib
33
import appdirs
4-
import pytest
54

65
from discordai_modelizer import customize
6+
from pytest import fixture
77

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

2020

21-
@pytest.fixture(scope="session")
21+
@fixture(scope="session")
2222
def default_file_output():
2323
# Ensure a clean start by removing any existing files
2424
if FULL_LOGS_PATH.exists():
@@ -33,3 +33,14 @@ def default_file_output():
3333
FULL_LOGS_PATH.unlink()
3434
if FULL_DATASET_PATH.exists():
3535
FULL_DATASET_PATH.unlink()
36+
37+
38+
@fixture(scope="function")
39+
def unset_envs():
40+
DISCORD_BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"]
41+
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
42+
del os.environ["DISCORD_BOT_TOKEN"]
43+
del os.environ["OPENAI_API_KEY"]
44+
yield
45+
os.environ["DISCORD_BOT_TOKEN"] = DISCORD_BOT_TOKEN
46+
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY

tests/expected_values.py renamed to discordai_modelizer/tests/expected_values.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
{"id": "dall-e-2", "created": "2023-11-01 00:22:57"},
55
{"id": "tts-1-hd-1106", "created": "2023-11-03 23:18:53"},
66
{"id": "tts-1-hd", "created": "2023-11-03 21:13:35"},
7+
{"id": "gpt-4-turbo-2024-04-09", "created": "2024-04-08 18:41:17"},
8+
{"id": "gpt-4-turbo", "created": "2024-04-05 23:57:21"},
79
{"id": "gpt-3.5-turbo-1106", "created": "2023-11-02 21:15:48"},
10+
{"id": "dall-e-3", "created": "2023-10-31 20:46:29"},
811
{"id": "gpt-4-0125-preview", "created": "2024-01-23 19:20:12"},
912
{"id": "gpt-4-turbo-preview", "created": "2024-01-23 19:22:57"},
1013
{"id": "text-embedding-3-small", "created": "2024-01-22 18:43:17"},
1114
{"id": "text-embedding-3-large", "created": "2024-01-22 19:53:00"},
1215
{"id": "gpt-3.5-turbo-16k", "created": "2023-05-10 22:35:02"},
1316
{"id": "gpt-4-1106-preview", "created": "2023-11-02 20:33:26"},
14-
{"id": "gpt-4-turbo-2024-04-09", "created": "2024-04-08 18:41:17"},
1517
{"id": "babbage-002", "created": "2023-08-21 16:16:55"},
1618
{"id": "gpt-4o-2024-05-13", "created": "2024-05-10 19:08:52"},
17-
{"id": "gpt-4-turbo", "created": "2024-04-05 23:57:21"},
1819
{"id": "gpt-4", "created": "2023-06-27 16:13:31"},
1920
{"id": "gpt-4-0613", "created": "2023-06-12 16:54:56"},
20-
{"id": "dall-e-3", "created": "2023-10-31 20:46:29"},
2121
{"id": "gpt-3.5-turbo-0125", "created": "2024-01-23 22:19:18"},
2222
{"id": "tts-1-1106", "created": "2023-11-03 23:14:01"},
2323
{"id": "gpt-3.5-turbo", "created": "2023-02-28 18:56:42"},
@@ -203,12 +203,30 @@
203203
"object": "model",
204204
"owned_by": "system",
205205
},
206+
{
207+
"id": "gpt-4-turbo-2024-04-09",
208+
"created": "2024-04-08 18:41:17",
209+
"object": "model",
210+
"owned_by": "system",
211+
},
212+
{
213+
"id": "gpt-4-turbo",
214+
"created": "2024-04-05 23:57:21",
215+
"object": "model",
216+
"owned_by": "system",
217+
},
206218
{
207219
"id": "gpt-3.5-turbo-1106",
208220
"created": "2023-11-02 21:15:48",
209221
"object": "model",
210222
"owned_by": "system",
211223
},
224+
{
225+
"id": "dall-e-3",
226+
"created": "2023-10-31 20:46:29",
227+
"object": "model",
228+
"owned_by": "system",
229+
},
212230
{
213231
"id": "gpt-4-0125-preview",
214232
"created": "2024-01-23 19:20:12",
@@ -245,12 +263,6 @@
245263
"object": "model",
246264
"owned_by": "system",
247265
},
248-
{
249-
"id": "gpt-4-turbo-2024-04-09",
250-
"created": "2024-04-08 18:41:17",
251-
"object": "model",
252-
"owned_by": "system",
253-
},
254266
{
255267
"id": "babbage-002",
256268
"created": "2023-08-21 16:16:55",
@@ -263,12 +275,6 @@
263275
"object": "model",
264276
"owned_by": "system",
265277
},
266-
{
267-
"id": "gpt-4-turbo",
268-
"created": "2024-04-05 23:57:21",
269-
"object": "model",
270-
"owned_by": "system",
271-
},
272278
{
273279
"id": "gpt-4",
274280
"created": "2023-06-27 16:13:31",
@@ -281,12 +287,6 @@
281287
"object": "model",
282288
"owned_by": "openai",
283289
},
284-
{
285-
"id": "dall-e-3",
286-
"created": "2023-10-31 20:46:29",
287-
"object": "model",
288-
"owned_by": "system",
289-
},
290290
{
291291
"id": "gpt-3.5-turbo-0125",
292292
"created": "2024-01-23 22:19:18",

0 commit comments

Comments
 (0)