A User Installable Discord App, made using JDA-5 ( java discord api 5 ), LangChain4J, and using Ollama to provide Ai Response anywhere in discord
Please Read : Important Things to Consider
- Features
- Prerequisite
- How-To
- Whitelisting Other People to use the App
- Important Things to Consider before Using the Project
- Limitations
- Run Using Docker
- Build Docker Image Your self
- SearXNG Guide
- Command Example
- Simple To Use
- Web Search Capabilities using SearXNG
- Web Document for RAG Support using URL
- Function Calling
- Normal Document Support
- can be used anywhere in discord where user installable apps are supported
- you can run you query by a different model on the fly using the model's field ( example below )
- URL RAG supported, where you can provide a url in the URL Option and the bot will take the Website as a context
- Ollama 0.28 or Greater ( Download Here )
- Ai Model for Ollama ( Download Here ) [ llama3 Preferred ]
- Java 19 or Greater
- Gradle 7.6 or Greater ( Download Here )
- A Discord App ( make New app from discord developer portal )
- Optional : SearXNG for Web Search ( Setup Here ) ( AiLama Guide Here )
- First Clone this Repo
https://github.com/ZeyoYT/AiLama.git
- Change Directory
cd AiLama
- Create Dot Env File ( check .env.example ) and Fill Details
mv ./.env.example ./.env
- Build Project
./gradlew build
After Building the project, a new Jar File would be made in AiLama/build/shadow/
, that jar file can now be used to run the bot using the following command
java -jar ./<jar file name here>.jar
- Go to
https://discord.com/developers/applications
- Click 'New Application' button
- Give it a Name and agree to TOS and Developer Policy
- Go to Bot and Un-Select Public Bot and Enable Presence Intent & Server Members Intent
- Click on Reset Token and Reset the bot's token
- Copy the Shown Token and Paste it in the
.env
file - Save the changes
- Go to Installation and Un-Select Guild Install, and Select User Install
- in Install Link select
Discord Provided Link
, then copy the link and open it - Authorize the App
Using the Authorization Link, you can allow others to install the app, but to actually use the app you need to whitelist them
In the Dot Env File ( .env ), there is a field called WHITELISTED_USERS
, it must be shown something like this
WHITELISTED_USERS='WHITELISTED_USER_ID_HERE, WHITELISTED_USER_ID_HERE, ...'
in this you need to add there User ID's inside a single quote seperated by coma ( , ), for Example
WHITELISTED_USERS='426802118683262976, 259214353931304963, 848561799132741652'
Note: After Authorization of app, they might need to restart discord for the app to show up, and the app must be running, or else the command wont be registerd
- This is a side project, i will try my best to maintain it
- You Need to run the Bot to use the command and keep it running
- Code Quality is Low because i am still new with Ai and Lang Chain
- This project uses a unreleased feature of JDA-5 that Supports User Installable Apps
- Because its a unreleased feature, i didnt find any proper command framework, so a workaround manual command registration code was used ( will be fixed in future release )
- The Ai does not have a memory of previous conversation (would be added in future)
- Its my first time making a docker image, so there might be some issues with it
- First Response might be slow because of the model loading
- The Response will varay from model to model
- URL RAG might not work with smaller models that support less context window
- Only supports Ollama right now
- No Memory for previous conversations
Docker Image is Available at Docker Hub
version: '3.8'
services:
app:
image: ailama:latest
environment:
- TOKEN=<YOUR_BOT_TOKEN>
- OLLAMA_URL=<YOUR_OLLAMA_URL>
- OLLAMA_PORT=<YOUR_OLLAMA_PORT>
- OLLAMA_MODEL=<YOUR_OLLAMA_MODEL>
- OLLAMA_EMBEDDING_MODEL=<YOUR_OLLAMA_EMBEDDING_MODEL>
- DEV_ID=<YOUR_DISCORD_ID>
# Optional Parameters :-
# Write inside single quotes and the user ids separated by commas, if you dont want to use this feature, just write '' (empty string enclosed by single quotes)
- WHITELISTED_USERS='<user_id1>,<user_id2>,<user_id3> ... <user_idN>'
- SEARXNG_URL=<YOUR_SEARXNG_URL>
- SEARXNG_PORT=<YOUR_SEARXNG_PORT>
- SEARXNG_ENGINES=<YOUR_SEARXNG_ENGINES>
docker-compose up -d
docker pull zeyoog/ailama
docker run -e "TOKEN=<bot token>" -e OLLAMA_URL=<ollama_host_url> -e OLLAMA_PORT=<ollama_port> -e OLLAMA_MODEL=<ollama_model> -e OLLAMA_EMBEDDING_MODEL=<ollama_embedding_model> -e DEV_ID=<developer_id> -e "WHITELISTED_USERS='<whitelisted_user_id>, <whitelisted_user_id>'" ailama:latest
After Building you can also use the docker compose to run the bot
1. Clone Repo and Change Directory :
git clone https://github.com/zeyoyt/AiLama.git
cd AiLama
2. Run Docker Build Command :
docker build -t ailama:latest .
3. Run Docker Container :
docker run -e "TOKEN=<bot token>" -e OLLAMA_URL=<ollama_host_url> -e OLLAMA_PORT=<ollama_port> -e OLLAMA_MODEL=<ollama_model> -e OLLAMA_EMBEDDING_MODEL=<ollama_embedding_model> -e DEV_ID=<developer_id> -e "WHITELISTED_USERS='<whitelisted_user_id>, <whitelisted_user_id>'" ailama:latest
WARNING :- Using SearXNG you are scrapping results of different search engines and it might get you blocked from that search engine as its against there TOS
- First Install SearXNG ( Setup Here )
- After Setting SearXNG, Open the
settings.yml
file ( Guide Here ) - Find
Search:
( Guide Here ) - Add
json
toFormats
like :-
# In settings.yml
search:
formats:
- html
- json
- Add the Following Environment Variables to the
.env
file
SEARXNG_URL=<SEARXNG_HOST_URL>
SEARXNG_PORT=<SEARXNG_PORT>
SEARXNG_ENGINES=<SEARXNG_ENGINES>
- Restart the Bot and Now you can use the Web Search FeatureS='SEARCH_ENGINE_HERE, SEARCH_ENGINE_HERE, ...'
/ai ask: <query here>
Example :-
/ai ask:Why is the Sky Blue
/ai ask: <query> model: <model_name_with_version>
Example :-
/ai ask:Why is the Sky Blue model:gemma:latest
Asking Query in a User only Visible Message
( the command would be visible to the user who executed it ) :-
/ai ask: <query> ephemeral: <Options : True | False>
Example :-
/ai ask:Why is the Sky Blue ephemeral:True
/ai ask: <query> url: <url>
Example :-
/ai ask:Why is the Sky Blue url:https://www.space.com/why-is-the-sky-blue
/ai ask: <query> web: <Options : True | False>
Example :-
/ai ask:What is the Time web:True
/web search: <search query>
Example :-
/ai ask:What is the Time