Skip to content

Commit 7035f0f

Browse files
authored
Merge pull request #19 from A-Baji/dev
thought min max and bold prompts
2 parents b02c9c4 + 0e1e196 commit 7035f0f

File tree

5 files changed

+48
-17
lines changed

5 files changed

+48
-17
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ Pick a channel and user whose chat logs you want to use for creating your custom
3030

3131
You can follow [this guide](https://turbofuture.com/internet/Discord-Channel-ID) to learn how to find a channel's ID. Make sure that you include the full username with the #id, and wrap it in quotes if it contains spaces. The `--dirty` flag prevents the outputted dataset files from being deleted. Downloaded chat logs get saved and reused, but you can set the `--redownload` flag if you want to update the logs.
3232

33-
You may have noticed the lack of a model customization process occurring after running that command. This is because no base model was selected, but before you specify a base model, you should analyze the generated dataset located in the directory mentioned in the logs. Chat messages are parsed into a dataset by grouping individual messages sent within a certain timeframe into "thoughts", where each thought is a completion in the dataset. The default for this timeframe is 10 seconds. If your dataset looks a bit off, try different timeframe settings using the `-t` option:
33+
You may have noticed the lack of a model customization process occurring after running that command. This is because no base model was selected, but before you specify a base model, you should analyze the generated dataset located in the directory mentioned in the logs. Chat messages are parsed into a dataset by grouping individual messages sent within a certain timeframe into "thoughts", where each thought is a completion in the dataset. The default for this timeframe is 10 seconds. The length of each thought must also be within the minimum and max thought length. The defaults for these are 4 words and `None`, or optional. If your dataset looks a bit off, try different settings using the `--ttime`, `--tmin`, and `--ttmax` options:
3434

35-
`discordai model create -c <channel_id> -u "<username#id>" -t <timeframe> --dirty`
35+
`discordai model create -c <channel_id> -u "<username#id>" --ttime <timeframe> --tmax <thought_max> --tmin <thought_min> --dirty`
3636

37-
After you've found a good timeframe setting, you will want to manage your dataset's size. The larger your dataset, the more openAI credits it will cost to create a custom model. By default, the max dataset size is set to 1000. If your dataset exceeds this limit, it will be reduced using either a "first", "last", "middle", or "even" reduction method. The "first" method will select the first n messages, "last" will select the last n, "middle" will select the middle n, and "even" will select an even distribution of n messages. The default reduction method is even. You can set the max dataset size and reduction mode using the `-m` and `-r` options:
37+
After you've found good thought settings, you will want to manage your dataset's size. The larger your dataset, the more openAI credits it will cost to create a custom model. By default, the max dataset size is set to 1000. If your dataset exceeds this limit, it will be reduced using either a "first", "last", "middle", or "even" reduction method. The "first" method will select the first n messages, "last" will select the last n, "middle" will select the middle n, and "even" will select an even distribution of n messages. The default reduction method is even. You can set the max dataset size and reduction mode using the `-m` and `-r` options:
3838

39-
`discordai model create -c <channel_id> -u "<username#id>" -t <timeframe> -m <max_size> -r <reduction_mode> --dirty`
39+
`discordai model create -c <channel_id> -u "<username#id>" --ttime <timeframe> --tmax <thought_max> --tmin <thought_min> -m <max_size> -r <reduction_mode> --dirty`
4040

4141
If you are planning on creating multiple models, you may want to get your hands on multiple openAI API keys in order to maximize the free credit usage. You can assign specific api keys to custom models using the `-o` option. Otherwise, the key provided in your config will be used.
4242

4343
Now that you have fine tuned your dataset, you can finally begin the customization process by specifying a base model. OpenAI has four base [models](https://beta.openai.com/docs/models/gpt-3): davinci, curie, babbage, and ada, in order of most advanced to least advanced. Generally you will want to use davinci, but it is also the most expensive model as well as the longest to customize. Select your base model with the `-b` option.
4444

4545
Your final command should look something like this:
4646

47-
`discordai model create -c <channel_id> -u "<username#id>" -t <timeframe> -m <max_size> -r <reduction_mode> -b <base_model>`
47+
`discordai model create -c <channel_id> -u "<username#id>" --ttime <timeframe> --tmax <thought_max> --tmin <thought_min> -m <max_size> -r <reduction_mode> -b <base_model>`
4848

4949
If you find the training step to cost too many credits with your current options, you can cancel it with `discordai job cancel -j <job_id>`, and then either lower your max dataset size, or choose a different discord channel and/or user. You can get a list of all your jobs with `discordai job list --simple`.
5050
### Test the new model

discordai/command_line.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ def discordai():
110110
dest='stop_default',
111111
help="Set the stop option to use for completions to True",
112112
)
113+
new_cmd_optional_named.add_argument(
114+
"--bolden",
115+
action='store_true',
116+
required=False,
117+
dest='bolden',
118+
help="Boldens the original prompt in the completion output",
119+
)
113120

114121
delete_cmd = bot_cmds_commands_subcommand.add_parser(
115122
"delete", description="Delete a slash command from your bot"
@@ -179,13 +186,29 @@ def discordai():
179186
help="The base model to use for customization. If none, then skips training step: DEFAULT=none",
180187
)
181188
model_create_optional_named.add_argument(
182-
"-t", "--thought-time",
189+
"--ttime", "--thought-time",
183190
type=int,
184191
default=10,
185192
required=False,
186193
dest='thought_time',
187194
help="The max amount of time in seconds to consider two individual messages to be part of the same \"thought\": DEFAULT=10",
188195
)
196+
model_create_optional_named.add_argument(
197+
"--tmax", "--thought-max",
198+
type=int,
199+
default=None,
200+
required=False,
201+
dest='thought_max',
202+
help="The max in words length of each thought: DEFAULT=None",
203+
)
204+
model_create_optional_named.add_argument(
205+
"--tmin", "--thought-min",
206+
type=int,
207+
default=4,
208+
required=False,
209+
dest='thought_min',
210+
help="The minimum in words length of each thought: DEFAULT=4",
211+
)
189212
model_create_optional_named.add_argument(
190213
"-m", "--max-entries",
191214
type=int,
@@ -301,6 +324,13 @@ def discordai():
301324
dest='openai_key',
302325
help="The openAI API key associated with the job to see the status for: DEFAULT=config.openai_key",
303326
)
327+
job_status_optional_named.add_argument(
328+
"--events",
329+
action='store_true',
330+
required=False,
331+
dest='events',
332+
help="Simplify the output to just the event list",
333+
)
304334

305335
job_cancel = job_subcommand.add_parser(
306336
"cancel", description="Cancel an openAI customization job"
@@ -351,17 +381,18 @@ def discordai():
351381
if args.subcommand == "commands":
352382
if args.subsubcommand == "new":
353383
template.gen_new_command(args.model_id, args.command_name, args.temp_default, args.pres_default,
354-
args.freq_default, args.max_tokens_default, args.stop_default, args.openai_key)
384+
args.freq_default, args.max_tokens_default, args.stop_default, args.openai_key,
385+
args.bolden)
355386
elif args.subsubcommand == "delete":
356387
template.delete_command(args.command_name)
357388
elif args.command == "model":
358389
if args.subcommand == "list":
359390
openai_wrapper.list_models(args.openai_key, args.simple)
360391
if args.subcommand == "create":
361392
customize.create_model(config["token"], args.openai_key, args.channel, args.user,
362-
thought_time=args.thought_time, max_entry_count=args.max_entries,
363-
reduce_mode=args.reduce_mode, base_model=args.base_model, clean=args.dirty,
364-
redownload=args.redownload)
393+
thought_time=args.thought_time, thought_max=args.thought_max, thought_min=args.thought_min,
394+
max_entry_count=args.max_entries, reduce_mode=args.reduce_mode, base_model=args.base_model,
395+
clean=args.dirty, redownload=args.redownload)
365396
if args.subcommand == "delete":
366397
openai_wrapper.delete_model(args.openai_key, args.model_id)
367398
elif args.command == "job":
@@ -370,7 +401,7 @@ def discordai():
370401
if args.subcommand == "follow":
371402
openai_wrapper.follow_job(args.openai_key, args.job_id)
372403
if args.subcommand == "status":
373-
openai_wrapper.get_status(args.openai_key, args.job_id)
404+
openai_wrapper.get_status(args.openai_key, args.job_id, args.events)
374405
if args.subcommand == "cancel":
375406
openai_wrapper.cancel_job(args.openai_key, args.job_id)
376407
elif args.command == "config":

discordai/template.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ async def customai(self, context: Context, prompt: str = "", temp: float = {temp
4444
frequency_penalty=presPen,
4545
presence_penalty=freqPen,
4646
max_tokens=max_tokens,
47-
echo=True if prompt else False,
47+
echo=False,
4848
stop='.' if stop else None,
4949
)
50-
await context.send(response[\'choices\'][0][\'text\'][:2000])
50+
await context.send(f"{{'**' if {bold} else ''}}{{prompt}}{{'**' if {bold} else ''}}{{response[\'choices\'][0][\'text\'][:2000]}}")
5151
except Exception as error:
5252
print({error})
5353
await context.send(
@@ -63,7 +63,7 @@ async def setup(bot):
6363

6464

6565
def gen_new_command(model_id: str, command_name: str, temp_default: float, pres_default: float, freq_default: float,
66-
max_tokens_default: int, stop_default: bool, openai_key: str):
66+
max_tokens_default: int, stop_default: bool, openai_key: str, bold_prompt: bool):
6767
if getattr(sys, 'frozen', False):
6868
# The code is being run as a frozen executable
6969
data_dir = pathlib.Path(appdirs.user_data_dir(appname="discordai"))
@@ -84,7 +84,7 @@ def gen_new_command(model_id: str, command_name: str, temp_default: float, pres_
8484
command_name=command_name, temp_default=float(temp_default),
8585
pres_default=float(pres_default),
8686
freq_default=float(freq_default),
87-
max_tokens_default=max_tokens_default, stop_default=stop_default, openai_key=openai_key,
87+
max_tokens_default=max_tokens_default, stop_default=stop_default, openai_key=openai_key, bold = bold_prompt,
8888
error="f\"Failed to generate valid response for prompt: {prompt}\\nError: {error}\""))
8989
print(f"Successfully created new slash command: /{command_name} using model {model_id}")
9090

discordai/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.2.1"
1+
__version__ = "1.3.0"

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ discord.py
22
openai
33
pandas
44
appdirs
5-
discordai_modelizer @ git+https://github.com/A-Baji/discordAI-modelizer.git@1.1.0
5+
discordai_modelizer @ git+https://github.com/A-Baji/discordAI-modelizer.git@1.2.0

0 commit comments

Comments
 (0)