Skip to content

Commit 075c719

Browse files
authored
Merge pull request #18 from A-Baji/dev
rework cli, fix bug, change download logic
2 parents 513fe1c + 68a53fc commit 075c719

File tree

6 files changed

+137
-127
lines changed

6 files changed

+137
-127
lines changed

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,26 @@ DiscordAI Modelizer is primarily used as a subcomponent of [DiscordAI](https://g
1111
3. The source may now be deleted
1212

1313
## Commands
14-
### `discordai_modelizer openai create`
15-
This command will download the specified chat logs, parse them into a usable dataset, then create a customized model using openai.
16-
### `discordai_modelizer openai list_jobs`
17-
This command will list all of the openai customization jobs associated with a specified api key.
18-
### `discordai_modelizer openai list_models`
19-
This command will list all of the openai customized models associated with a specified api key.
20-
### `discordai_modelizer openai follow`
21-
This command will output the event stream of a specified customization job process.
22-
### `discordai_modelizer openai status`
23-
This command will output the status of a specified customization job.
24-
### `discordai_modelizer openai cancel`
25-
This command will cancel a specified customization job.
26-
### `discordai_modelizer openai delete`
27-
This command will delete a specified customized model.
14+
### Model
15+
Commands related to your openAI models
16+
#### `discordai_modelizer model list`
17+
List your openAi customized models
18+
#### `discordai_modelizer model create`
19+
Create a new openAI customized model by downloading the specified chat logs, parsing them into a usable dataset, and then training a customized model using openai
20+
21+
For a proper usage, see the [guide](https://github.com/A-Baji/discordAI#create-a-new-customized-openai-model) for DiscordAI.
22+
#### `discordai_modelizer model delete`
23+
Delete an openAI customized model
24+
### Job
25+
Commands related to your openAI jobs
26+
#### `discordai_modelizer job list`
27+
List your openAI customization jobs
28+
#### `discordai_modelizer job follow`
29+
Follow an openAI customization job
30+
#### `discordai_modelizer job status`
31+
Get an openAI customization job's status
32+
#### `discordai_modelizer job cancel`
33+
Cancel an openAI customization job
2834

2935
## Disclaimer
3036
This application allows users to download the chat history of any channel for which they have permission to invite a bot, and then use those logs to create an openai model based on a user's chat messages. It is important to note that this application should only be used with the consent of all members of the channel. Using this application for malicious purposes, such as impersonation, or without the consent of all members is strictly prohibited.

discordai_modelizer/command_line.py

Lines changed: 94 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -12,205 +12,208 @@ def discordai_modelizer():
1212
)
1313
command = parser.add_subparsers(dest="command")
1414

15-
openai = command.add_parser("openai", description="OpenAI model customizer and API wrapper")
16-
openai_subcommand = openai.add_subparsers(dest="subcommand")
15+
model = command.add_parser("model", description="Commands related to your openAI models")
16+
job = command.add_parser("job", description="Commands related to your openAI jobs")
1717

18-
openai_create = openai_subcommand.add_parser(
19-
"create", description="Create a new custom openAI model"
18+
model_subcommand = model.add_subparsers(dest="subcommand")
19+
job_subcommand = job.add_subparsers(dest="subcommand")
20+
21+
model_list = model_subcommand.add_parser(
22+
"list", description="List your openAi customized models"
23+
)
24+
model_list.add_argument(
25+
"-o", "--openai-key",
26+
type=str,
27+
dest='openai_key',
28+
help="The openAI API key to list the models for",
29+
)
30+
model_list.add_argument(
31+
"--simple",
32+
action='store_true',
33+
required=False,
34+
dest='simple',
35+
help="Simplify the output to just the model name, job id, and status",
2036
)
21-
openai_create_required_named = openai_create.add_argument_group(
37+
38+
model_create = model_subcommand.add_parser(
39+
"create",
40+
description="Create a new openAI customized model by downloading the specified chat logs, parsing them into a usable dataset, and then training a customized model using openai")
41+
model_create_required_named = model_create.add_argument_group(
2242
"required named arguments"
2343
)
24-
openai_create_required_named.add_argument(
25-
"-d", "--discord_token",
44+
model_create_required_named.add_argument(
45+
"-d", "--discord-token",
2646
type=str,
2747
dest='discord_token',
2848
help="The discord token for your bot",
2949
)
30-
openai_create_required_named.add_argument(
31-
"-o", "--openai_key",
50+
model_create_required_named.add_argument(
51+
"-o", "--openai-key",
3252
type=str,
3353
dest='openai_key',
34-
help="Your openAI API key",
54+
help="The openAI API key to use to create the model",
3555
)
36-
openai_create_required_named.add_argument(
56+
model_create_required_named.add_argument(
3757
"-c", "--channel",
3858
type=str,
3959
dest='channel',
4060
help="The ID of the discord channel you want to use",
4161
)
42-
openai_create_required_named.add_argument(
62+
model_create_required_named.add_argument(
4363
"-u", "--user",
4464
type=str,
4565
dest='user',
46-
help="The name#ID of the discord user you want to use",
66+
help="The username#ID of the discord user you want to use",
4767
)
48-
49-
openai_create_optional_named = openai_create.add_argument_group("optional named arguments")
50-
openai_create_optional_named.add_argument(
51-
"-b", "--base_model",
68+
model_create_optional_named = model_create.add_argument_group("optional named arguments")
69+
model_create_optional_named.add_argument(
70+
"-b", "--base-model",
5271
choices=["davinci", "curie", "babbage", "ada", "none"],
5372
default="none",
5473
required=False,
5574
dest='base_model',
5675
help="The base model to use for customization. If none, then skips training step: DEFAULT=none",
5776
)
58-
openai_create_optional_named.add_argument(
59-
"-t", "--thought_time",
77+
model_create_optional_named.add_argument(
78+
"-t", "--thought-time",
6079
type=int,
6180
default=10,
6281
required=False,
6382
dest='thought_time',
6483
help="The max amount of time in seconds to consider two individual messages to be part of the same \"thought\": DEFAULT=10",
6584
)
66-
openai_create_optional_named.add_argument(
67-
"-m", "--max_entries",
85+
model_create_optional_named.add_argument(
86+
"-m", "--max-entries",
6887
type=int,
6988
default=1000,
7089
required=False,
7190
dest='max_entries',
7291
help="The max amount of entries that may exist in the dataset: DEFAULT=1000",
7392
)
74-
openai_create_optional_named.add_argument(
75-
"-r", "--reduce_mode",
93+
model_create_optional_named.add_argument(
94+
"-r", "--reduce-mode",
7695
choices=["first", "last", "middle", "even"],
7796
default="even",
7897
required=False,
7998
dest='reduce_mode',
8099
help="The method to reduce the entry count of the dataset: DEFAULT=even",
81100
)
82-
openai_create_optional_named.add_argument(
83-
"--clean",
84-
action='store_true',
101+
model_create_optional_named.add_argument(
102+
"--dirty",
103+
action='store_false',
85104
required=False,
86-
dest='clean',
87-
help="A flag that can be set to clean up outputted files: DEFAULT=False",
105+
dest='dirty',
106+
help="Skip the clean up step for outputted files",
88107
)
89-
openai_create_optional_named.add_argument(
108+
model_create_optional_named.add_argument(
90109
"--redownload",
91110
action='store_true',
92111
required=False,
93112
dest='redownload',
94-
help="A flag that can be set to redownload the discord chat logs: DEFAULT=False",
113+
help="Redownload the discord chat logs",
95114
)
96115

97-
openai_list_jobs = openai_subcommand.add_parser(
98-
"list_jobs", description="Get a list of your openAI jobs"
116+
model_delete = model_subcommand.add_parser(
117+
"delete", description="Delete an openAI customized model"
99118
)
100-
openai_list_jobs.add_argument(
101-
"-o", "--openai_key",
119+
model_delete.add_argument(
120+
"-o", "--openai-key",
102121
type=str,
103122
dest='openai_key',
104-
help="Your openAI API key",
123+
help="The openAI API key associated with the model to delete",
105124
)
106-
openai_list_jobs.add_argument(
107-
"--simple",
108-
action='store_true',
109-
required=False,
110-
dest='simple',
111-
help="Simplify the output to just the model name, job id, and status",
125+
model_delete.add_argument(
126+
"-m", "--model-id",
127+
type=str,
128+
dest='model_id',
129+
help="Target model id",
112130
)
113131

114-
openai_list_models = openai_subcommand.add_parser(
115-
"list_models", description="Get a list of your openAI models"
132+
job_list = job_subcommand.add_parser(
133+
"list", description="List your openAI customization jobs"
116134
)
117-
openai_list_models.add_argument(
118-
"-o", "--openai_key",
135+
job_list.add_argument(
136+
"-o", "--openai-key",
119137
type=str,
120138
dest='openai_key',
121-
help="Your openAI API key",
139+
help="The openAI API key to list the jobs for",
122140
)
123-
openai_list_models.add_argument(
141+
job_list.add_argument(
124142
"--simple",
125143
action='store_true',
126144
required=False,
127145
dest='simple',
128146
help="Simplify the output to just the model name, job id, and status",
129147
)
130148

131-
openai_follow = openai_subcommand.add_parser(
132-
"follow", description="Follow a custom openAI model job"
149+
job_follow = job_subcommand.add_parser(
150+
"follow", description="Follow an openAI customization job"
133151
)
134-
openai_follow.add_argument(
135-
"-o", "--openai_key",
152+
job_follow.add_argument(
153+
"-o", "--openai-key",
136154
type=str,
137155
dest='openai_key',
138-
help="Your openAI API key",
156+
help="The openAI API key associated with the job to follow",
139157
)
140-
openai_follow.add_argument(
141-
"-j", "--job_id",
158+
job_follow.add_argument(
159+
"-j", "--job-id",
142160
type=str,
143161
dest='job_id',
144162
help="Target job id",
145163
)
146164

147-
openai_status = openai_subcommand.add_parser(
148-
"status", description="Get the status of a custom openAI model job"
165+
job_status = job_subcommand.add_parser(
166+
"status", description="Get an openAI customization job's status"
149167
)
150-
openai_status.add_argument(
151-
"-o", "--openai_key",
168+
job_status.add_argument(
169+
"-o", "--openai-key",
152170
type=str,
153171
dest='openai_key',
154-
help="Your openAI API key",
172+
help="The openAI API key associated with the job to see the status for",
155173
)
156-
openai_status.add_argument(
157-
"-j", "--job_id",
174+
job_status.add_argument(
175+
"-j", "--job-id",
158176
type=str,
159177
dest='job_id',
160178
help="Target job id",
161179
)
162180

163-
openai_cancel = openai_subcommand.add_parser(
164-
"cancel", description="Cancel a custom openAI model job"
181+
job_cancel = job_subcommand.add_parser(
182+
"cancel", description="Cancel an openAI customization job"
165183
)
166-
openai_cancel.add_argument(
167-
"-o", "--openai_key",
184+
job_cancel.add_argument(
185+
"-o", "--openai-key",
168186
type=str,
169187
dest='openai_key',
170-
help="Your openAI API key",
188+
help="The openAI API key associated with the job to cancel",
171189
)
172-
openai_cancel.add_argument(
173-
"-j", "--job_id",
190+
job_cancel.add_argument(
191+
"-j", "--job-id",
174192
type=str,
175193
dest='job_id',
176194
help="Target job id",
177195
)
178196

179-
openai_delete = openai_subcommand.add_parser(
180-
"delete", description="Delete a custom openAI model"
181-
)
182-
openai_delete.add_argument(
183-
"-o", "--openai_key",
184-
type=str,
185-
dest='openai_key',
186-
help="Your openAI API key",
187-
)
188-
openai_delete.add_argument(
189-
"-m", "--model_id",
190-
type=str,
191-
dest='model_id',
192-
help="Target model id",
193-
)
194-
195197
args = parser.parse_args()
196-
if args.command == "openai":
198+
if args.command == "model":
199+
if args.subcommand == "list":
200+
openai_wrapper.list_models(args.openai_key, args.simple)
197201
if args.subcommand == "create":
198202
customize.create_model(args.discord_token, args.openai_key, args.channel, args.user,
199203
thought_time=args.thought_time, max_entry_count=args.max_entries,
200-
reduce_mode=args.reduce_mode, base_model=args.base_model, clean=args.clean,
204+
reduce_mode=args.reduce_mode, base_model=args.base_model, clean=args.dirty,
201205
redownload=args.redownload)
202-
if args.subcommand == "list_jobs":
206+
if args.subcommand == "delete":
207+
openai_wrapper.delete_model(args.openai_key, args.model_id)
208+
elif args.command == "job":
209+
if args.subcommand == "list":
203210
openai_wrapper.list_jobs(args.openai_key, args.simple)
204-
if args.subcommand == "list_models":
205-
openai_wrapper.list_models(args.openai_key, args.simple)
206211
if args.subcommand == "follow":
207212
openai_wrapper.follow_job(args.openai_key, args.job_id)
208213
if args.subcommand == "status":
209214
openai_wrapper.get_status(args.openai_key, args.job_id)
210215
if args.subcommand == "cancel":
211216
openai_wrapper.cancel_job(args.openai_key, args.job_id)
212-
if args.subcommand == "delete":
213-
openai_wrapper.delete_model(args.openai_key, args.model_id)
214217

215218

216219
if __name__ == "__main__":

discordai_modelizer/customize.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def create_model(bot_token: str, openai_key: str, channel_id: str, user_id: str,
1313
files_path = appdirs.user_data_dir(appauthor="Adib Baji", appname="discordai")
1414

1515
# Download logs
16-
if not os.path.isfile(f"{files_path}/{channel_user}_logs.json") or redownload:
16+
if not os.path.isfile(f"{files_path}/{channel_id}_logs.json") or redownload:
1717
print("INFO: Exporting chat logs using DiscordChatExporter...")
1818
print("INFO: This may take a few minutes to hours depending on the message count of the channel")
1919
print("INFO: Progress will NOT be saved if cancelled")
@@ -26,19 +26,18 @@ def create_model(bot_token: str, openai_key: str, channel_id: str, user_id: str,
2626
"export",
2727
"-c", channel_id,
2828
"-t", bot_token,
29-
"-o", f"{channel_user}_logs.json",
30-
"-f", "Json",
31-
"--filter", f"from:'{user_id}'"
29+
"-o", f"{channel_id}_logs.json",
30+
"-f", "Json"
3231
])
3332
print("--------------------------DiscordChatExporter---------------------------")
34-
shutil.move(f"{channel_user}_logs.json", f"{files_path}/{channel_user}_logs.json")
35-
print(f"INFO: Logs saved to {files_path}/{channel_user}_logs.json")
33+
shutil.move(f"{channel_id}_logs.json", f"{files_path}/{channel_id}_logs.json")
34+
print(f"INFO: Logs saved to {files_path}/{channel_id}_logs.json")
3635
else:
37-
print(f"INFO: Chat logs detected locally at {files_path}/{channel_user}_logs.json... Skipping download.")
36+
print(f"INFO: Chat logs detected locally at {files_path}/{channel_id}_logs.json... Skipping download.")
3837

3938
# Parse logs
4039
print("INFO: Parsing chat logs into a openAI compatible dataset...")
41-
parse_logs(f"{files_path}/{channel_user}_logs.json", user_id, thought_time)
40+
parse_logs(f"{files_path}/{channel_id}_logs.json", user_id, thought_time)
4241

4342
# Prepare and reduce dataset
4443
print("INFO: Cleaning up generated dataset...")

0 commit comments

Comments
 (0)