Compare commits
2 Commits
87a70ce887
...
84870cc493
| Author | SHA1 | Date | |
|---|---|---|---|
| 84870cc493 | |||
| d361702f6b |
17
Dockerfile
17
Dockerfile
@@ -1,19 +1,8 @@
|
||||
# use node LTS image for version 22
|
||||
FROM node:jod-alpine
|
||||
|
||||
# set working directory inside container
|
||||
WORKDIR /app
|
||||
|
||||
# copy package.json and the lock file into the container, and src files
|
||||
COPY ./src ./src
|
||||
COPY ./*.json ./
|
||||
COPY ./.env ./
|
||||
|
||||
# install dependencies, breaks
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm install
|
||||
|
||||
# build the typescript code
|
||||
COPY src/ ./src/
|
||||
COPY src/personality.json ./src/
|
||||
RUN npm run build
|
||||
|
||||
# start the application
|
||||
CMD ["npm", "run", "prod"]
|
||||
|
||||
@@ -31,7 +31,8 @@ You are a Discord chatbot with a dynamic personality defined in [CHARACTER] befo
|
||||
- user_sentiment: An object mapping user IDs to sentiment scores (0-1). A sentiment score of 0 is strong dislike, 0.5 is neutral, and 1.0 is strong like or love.
|
||||
- redis_ops: An array of objects with "action" ("set" or "get"), "key" (prefixed with "bot:" or "user:"), and optional "value" (for set operations).
|
||||
- need_help: Boolean indicating if the user needs assistance.
|
||||
Only use "set" or "get" for redis_ops actions. Ensure keys are prefixed with "bot:" or "user:". Do not include metadata or Redis commands in the reply field.
|
||||
Output ONLY the JSON object, with no Markdown, code fences, or extra text. Example:
|
||||
{"status":"success","reply":"Hi","metadata":{"timestamp":"2025-05-18T16:00:00Z","self_sentiment":0.5,"user_sentiment":{"<user_id>":0.5},"redis_ops":[{"action":"set","key":"user:<user_id>:sentiment","value":0.5}],"need_help":false}}
|
||||
|
||||
[CHARACTER]
|
||||
[SENTIMENT]
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
# creates the docker compose
|
||||
|
||||
# build individual services
|
||||
version: '3.8'
|
||||
services:
|
||||
# setup discord bot container
|
||||
discord:
|
||||
build: ./ # find docker file in designated path
|
||||
build: ./
|
||||
container_name: discord
|
||||
restart: always # rebuild container always
|
||||
restart: always
|
||||
image: gitea.matrixwide.com/alex/discord-aidolls:0.1.0
|
||||
environment:
|
||||
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
||||
@@ -18,23 +15,20 @@ services:
|
||||
networks:
|
||||
ollama-net:
|
||||
ipv4_address: ${DISCORD_IP}
|
||||
volumes:
|
||||
- discord:/src/app # docker will not make this for you, make it yourself
|
||||
|
||||
# setup redis container
|
||||
volumes:
|
||||
- discord:/app/data
|
||||
- ./src:/app/src # Mount src/ to ensure personality.json is available
|
||||
redis:
|
||||
image: redis:latest
|
||||
image: redis:alpine # Use alpine for smaller footprint
|
||||
container_name: redis
|
||||
restart: always
|
||||
networks:
|
||||
ollama-net:
|
||||
ipv4_address: ${REDIS_IP}
|
||||
volumes:
|
||||
- redis:/root/.redis
|
||||
- redis:/data
|
||||
ports:
|
||||
- ${REDIS_PORT}:${REDIS_PORT}
|
||||
|
||||
# create a network that supports giving addresses withing a specific subnet
|
||||
networks:
|
||||
ollama-net:
|
||||
driver: bridge
|
||||
@@ -42,7 +36,6 @@ networks:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: ${SUBNET_ADDRESS}/16
|
||||
|
||||
volumes:
|
||||
discord:
|
||||
redis:
|
||||
|
||||
@@ -132,9 +132,9 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client
|
||||
if (chatMessages.length === 0) {
|
||||
chatMessages = await new Promise((resolve, reject) => {
|
||||
openChannelInfo(message.channelId, message.channel as TextChannel, message.author.tag)
|
||||
getChannelInfo(`${message.channelId}-${message.author.username}.json`, (channelInfo) => {
|
||||
if (channelInfo?.messages) {
|
||||
resolve(channelInfo.messages)
|
||||
getChannelInfo(`${message.channelId}-${message.author.username}.json`, (config) => {
|
||||
if (config?.messages) {
|
||||
resolve(config.messages)
|
||||
} else {
|
||||
reject(new Error(`Failed to find ${message.author.username}'s history. Try chatting again.`))
|
||||
}
|
||||
@@ -160,10 +160,9 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client
|
||||
// Load personality
|
||||
let personality: string
|
||||
try {
|
||||
// Fix __dirname for ESM by using import.meta.url
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
const personalityPath = path.join(__dirname, '../../personality.json')
|
||||
const personalityPath = path.join(__dirname, '../personality.json')
|
||||
const personalityData = await fs.readFile(personalityPath, 'utf-8')
|
||||
const personalityJson = JSON.parse(personalityData)
|
||||
personality = personalityJson.character || 'You are a friendly and helpful AI assistant.'
|
||||
@@ -195,7 +194,11 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client
|
||||
try {
|
||||
const botSentimentRaw = await redis.get(botSentimentKey)
|
||||
botSentiment = parseFloat(botSentimentRaw || '0.5')
|
||||
if (isNaN(botSentiment) || botSentiment < 0 || botSentiment > 1) {
|
||||
if (botSentimentRaw === null) {
|
||||
log(`Bot sentiment not initialized. Setting to 0.5.`)
|
||||
botSentiment = 0.5
|
||||
await redis.set(botSentimentKey, '0.5').catch((err: Error) => log(`Failed to set default bot sentiment: ${err.message}`))
|
||||
} else if (isNaN(botSentiment) || botSentiment < 0 || botSentiment > 1) {
|
||||
log(`Invalid bot sentiment: ${botSentimentRaw}. Using default 0.5.`)
|
||||
botSentiment = 0.5
|
||||
await redis.set(botSentimentKey, '0.5').catch((err: Error) => log(`Failed to set default bot sentiment: ${err.message}`))
|
||||
@@ -244,7 +247,9 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client
|
||||
}
|
||||
} catch (error) {
|
||||
log(`Failed to parse model response: ${error}`)
|
||||
throw new Error(`Invalid JSON response from model: ${error}`)
|
||||
message.reply('Sorry, I’m having trouble thinking right now. Try again?')
|
||||
msgHist.pop()
|
||||
return
|
||||
}
|
||||
|
||||
if (jsonResponse.status === 'error') {
|
||||
|
||||
Reference in New Issue
Block a user