Compare commits
11 Commits
8244ee95c9
...
cea0ba39bc
| Author | SHA1 | Date | |
|---|---|---|---|
| cea0ba39bc | |||
|
|
ba6f93dc96 | ||
|
|
ae97fdcce7 | ||
|
|
c38e3ba8c0 | ||
|
|
622e46e22f | ||
|
|
ac930d08c4 | ||
|
|
12c38ec54f | ||
|
|
e32d5e41e0 | ||
|
|
eecd0cd6a7 | ||
|
|
bb8db4f3d7 | ||
|
|
fd749872da |
@ -1,4 +1,4 @@
|
|||||||
FROM python:3-alpine
|
FROM python:3.13-alpine
|
||||||
|
|
||||||
# Set environment variables to prevent Python from writing .pyc files to disk and buffering stdout and stderr
|
# Set environment variables to prevent Python from writing .pyc files to disk and buffering stdout and stderr
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|||||||
@ -8,7 +8,7 @@ This Discord chatbot is built to follow the chat flow and have a conversation wi
|
|||||||
|
|
||||||
0. Have [Ollama](https://ollama.com) and [Docker](https://docker.com) installed and running
|
0. Have [Ollama](https://ollama.com) and [Docker](https://docker.com) installed and running
|
||||||
1. Clone the repository
|
1. Clone the repository
|
||||||
2. Configure the `.env` file with at least the following variables (see [Configuration](#configuration) for more options):
|
2. Configure the `bot.env` file with at least the following variables (see [Configuration](#configuration) for more options):
|
||||||
- `DISCORD_TOKEN`: The token of the discord bot (token can be obtained from the [Discord Developer Portal](https://discord.com/developers/applications))
|
- `DISCORD_TOKEN`: The token of the discord bot (token can be obtained from the [Discord Developer Portal](https://discord.com/developers/applications))
|
||||||
- `ADMIN_ID`: The id of the admin user, which allows to RESET the chat
|
- `ADMIN_ID`: The id of the admin user, which allows to RESET the chat
|
||||||
3. Run `docker-compose up -d` to start the bot
|
3. Run `docker-compose up -d` to start the bot
|
||||||
|
|||||||
10
bot.py
10
bot.py
@ -116,7 +116,7 @@ class Bot:
|
|||||||
# pull the model
|
# pull the model
|
||||||
# await self.ollama.pull(self.model)
|
# await self.ollama.pull(self.model)
|
||||||
|
|
||||||
activity = discord.Activity(name='Status', state=f'Hi, I\'m {self.bot_name.title()}! I only respond to mentions.', type=discord.ActivityType.custom)
|
activity = discord.Activity(name='Status', state=f'Hi, I\'m {self.bot_name.title()}. Don\'t talk to me.', type=discord.ActivityType.custom)
|
||||||
await self.discord.change_presence(activity=activity)
|
await self.discord.change_presence(activity=activity)
|
||||||
|
|
||||||
logging.info(
|
logging.info(
|
||||||
@ -173,14 +173,14 @@ class Bot:
|
|||||||
await response.write(message, 'I am sorry, I am unable to respond in private messages.')
|
await response.write(message, 'I am sorry, I am unable to respond in private messages.')
|
||||||
return
|
return
|
||||||
|
|
||||||
# Do not respond to messages that don't mention us
|
# Do not respond to messages that don't mention us. 0.2 is 20 percent chance to answer anyway.
|
||||||
if not self.discord.user.mentioned_in(message) or message.author.bot or '@everyone' in message.content or '@here' in message.content:
|
if not self.discord.user.mentioned_in(message) or message.author.bot or '@everyone' in message.content or '@here' in message.content:
|
||||||
# don't respond to messages that don't mention us, but save it for context
|
# don't respond to messages that don't mention us, but save it for context
|
||||||
await self.save_message(str(message.channel.id), self.message(message, message.content), 'user')
|
await self.save_message(str(message.channel.id), self.message(message, message.content), 'user')
|
||||||
logging.info('Message saved for context in %s, but it was not for us', (message.channel.id))
|
logging.info('Message saved for context in %s, but it was not for us', (message.channel.id))
|
||||||
|
|
||||||
# However, if randomly it does accept the message, and respond. There is a 0.01% chance of it happening.
|
# However, if randomly it does accept the message, and respond. There is a 0.01% chance of it happening.
|
||||||
if (random.random() * 1000) > 0.1:
|
if (random.random()* 1000) > 0.1:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Clean message
|
# Clean message
|
||||||
@ -238,8 +238,12 @@ class Bot:
|
|||||||
response_message = ''
|
response_message = ''
|
||||||
data = await self.ollama.chat(model=self.model, keep_alive=-1, stream=False, messages=local_messages, options={'num_ctx': self.ctx})
|
data = await self.ollama.chat(model=self.model, keep_alive=-1, stream=False, messages=local_messages, options={'num_ctx': self.ctx})
|
||||||
|
|
||||||
|
try:
|
||||||
response_message = data['message']['content']
|
response_message = data['message']['content']
|
||||||
await self.save_message(channel_id, response_message, 'assistant')
|
await self.save_message(channel_id, response_message, 'assistant')
|
||||||
|
except Exception as e:
|
||||||
|
logging.error('Error saving response: %s', e)
|
||||||
|
return 'I am sorry, I am unable to respond at the moment.'
|
||||||
|
|
||||||
return response_message
|
return response_message
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -44,7 +44,7 @@ services:
|
|||||||
image: redis/redis-stack-server:latest
|
image: redis/redis-stack-server:latest
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- redis:/data
|
- /portainer/Files/AppData/Config/discordluna/redis:/data
|
||||||
networks:
|
networks:
|
||||||
- redis
|
- redis
|
||||||
expose:
|
expose:
|
||||||
|
|||||||
18
package-lock.json
generated
18
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ollama-discord-bot",
|
"name": "ollama-discord-bot",
|
||||||
"version": "1.0.7",
|
"version": "1.1.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ollama-discord-bot",
|
"name": "ollama-discord-bot",
|
||||||
"version": "1.0.7",
|
"version": "1.1.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@semantic-release/commit-analyzer": "^11.1.0",
|
"@semantic-release/commit-analyzer": "^11.1.0",
|
||||||
@ -828,12 +828,12 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/braces": {
|
"node_modules/braces": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||||
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
|
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fill-range": "^7.0.1"
|
"fill-range": "^7.1.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
@ -1605,9 +1605,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fill-range": {
|
"node_modules/fill-range": {
|
||||||
"version": "7.0.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||||
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
|
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"to-regex-range": "^5.0.1"
|
"to-regex-range": "^5.0.1"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ollama-discord-bot",
|
"name": "ollama-discord-bot",
|
||||||
"version": "1.0.7",
|
"version": "1.1.2",
|
||||||
"description": "This Discord chatbot is built to follow the chat flow and have a conversation with the user. The bot is built using the discord.py library, and the chat is stored in Redis. The number of messages to have in context is configurable.",
|
"description": "This Discord chatbot is built to follow the chat flow and have a conversation with the user. The bot is built using the discord.py library, and the chat is stored in Redis. The number of messages to have in context is configurable.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
discord-py==2.3.2
|
discord-py==2.5.2
|
||||||
redis==5.0.4
|
redis==5.0.4
|
||||||
ollama==0.2.0
|
ollama==0.2.0
|
||||||
|
audioop-lts
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user