fastdc 1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastdc/__init__.py +3 -0
- fastdc/bot.py +61 -0
- fastdc/trainer.py +27 -0
- fastdc-1.0.dist-info/METADATA +18 -0
- fastdc-1.0.dist-info/RECORD +7 -0
- fastdc-1.0.dist-info/WHEEL +5 -0
- fastdc-1.0.dist-info/top_level.txt +1 -0
fastdc/__init__.py
ADDED
fastdc/bot.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import discord
|
|
2
|
+
from discord.ext import commands
|
|
3
|
+
from .trainer import FastdcTrainer
|
|
4
|
+
|
|
5
|
+
class FastBot:
|
|
6
|
+
def __init__(self, token: str, prefix: str = "!"):
|
|
7
|
+
self.token = token
|
|
8
|
+
self.bot = commands.Bot(command_prefix=prefix, intents=discord.Intents.all())
|
|
9
|
+
self.trainer = FastdcTrainer()
|
|
10
|
+
self.trainer.train()
|
|
11
|
+
|
|
12
|
+
def auto_reply(self, trigger, response):
|
|
13
|
+
@self.bot.event
|
|
14
|
+
async def on_message(message):
|
|
15
|
+
if message.author.bot:
|
|
16
|
+
return
|
|
17
|
+
if trigger.lower() in message.content.lower():
|
|
18
|
+
await message.channel.send(response)
|
|
19
|
+
await self.bot.process_commands(message)
|
|
20
|
+
|
|
21
|
+
def ai_chat(self, api_key_usr):
|
|
22
|
+
from groq import Groq
|
|
23
|
+
|
|
24
|
+
@self.bot.command()
|
|
25
|
+
async def ai(ctx, *, prompt):
|
|
26
|
+
|
|
27
|
+
client = Groq(api_key=api_key_usr)
|
|
28
|
+
|
|
29
|
+
chat_completion = client.chat.completions.create(
|
|
30
|
+
|
|
31
|
+
messages=[
|
|
32
|
+
{
|
|
33
|
+
"role": "system",
|
|
34
|
+
"content": "you are a helpful assistant."
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
{
|
|
38
|
+
"role": "user",
|
|
39
|
+
"content": prompt,
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
|
|
43
|
+
model="llama-3.3-70b-versatile",
|
|
44
|
+
temperature=0.5,
|
|
45
|
+
max_completion_tokens=1024,
|
|
46
|
+
top_p=1,
|
|
47
|
+
stop=None,
|
|
48
|
+
stream=False,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
await ctx.send(chat_completion.choices[0].message.content)
|
|
52
|
+
|
|
53
|
+
def train_bot(self):
|
|
54
|
+
@self.bot.command()
|
|
55
|
+
async def askbot(ctx, *, message):
|
|
56
|
+
response = self.trainer.get_response(message)
|
|
57
|
+
await ctx.send(response)
|
|
58
|
+
|
|
59
|
+
def run(self):
|
|
60
|
+
self.bot.run(self.token)
|
|
61
|
+
|
fastdc/trainer.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from chatterbot import ChatBot
|
|
2
|
+
from chatterbot.trainers import ListTrainer
|
|
3
|
+
import os
|
|
4
|
+
import spacy
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
spacy.load("en_core_web_sm")
|
|
8
|
+
except OSError:
|
|
9
|
+
from spacy.cli import download
|
|
10
|
+
print("🔧 Downloading 'en_core_web_sm' model...")
|
|
11
|
+
download("en_core_web_sm")
|
|
12
|
+
|
|
13
|
+
class FastdcTrainer:
|
|
14
|
+
def __init__(self, name="FastdcBot", data_path="data_train.txt"):
|
|
15
|
+
self.chatbot = ChatBot(name)
|
|
16
|
+
self.data_path = data_path
|
|
17
|
+
|
|
18
|
+
def train(self):
|
|
19
|
+
trainer = ListTrainer(self.chatbot)
|
|
20
|
+
if not os.path.exists(self.data_path):
|
|
21
|
+
raise FileNotFoundError(f"Training data file '{self.data_path}' not found.")
|
|
22
|
+
with open(self.data_path, "r", encoding="utf-8") as file:
|
|
23
|
+
conversation = file.read().split("\n")
|
|
24
|
+
trainer.train(conversation)
|
|
25
|
+
|
|
26
|
+
def get_response(self, message):
|
|
27
|
+
return str(self.chatbot.get_response(message))
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: fastdc
|
|
3
|
+
Version: 1.0
|
|
4
|
+
Summary: FastDC: A fast, modular, and AI-integrated Discord bot framework.
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: Arya Wiratama
|
|
7
|
+
Author-email: aryawiratama2401@gmail.com
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Requires-Dist: chatterbot
|
|
12
|
+
Requires-Dist: discord.py
|
|
13
|
+
Requires-Dist: groq
|
|
14
|
+
Requires-Dist: python-dotenv
|
|
15
|
+
Requires-Dist: spacy
|
|
16
|
+
|
|
17
|
+
UNKNOWN
|
|
18
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
fastdc/__init__.py,sha256=q1NOCWYxFR_XtdT2AE7kG9kSwM3b1DjxoTUuvSWhkAU,47
|
|
2
|
+
fastdc/bot.py,sha256=CM8Ml6qIR4gU-_Gqm_xnuU7I9_cKfnNTsmb07ltJVGk,1858
|
|
3
|
+
fastdc/trainer.py,sha256=3D6YPHM7FDhbBCvFY6kfGyzn2KM40aXjb_lpymoeGaU,887
|
|
4
|
+
fastdc-1.0.dist-info/METADATA,sha256=5w9_ACcrPcL2qDOAGkWkP3bkjU7-kma3RQln_7a0NDQ,396
|
|
5
|
+
fastdc-1.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
6
|
+
fastdc-1.0.dist-info/top_level.txt,sha256=sdmDhZploPuCh4-ieWzafCUSV_1R5S6e8PWaS5ug5W8,7
|
|
7
|
+
fastdc-1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fastdc
|