From 54b5eadcc493a5db5cedd0139b728c2c47ba70e0 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sun, 30 Apr 2023 00:31:28 +0200 Subject: [PATCH] docs: add discord-bot example (#126) --- Dockerfile.dev | 14 ++++++++++++ docker-compose.yaml | 4 ++-- examples/README.md | 1 + examples/chatbot-ui/docker-compose.yaml | 2 +- examples/discord-bot/.env.example | 6 +++++ examples/discord-bot/README.md | 28 ++++++++++++++++++++++++ examples/discord-bot/docker-compose.yaml | 23 +++++++++++++++++++ examples/discord-bot/models | 1 + 8 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 Dockerfile.dev create mode 100644 examples/discord-bot/.env.example create mode 100644 examples/discord-bot/README.md create mode 100644 examples/discord-bot/docker-compose.yaml create mode 120000 examples/discord-bot/models diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..16c8447 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,14 @@ +ARG GO_VERSION=1.20 +ARG DEBIAN_VERSION=11 +ARG BUILD_TYPE= + +FROM golang:$GO_VERSION as builder +WORKDIR /build +RUN apt-get update && apt-get install -y cmake +COPY . . +RUN make build + +FROM debian:$DEBIAN_VERSION +COPY --from=builder /build/local-ai /usr/bin/local-ai +EXPOSE 8080 +ENTRYPOINT [ "/usr/bin/local-ai" ] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 8058e46..f7d7653 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,11 +5,11 @@ services: image: quay.io/go-skynet/local-ai:latest build: context: . - dockerfile: Dockerfile + dockerfile: Dockerfile.dev ports: - 8080:8080 env_file: - .env volumes: - ./models:/models:cached - command: ["/usr/bin/local-ai" ] \ No newline at end of file + command: ["/usr/bin/local-ai" ] diff --git a/examples/README.md b/examples/README.md index 5368624..dfbbdd5 100644 --- a/examples/README.md +++ b/examples/README.md @@ -5,6 +5,7 @@ Here is a list of projects that can easily be integrated with the LocalAI backen ## Projects - [chatbot-ui](https://github.com/go-skynet/LocalAI/tree/master/examples/chatbot-ui/) (by [@mkellerman](https://github.com/mkellerman)) +- [discord-bot](https://github.com/go-skynet/LocalAI/tree/master/examples/discord-bot/) (by [@mudler](https://github.com/mudler)) ## Want to contribute? diff --git a/examples/chatbot-ui/docker-compose.yaml b/examples/chatbot-ui/docker-compose.yaml index c7782c3..a5f94ac 100644 --- a/examples/chatbot-ui/docker-compose.yaml +++ b/examples/chatbot-ui/docker-compose.yaml @@ -5,7 +5,7 @@ services: image: quay.io/go-skynet/local-ai:latest build: context: ../../ - dockerfile: Dockerfile + dockerfile: Dockerfile.dev ports: - 8080:8080 environment: diff --git a/examples/discord-bot/.env.example b/examples/discord-bot/.env.example new file mode 100644 index 0000000..7f94e67 --- /dev/null +++ b/examples/discord-bot/.env.example @@ -0,0 +1,6 @@ +OPENAI_API_KEY=x +DISCORD_BOT_TOKEN=x +DISCORD_CLIENT_ID=x +OPENAI_API_BASE=http://api:8080 +ALLOWED_SERVER_IDS=x +SERVER_TO_MODERATION_CHANNEL=1:1 diff --git a/examples/discord-bot/README.md b/examples/discord-bot/README.md new file mode 100644 index 0000000..6053ae8 --- /dev/null +++ b/examples/discord-bot/README.md @@ -0,0 +1,28 @@ +# discord-bot + +## Setup + +```bash +# Clone LocalAI +git clone https://github.com/go-skynet/LocalAI + +cd LocalAI/examples/discord-bot + +git clone https://github.com/go-skynet/gpt-discord-bot.git + +# (optional) Checkout a specific LocalAI tag +# git checkout -b build + +# Download gpt4all-j to models/ +wget https://gpt4all.io/models/ggml-gpt4all-j.bin -O models/ggml-gpt4all-j + +# Set the discord bot options +cp -rfv .env.example .env +vim .env + +# start with docker-compose +docker-compose up -d --build +``` + +Open up the URL in the console and give permission to the bot in your server. Start a thread with `/chat ..` + diff --git a/examples/discord-bot/docker-compose.yaml b/examples/discord-bot/docker-compose.yaml new file mode 100644 index 0000000..19056d5 --- /dev/null +++ b/examples/discord-bot/docker-compose.yaml @@ -0,0 +1,23 @@ +version: '3.6' + +services: + api: + image: quay.io/go-skynet/local-ai:latest + build: + context: ../../ + dockerfile: Dockerfile.dev + ports: + - 8080:8080 + environment: + - DEBUG=true + - MODELS_PATH=/models + volumes: + - ./models:/models:cached + command: ["/usr/bin/local-ai" ] + + bot: + build: + context: ./gpt-discord-bot + dockerfile: Dockerfile + env_file: + - .env diff --git a/examples/discord-bot/models b/examples/discord-bot/models new file mode 120000 index 0000000..7055d2b --- /dev/null +++ b/examples/discord-bot/models @@ -0,0 +1 @@ +../chatbot-ui/models/ \ No newline at end of file