Radosław Wolnik commited on
Commit
f5e2b6b
·
1 Parent(s): 79f18b3
Files changed (6) hide show
  1. .gitignore +2 -1
  2. ChatAI/__init__.py +0 -0
  3. ChatAI/chat_ai.py +4 -0
  4. README.md +0 -12
  5. app.py +62 -61
  6. requirements.txt +3 -1
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  /.idea/
2
- /.Chatter/
 
 
1
  /.idea/
2
+ /.Chatter/
3
+ .aider*
ChatAI/__init__.py ADDED
File without changes
ChatAI/chat_ai.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+
4
+ pipe = pipeline("text2text-generation", model="google/flan-t5-xxl")
README.md DELETED
@@ -1,12 +0,0 @@
1
- ---
2
- title: DiscordChatter
3
- emoji: 💬
4
- colorFrom: yellow
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.0.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -1,61 +1,62 @@
1
- <<<<<<< SEARCH
2
- =======
3
- from dataclasses import dataclass
4
- import logging
5
- from typing import Optional, Union
6
-
7
- logger = logging.getLogger(__name__)
8
-
9
- @dataclass
10
- class DiscordBot:
11
- command_prefix: str = "!"
12
- bot: commands.Bot = None
13
- channel: Optional[discord.Channel] = None
14
-
15
- def __init__(self, command_prefix: str, bot: commands.Bot, channel: Optional[discord.Channel] = None):
16
- self.command_prefix = command_prefix
17
- self.bot = bot
18
- self.channel = channel
19
-
20
- async def send_message(self, message: str):
21
- """Sends a message to the specified channel"""
22
- if self.channel:
23
- await self.channel.send(message)
24
-
25
- async def __aenter__(self):
26
- """Enter context manager"""
27
- return self
28
-
29
- async def __aexit__(self, *exc_info):
30
- """Exit context manager"""
31
- await self.close()
32
-
33
- async def close(self):
34
- """Closes the bot connection"""
35
- if self.bot:
36
- await self.bot.close()
37
-
38
- @dataclass
39
- class ChatAI:
40
- model_name: str = "bigband/TranscendentBrahma"
41
- pipe: Optional[pipeline.Pipeline] = None
42
-
43
- def generate_response(self, prompt: str) -> str:
44
- """Generates response using the AI model"""
45
- if self.pipe:
46
- return self.pipe(prompt)
47
- raise ValueError("AI model not initialized")
48
-
49
- if __name__ == "__main__":
50
- import os
51
- from huggingface_hub import InferenceClient
52
-
53
- # Initialize AI model
54
- pipe = InferenceClient(model_name)
55
-
56
- # Create bot instance
57
- bot = DiscordBot(command_prefix="!", bot=commands.Bot(), channel=None)
58
-
59
- # Run bot
60
- bot.run("MTMzODQ4NTY2MzY3MDA3OTQ4OA")
61
- >>>>>>> REPLACE
 
 
1
+ import discord
2
+ from discord.ext import commands
3
+ from ChatAI.chat_ai import pipe as ai
4
+
5
+ # Set up Discord bot intents and command prefix
6
+ intents = discord.Intents.default()
7
+ intents.message_content = True
8
+ intents.messages = True
9
+ bot = commands.Bot(command_prefix="!", intents=intents)
10
+
11
+ # Dictionary to track message count per channel
12
+ message_counts = {}
13
+
14
+ @bot.event
15
+ async def on_message(message):
16
+ guild = message.guild # Get the guild (server) the message is from
17
+ channel = message.channel
18
+ if message.channel != discord.utils.get(guild.text_channels, name="ai_chatter"):
19
+ print("not ai_chatter channel"); return;
20
+ print("channel: ai_chatter")
21
+
22
+ if message.author.bot:
23
+ print("not taking own messages into count"); return;
24
+
25
+ if message.author.name!="sandra_n": pass;
26
+ print("I can see its you, sis"); await message.channel.send("I can see its you, sis")
27
+
28
+ if message.channel.id not in message_counts: # Ensure tracking exists for this channel
29
+ message_counts[message.channel.id] = 0
30
+
31
+ message_counts[message.channel.id] += 1 # Increment message count
32
+ print(message_counts[message.channel.id])
33
+
34
+ messages = []
35
+ if message_counts[message.channel.id] >= 4: # Check if the count reaches 10
36
+ async for message in channel.history(limit=4):
37
+ messages.append(message.content)
38
+
39
+ await message.channel.send("\n".join(messages))
40
+
41
+
42
+ message_counts[message.channel.id] = 0 # Reset the counter
43
+
44
+
45
+ await bot.process_commands(message) # Ensure commands still work
46
+
47
+ @bot.event
48
+ async def on_ready():
49
+ print(f'Logged in as {bot.user}') # Logs bot login in console
50
+
51
+ guild = discord.utils.get(bot.guilds, name="PrzebieralniaKoedukacyjna")
52
+ if guild:
53
+ # Get the channel by name
54
+ channel = discord.utils.get(guild.channels, name="ai_chatter") # Replace "general" with your channel name
55
+ if channel:
56
+ print(f"Channel found: {channel.name} (ID: {channel.id})")
57
+ else:
58
+ print("Channel not found!")
59
+
60
+ await channel.send(f"{bot.user} logged in, runnin on 'huggingface.co/spaces")
61
+
62
+ bot.run("MTMzODQ4NTY2MzY3MDA3OTQ4OA.GlmK1T.7ZeEiDz7ViY3zvuSqlacVocDMSZ-ln80c09AS4")
requirements.txt CHANGED
@@ -1,3 +1,5 @@
 
1
  huggingface_hub==0.25.2
2
  discord.py
3
- discord
 
 
1
+ transformers
2
  huggingface_hub==0.25.2
3
  discord.py
4
+ discord
5
+ TensorFlow>=2.0