Skip to content

Commit be8e4bf

Browse files
committed
Merge branch 'yGuy/master' into release
✨ Upgrade 2.1.2 from upstream
2 parents 13bfe96 + 4cae8f9 commit be8e4bf

18 files changed

+1345
-4091
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/node_modules/
2+
/dist/
23
/*.crt
34
docker-compose.override.yml
45

Dockerfile

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@ FROM node:20-slim as npm_builder
33
#20.3.0-bookworm-slim (Debian 12)
44

55
WORKDIR /app
6-
COPY [ "package.json", "package-lock.json", ".npmrc", \
7-
".eslintrc.json", ".prettierignore", ".prettierrc", \
8-
"tsconfig.json", \
9-
"esbuild.config.js", \
10-
"./" ]
6+
COPY [ "package.json", "package-lock.json", "tsconfig.json", "./"]
117
COPY [ "src/", "./src/" ]
128

13-
RUN npm ci
14-
RUN npm run lint
9+
RUN npm ci --omit dev
1510
RUN npm run build
16-
RUN rm -rf node_modules/ && npm ci --omit dev
17-
1811

1912
# NPM runtime image
2013
FROM node:20-slim as npm_runtime
@@ -23,12 +16,13 @@ WORKDIR /app
2316

2417
ARG NODE_ENV=production
2518
ENV NODE_ENV $NODE_ENV
19+
ENV PLUGINS=image-plugin,graph-plugin
2620

2721
# Avoid running as root:
2822
USER node
2923

3024
COPY --from=npm_builder [ "/app/node_modules/", "./node_modules/" ]
31-
COPY --from=npm_builder [ "/app/out/", "./out/" ]
25+
COPY --from=npm_builder [ "/app/dist/", "./src/" ]
3226
COPY [ "./license.md", "./" ]
3327

3428
ENTRYPOINT [ "node", "out/botservice.mjs" ]

README.md

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
![A chat window in Mattermost showing the chat between the OpenAI bot and "yGuy"](./mattermost-chat.png)
44

5-
Here's how to get the bot running - it's easy if you have a Docker server.
5+
The bot can talk to you like a regular mattermost user. It's like having chat.openai.com built collaboratively built into Mattermost!
6+
But that's not all, you can also use it to generate images via Dall-E or diagram visualizations via a yFiles plugin!
7+
8+
Here's how to get the bot running - it's easy if you have a Docker host.
69

710
You need
811
- the [Mattermost token](https://docs.mattermost.com/integrations/cloud-bot-accounts.html) for the bot user (`@chatgpt` by default)
912
- the [OpenAI API key](https://platform.openai.com/account/api-keys)
10-
- a [Docker](https://www.docker.com/) server for continuously running the service, alternatively for testing, Node.js is sufficient.
13+
- a [Docker](https://www.docker.com/) server for continuously running the service, alternatively for testing, Node.js 16 is sufficient.
1114

1215
Andrew Zigler from Mattermost created a [YouTube Video](https://www.youtube.com/watch?v=Hx4Ex7YZZiA) that quickly guides you through the setup.
1316

@@ -16,45 +19,31 @@ If you want to learn more about how this plugin came to live, [read the blog pos
1619

1720
## Options
1821

19-
These are the available options, you can set them as environment variables when running [the script](./src/botservice.js)
20-
or when [running the docker image](#using-the-ready-made-image) or when configuring your [docker-compose](#docker-compose) file.
21-
22-
| Name | Required | Example Value | Description |
23-
|---------------------|----------|-----------------------------|---------------------------------------------------------------------------------------------|
24-
| MATTERMOST_URL | yes | `https://mattermost.server` | The URL to the server. This is used for connecting the bot to the Mattermost API |
25-
| MATTERMOST_TOKEN | yes | `abababacdcdcd` | The authentication token from the logged in mattermost bot |
26-
| OPENAI_API_KEY | yes | `sk-234234234234234234` | The OpenAI API key to authenticate with OpenAI |
27-
| OPENAI_MODEL_NAME | no | `gpt-3.5-turbo` | The OpenAI language model to use, defaults to `gpt-3.5-turbo` |
28-
| OPENAI_MAX_TOKENS | no | `2000` | The max_tokens parameter to pass to the OpenAI API, with a default value of 2000. API will answer up to this number of tokens |
29-
| OPENAI_TEMPERATURE | no | `0.2` | The sampling temperature to use, between 0 and 2, defaults to 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. |
30-
| AZURE_OPENAI_API_KEY | no | `0123456789abcdefghijklmno` | The Azure OpenAI Service API key to authoenticate |
31-
| AZURE_OPENAI_API_INSTANCE_NAME | no | `example-name` | The instance name on the Azure OpenAI Service |
32-
| AZURE_OPENAI_API_DEPLOYMENT_NAME | no | `gpt-35-turbo` | The name of the deployed model on the Azure OpenAI Service |
33-
| AZURE_OPENAI_API_VERSION | no | `2023-03-15-preview` | The Azure OpenAI version |
34-
| YFILES_SERVER_URL | no | `http://localhost:3835` | The URL to the yFiles graph service for embedding auto-generated diagrams. |
35-
| NODE_EXTRA_CA_CERTS | no | `/file/to/cert.crt` | a link to a certificate file to pass to node.js for authenticating self-signed certificates |
36-
| MATTERMOST_BOTNAME | no | `"@chatgpt"` | the name of the bot user in Mattermost, defaults to '@chatgpt' |
37-
| MAX_PROMPT_TOKENS | no | `2000` | Maximum token count of the prompt passed to the OpenAI API. default is 2000 |
38-
| DEBUG_LEVEL | no | `TRACE` | a debug level used for logging activity, defaults to `INFO` |
22+
These are the available options, you can set them as environment variables when running [the script](./src/botservice.ts)
23+
or when [running the docker image](#using-the-ready-made-docker-image) or when configuring your [docker-compose](#docker-compose) file.
24+
25+
| Name | Required | Example Value | Description |
26+
|----------------------|----------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
27+
| MATTERMOST_URL | yes | `https://mattermost.server` | The URL to the server. This is used for connecting the bot to the Mattermost API |
28+
| MATTERMOST_TOKEN | yes | `abababacdcdcd` | The authentication token from the logged in mattermost bot |
29+
| OPENAI_API_KEY | yes | `sk-234234234234234234` | The OpenAI API key to authenticate with OpenAI |
30+
| OPENAI_MODEL_NAME | no | `gpt-3.5-turbo` | The OpenAI language model to use, defaults to `gpt-3.5-turbo` |
31+
| OPENAI_MAX_TOKENS | no | `2000` | The maximum number of tokens to pass to the OpenAI API, defaults to 2000 |
32+
| OPENAI_TEMPERATURE | no | `0.2` | The sampling temperature to use, between 0 and 2, defaults to 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. |
33+
| YFILES_SERVER_URL | no | `http://localhost:3835` | The URL to the yFiles graph service for embedding auto-generated diagrams. |
34+
| NODE_EXTRA_CA_CERTS | no | `/file/to/cert.crt` | a link to a certificate file to pass to node.js for authenticating self-signed certificates |
35+
| MATTERMOST_BOTNAME | no | `"@chatgpt"` | the name of the bot user in Mattermost, defaults to '@chatgpt' |
36+
| PLUGINS | no | `graph-plugin, image-plugin` | The enabled plugins of the bot. By default all plugins (grpah-plugin and image-plugin) are enabled. |
37+
| DEBUG_LEVEL | no | `TRACE` | a debug level used for logging activity, defaults to `INFO` |
38+
| BOT_CONTEXT_MSG | no | `15` | The number of previous messages which are appended to the conversation with ChatGPT, defaults to 100 |
3939

4040
> **Note**
4141
> The `YFILES_SERVER_URL` is used for automatically converting text information created by the bot into diagrams.
4242
> This is currently in development. You can see it in action, here:
4343
> [LinkedIn Post](https://www.linkedin.com/posts/yguy_chatgpt-yfiles-diagramming-activity-7046713027005407232-2bKH)
4444
> If you are interested in getting your hands on the plugin, please contact [yWorks](https://www.yworks.com)!
4545
46-
## Enhanced from the [original yGuy/chatgpt-mattermost-bot](https://github.com/yGuy/chatgpt-mattermost-bot)
47-
48-
* Support Azure OpenAI API
49-
* Migrated to TypeScript.
50-
+ Formatted by Prettier
51-
+ Lint by eslint
52-
+ Build by esbuild
53-
* Token-count-based conversation thread management
54-
* Splitting message that are too long
55-
* Support GitLab AutoDevOps by test dummy
56-
57-
## Using the ready-made image
46+
## Using the ready-made Docker image
5847

5948
Use the prebuilt image from [`gitlab.on-o.com/docker/chatgpt-mattermost-bot/release`](https://gitlab.on-o.com/Docker/chatgpt-mattermost-bot/container_registry/150)
6049

@@ -67,29 +56,17 @@ docker run -d --restart unless-stopped \
6756
gitlab.on-o.com/docker/chatgpt-mattermost-bot/release:latest
6857
```
6958

70-
As Azure OpenAI Service case
71-
```bash
72-
docker run -d --restart unless-stopped \
73-
-e MATTERMOST_URL=https://mattermost.server \
74-
-e MATTERMOST_TOKEN=abababacdcdcd \
75-
-e AZURE_OPENAI_API_KEY=234234234234234234 \
76-
-e AZURE_OPENAI_API_INSTANCE_NAME=example-name \
77-
--name chatbot \
78-
gitlab.on-o.com/docker/chatgpt-mattermost-bot/release:latest
79-
```
80-
81-
82-
## Building the docker image yourself
59+
## Building the Docker image manually
8360

8461
First step is to clone this repo.
8562

8663
```bash
8764
git clone https://github.com/takuya-o/chatgpt-mattermost-bot.git && cd chatgpt-mattermost-bot
8865
```
8966

90-
For testing, you could now just run `npm ci` and `npm run start` or `npx ts-node src/botservice.ts` directly, but be sure to set the [environment variables](#options) or pass them to the node process, first!
67+
For testing, you could now just run `npm install` and `npm run start` directly, but be sure to set the [environment variables](#options) or pass them to the node process, first!
9168

92-
For production use, in order to create a service on a docker container that will always provide the service without you having to run it on your own PC, you can do the following:
69+
For production use, in order to create a service on a docker container that will always provide the service without you having to run it on your own machine, you can do the following:
9370

9471
Build the docker image from the [Dockerfile](./Dockerfile):
9572
```bash
@@ -171,15 +148,8 @@ services:
171148
NODE_EXTRA_CA_CERTS: /certs/certfile.crt
172149
```
173150
174-
### Run the container as a daemon
175-
When all configuration is complete, build and start the container service.
176-
177-
Build docker image:
178-
```bash
179-
docker compose build
180-
```
181-
182-
Start container:
151+
### Run the container as a service
152+
When all configuration is complete, start the container service.
183153
```bash
184154
docker compose up -d
185155
```
@@ -205,10 +175,10 @@ Here's an example chat that I just had with our bot:
205175
>chatgpt (BOT):
206176
>>Hello there! I'm @chatgpt, a friendly and reliable Mattermost bot designed to make your communication experience smoother and more efficient. I'm honored to be part of the team at yWorks, where I help employees get things done faster and with less hassle. With my advanced machine learning algorithms, I'm capable of understanding complex natural language queries and providing succinct and accurate responses in a matter of seconds. Whether you're a developer looking for information on your codebase or a manager seeking to streamline your team's workflows, I'm here to help. Installing a Mattermost chatbot like me is a must for any organization looking to boost its productivity and enjoy a more pleasant communication experience. So what are you waiting for? Let's chat!
207177
208-
I built this tool as a quick hack on a rainy Saturday afternoon, but we are using the bot in production in our Mattermost instance at our office at [yworks](https://www.yworks.com) and the bot has proved to be very helpful for many simple tasks. Give it a try and provide feedback if you like! It's really not very expensive: We had it runnning for about 30 users for two weeks and that cost us less than half a dollar for the ChatGPT service!
178+
I built this tool as a quick hack on a rainy Saturday afternoon, but we are using the bot in production in our Mattermost instance at our office at [yworks](https://www.yworks.com) and the bot has proved to be very helpful for many simple tasks. Give it a try and provide feedback if you like! It's really not very expensive: We had it running for about 30 users for two weeks and that cost us less than half a dollar for the ChatGPT service!
209179

210180
I will also accept helpful pull requests if you find an issue or have an idea for an improvement.
211181

212182
Last but not least, check out [yWorks](https://www.yworks.com)' fine diagramming SDKs for software developers [yFiles](https://yworks.com/yfiles) and our [free online graph and diagram editors](https://yworks.com/editors)!
213183

214-
This is under MIT license Copyright (c) 2023 Sebastian Mueller (yWorks)
184+
This is under MIT license Copyright (c) 2023 Sebastian Mueller (yWorks) and Michael Haeglsperger (yWorks)

mattermost-chat.png

-122 KB
Loading

0 commit comments

Comments
 (0)