Skip to content

Commit 8d36a52

Browse files
authored
Merge pull request #2 from A-Baji/dev
model customizer fucntionality
2 parents ef087d9 + a2bb197 commit 8d36a52

File tree

5 files changed

+281
-19
lines changed

5 files changed

+281
-19
lines changed

.github/workflows/package.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,38 @@ on:
77
pull_request:
88

99
jobs:
10+
test-package:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
py_ver:
16+
- '3.8'
17+
- '3.9'
18+
- '3.10'
19+
- '3.11'
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{matrix.py_ver}}
25+
- name: Install Package
26+
run: pip install .
27+
- name: Test Package
28+
run: echo -e "none\nnone" | discordai -V
1029
release:
30+
if: |
31+
github.event_name == 'push' &&
32+
startsWith(github.ref, 'refs/tags') &&
33+
github.repository_owner == 'A-Baji'
34+
needs: test-package
1135
runs-on: ubuntu-latest
1236
steps:
1337
- uses: actions/checkout@v3
1438
- id: version
1539
name: Get build metadata
1640
run: echo "::set-output name=discordai_version::$(cat discordai/version.py | grep -oP '\d+\.\d+\.\d+')"
1741
- name: Create release
18-
if: |
19-
github.event_name == 'push' &&
20-
startsWith(github.ref, 'refs/tags') &&
21-
github.repository_owner == 'A-Baji'
2242
uses: actions/create-release@v1
2343
env:
2444
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
@@ -29,14 +49,14 @@ jobs:
2949
draft: false
3050
prerelease: false
3151
package:
32-
needs: release
52+
needs: test-package
3353
runs-on: ${{ matrix.os }}
3454
strategy:
3555
fail-fast: false
3656
matrix:
3757
os:
3858
- windows-latest
39-
- macos-latest
59+
# - macos-latest
4060
- ubuntu-latest
4161
steps:
4262
- uses: actions/checkout@v3
@@ -49,18 +69,20 @@ jobs:
4969
- name: Windows CLI Package
5070
if: ${{matrix.os == 'windows-latest'}}
5171
run: |
52-
pyinstaller discordai/command_line.py --console --onefile --name=discordai --add-binary='discordai/bot/cogs;discordai/bot/cogs' --hidden-import=openai
72+
pyinstaller discordai/command_line.py --console --onefile --name=discordai --add-binary='discordai/bot/cogs;discordai/bot/cogs' --hidden-import=openai --collect-data=discordai_modelizer
5373
Compress-Archive -Path dist\*discordai* -DestinationPath discordai-windows.zip
5474
- name: Mac CLI Package
5575
if: ${{matrix.os == 'macos-latest'}}
5676
run: |
57-
pyinstaller discordai/command_line.py --console --onefile --name=discordai --add-data='discordai/bot/cogs:discordai/bot/cogs' --hidden-import=openai --hidden-import=configparser
77+
pyinstaller discordai/command_line.py --console --onefile --name=discordai --add-data='discordai/bot/cogs:discordai/bot/cogs' --hidden-import=openai --hidden-import=configparser --collect-data=discordai_modelizer --collect-data=aiohttp --collect-data=certifi
5878
zip -j discordai-macos.zip dist/*discordai*
79+
chmod +x dist/*discordai*
5980
- name: Linux CLI Package
6081
if: ${{matrix.os == 'ubuntu-latest'}}
6182
run: |
62-
pyinstaller discordai/command_line.py --console --onefile --name=discordai --add-binary='discordai/bot/cogs:discordai/bot/cogs' --hidden-import=openai
83+
pyinstaller discordai/command_line.py --console --onefile --name=discordai --add-binary='discordai/bot/cogs:discordai/bot/cogs' --hidden-import=openai --collect-data=discordai_modelizer
6384
zip -j discordai-linux.zip dist/*discordai*
85+
chmod +x dist/*discordai*
6486
# Upload
6587
- name: Upload Windows Package to Artifacts
6688
if: |

README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
# DiscordAI
22

3-
DiscordAI is CLI package that you can use to run your discord bot. It comes with two slash commands that use openAI's API to create prompt completions. There are also two hidden commands that are used to synchronize your bot's commands with discord: `@bot_name sync|unsyc guild|global`.
3+
DiscordAI is CLI package that you can use to run your discord bot. It can also be used to create customized openAI models based on a discord channel and user. The bot comes with two slash commands that use openAI's API to create prompt completions. There are also two hidden commands that are used to synchronize your bot's commands with discord: `@bot_name sync|unsyc guild|global`.
44

5-
## Planned Features
5+
## Installation
6+
### Executable
7+
Download the CLI executable for your OS from the [latest release](https://github.com/A-Baji/discordAI/releases/latest). Unfortunately, the Mac version of the executable is not available due to stability issues.
8+
### Pip
9+
`pip install -U git+https://github.com/A-Baji/discordAI.git`
10+
#### Or
11+
1. Download/clone the source locally
12+
2. Run `pip install -U <path to source>/.`
13+
3. The source may now be deleted
614

7-
- A CLI command that generates a customized openai model based on a given discord user's messages from a given discord channel.
8-
- A CLI command that generates a new slash command for your bot to create prompt completions using a given customized model.
15+
## Commands
16+
### `discordai start`
17+
Start your bot
18+
### `discordai openai create`
19+
Download the specified chat logs, parse them into a usable dataset, then create a customized model using openai.
20+
### `discordai openai list_jobs`
21+
List all of your openai customization jobs.
22+
### `discordai openai list_models`
23+
List all of your openai customized models.
24+
### `discordai openai follow`
25+
Output the event stream of a specified customization job process.
26+
### `discordai openai status`
27+
Get the status of a specified customization job.
28+
### `discordai openai cancel`
29+
Cancel a specified customization job.
30+
### `discordai openai delete`
31+
Delete a specified customized model.
32+
33+
## Disclaimer
34+
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.
35+
36+
By using this application, you agree to use it responsibly. The developers of this application are not responsible for any improper use of the application or any consequences resulting from such use. We strongly discourage using this application for any unethical purposes.

discordai/command_line.py

Lines changed: 215 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
from discordai import __version__ as version
33
from discordai import config as configuration
44
from discordai import bot
5+
from discordai_modelizer import customize
6+
from discordai_modelizer import openai as openai_wrapper
57

68

79
def discordai():
10+
config = configuration.get()
811
parser = argparse.ArgumentParser(
912
prog="discordai", description="discordAI CLI"
1013
)
@@ -15,10 +18,218 @@ def discordai():
1518

1619
start = command.add_parser("start", description="Start your discord bot")
1720

18-
args = parser.parse_args()
19-
config = configuration.get()
20-
if args.command == "start":
21-
bot.start_bot(config)
21+
openai = command.add_parser("openai", description="OpenAI model customizer and API wrapper")
22+
openai_subcommand = openai.add_subparsers(dest="subcommand")
23+
24+
openai_create = openai_subcommand.add_parser(
25+
"create", description="Create a new custom openAI model"
26+
)
27+
openai_create_required_named = openai_create.add_argument_group(
28+
"required named arguments"
29+
)
30+
openai_create_required_named.add_argument(
31+
"-c", "--channel",
32+
type=str,
33+
dest='channel',
34+
help="The ID of the discord channel you want to use",
35+
)
36+
openai_create_required_named.add_argument(
37+
"-u", "--user",
38+
type=str,
39+
dest='user',
40+
help="The name#ID of the discord user you want to use",
41+
)
42+
43+
openai_create_optional_named = openai_create.add_argument_group("optional named arguments")
44+
openai_create_optional_named.add_argument(
45+
"-o", "--openai_key",
46+
type=str,
47+
default=config["openai_key"],
48+
required=False,
49+
dest='openai_key',
50+
help="Your openAI API key: DEFAULT=config.openai_key",
51+
)
52+
openai_create_optional_named.add_argument(
53+
"-b", "--base_model",
54+
choices=["davinci", "curie", "babbage", "ada", "none"],
55+
default="none",
56+
required=False,
57+
dest='base_model',
58+
help="The base model to use for customization. If none, then skips training step: DEFAULT=none",
59+
)
60+
openai_create_optional_named.add_argument(
61+
"-t", "--thought_time",
62+
type=int,
63+
default=10,
64+
required=False,
65+
dest='thought_time',
66+
help="The max amount of time in seconds to consider two individual messages to be part of the same \"thought\": DEFAULT=10",
67+
)
68+
openai_create_optional_named.add_argument(
69+
"-m", "--max_entries",
70+
type=int,
71+
default=1000,
72+
required=False,
73+
dest='max_entries',
74+
help="The max amount of entries that may exist in the dataset: DEFAULT=1000",
75+
)
76+
openai_create_optional_named.add_argument(
77+
"-r", "--reduce_mode",
78+
choices=["first", "last", "middle", "even"],
79+
default="even",
80+
required=False,
81+
dest='reduce_mode',
82+
help="The method to reduce the entry count of the dataset: DEFAULT=even",
83+
)
84+
openai_create_optional_named.add_argument(
85+
"--dirty",
86+
action='store_false',
87+
required=False,
88+
dest='dirty',
89+
help="A flag that can be set to skip the clean up step for outputted files: DEFAULT=False",
90+
)
91+
openai_create_optional_named.add_argument(
92+
"--redownload",
93+
action='store_true',
94+
required=False,
95+
dest='redownload',
96+
help="A flag that can be set to redownload the discord chat logs: DEFAULT=False",
97+
)
98+
99+
openai_list_jobs = openai_subcommand.add_parser(
100+
"list_jobs", description="Get a list of your openAI jobs"
101+
)
102+
openai_list_jobs.add_argument(
103+
"-o", "--openai_key",
104+
type=str,
105+
default=config["openai_key"],
106+
required=False,
107+
dest='openai_key',
108+
help="Your openAI API key: DEFAULT=config.openai_key",
109+
)
110+
openai_list_jobs.add_argument(
111+
"--simple",
112+
action='store_true',
113+
required=False,
114+
dest='simple',
115+
help="Simplify the output to just the model name, job id, and status",
116+
)
117+
118+
openai_list_models = openai_subcommand.add_parser(
119+
"list_models", description="Get a list of your openAI models"
120+
)
121+
openai_list_models.add_argument(
122+
"-o", "--openai_key",
123+
type=str,
124+
default=config["openai_key"],
125+
required=False,
126+
dest='openai_key',
127+
help="Your openAI API key: DEFAULT=config.openai_key",
128+
)
129+
openai_list_models.add_argument(
130+
"--simple",
131+
action='store_true',
132+
required=False,
133+
dest='simple',
134+
help="Simplify the output to just the model name, job id, and status",
135+
)
136+
137+
openai_follow = openai_subcommand.add_parser(
138+
"follow", description="Follow a custom openAI model job"
139+
)
140+
openai_follow.add_argument(
141+
"-o", "--openai_key",
142+
type=str,
143+
default=config["openai_key"],
144+
required=False,
145+
dest='openai_key',
146+
help="Your openAI API key: DEFAULT=config.openai_key",
147+
)
148+
openai_follow.add_argument(
149+
"-j", "--job_id",
150+
type=str,
151+
dest='job_id',
152+
help="Target job id",
153+
)
154+
155+
openai_status = openai_subcommand.add_parser(
156+
"status", description="Get the status of a custom openAI model job"
157+
)
158+
openai_status.add_argument(
159+
"-o", "--openai_key",
160+
type=str,
161+
default=config["openai_key"],
162+
required=False,
163+
dest='openai_key',
164+
help="Your openAI API key: DEFAULT=config.openai_key",
165+
)
166+
openai_status.add_argument(
167+
"-j", "--job_id",
168+
type=str,
169+
dest='job_id',
170+
help="Target job id",
171+
)
172+
173+
openai_cancel = openai_subcommand.add_parser(
174+
"cancel", description="Cancel a custom openAI model job"
175+
)
176+
openai_cancel.add_argument(
177+
"-o", "--openai_key",
178+
type=str,
179+
default=config["openai_key"],
180+
required=False,
181+
dest='openai_key',
182+
help="Your openAI API key: DEFAULT=config.openai_key",
183+
)
184+
openai_cancel.add_argument(
185+
"-j", "--job_id",
186+
type=str,
187+
dest='job_id',
188+
help="Target job id",
189+
)
190+
191+
openai_delete = openai_subcommand.add_parser(
192+
"delete", description="Delete a custom openAI model"
193+
)
194+
openai_delete.add_argument(
195+
"-o", "--openai_key",
196+
type=str,
197+
default=config["openai_key"],
198+
required=False,
199+
dest='openai_key',
200+
help="Your openAI API key: DEFAULT=config.openai_key",
201+
)
202+
openai_delete.add_argument(
203+
"-m", "--model_id",
204+
type=str,
205+
dest='model_id',
206+
help="Target model id",
207+
)
208+
209+
try:
210+
args = parser.parse_args()
211+
if args.command == "start":
212+
bot.start_bot(config)
213+
elif args.command == "openai":
214+
if args.subcommand == "create":
215+
customize.create_model(config["token"], args.openai_key, args.channel, args.user,
216+
thought_time=args.thought_time, max_entry_count=args.max_entries,
217+
reduce_mode=args.reduce_mode, base_model=args.base_model, clean=args.dirty,
218+
redownload=args.redownload)
219+
if args.subcommand == "list_jobs":
220+
openai_wrapper.list_jobs(args.openai_key, args.simple)
221+
if args.subcommand == "list_models":
222+
openai_wrapper.list_models(args.openai_key, args.simple)
223+
if args.subcommand == "follow":
224+
openai_wrapper.follow_job(args.openai_key, args.job_id)
225+
if args.subcommand == "status":
226+
openai_wrapper.get_status(args.openai_key, args.job_id)
227+
if args.subcommand == "cancel":
228+
openai_wrapper.cancel_job(args.openai_key, args.job_id)
229+
if args.subcommand == "delete":
230+
openai_wrapper.delete_model(args.openai_key, args.model_id)
231+
except KeyboardInterrupt:
232+
print("Program interrupted by user. Exiting...")
22233

23234

24235
if __name__ == "__main__":

discordai/version.py

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

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
discord.py
22
openai
3-
appdirs
3+
appdirs
4+
discordai_modelizer @ git+https://github.com/A-Baji/discordAI-modelizer.git#egg=discord-modelizer

0 commit comments

Comments
 (0)