Skip to content

Commit

Permalink
✨ feat(botservice.ts): Changed to respond to system notifications col…
Browse files Browse the repository at this point in the history
…lectively

Because of splitting messages results in slow response.

✨ feat(package.json): add bugs and homepage URLs for issue reporting and project homepage
🐛 fix(package.json): add npm dedup to upgrade script
🔧 chore(package.json): update versions of dev dependencies
🔧 fix(botservice.ts): filter and modify messages to remove system messages and their lines
🐛 fix(botservice.ts): change variable name case from lowercase limit_tokes to uppercase LIMIT_TOKENS to improve semantics
✨ feat(botservice.ts): add expireMessages function to remove old messages
✨ feat: added functionality to add completion and modify last line when continuing a thread
🐛 fix: removed unnecessary function call and added debug information to log
🔧 fix(mm-client.ts): fix import order of packages
🔧 fix(openai-thread-completion.ts): change variable name to uppercase MAX_TOKENS
✨ feat(openai-thread-completion.ts): add usage statistics for the response
🔧 fix(process-graph-response.ts): fix import order

Added bugs and homepage URLs to package.json for issue reporting and accessing the project homepage, allowing users to report issues and access the project's homepage.
Added npm dedup to the upgrade script, which resolves dependency duplication and keeps package versions up to date.
Updated versions of dev dependencies, allowing the use of the latest versions of tools such as TypeScript and ESLint.
Filtered and modified the messages to remove system messages and their lines. This results in a cleaner display of messages within threads.
By changing the variable name to LIMIT_TOKENS, the limit value for tokens becomes more clear. The addition of the expireMessages function allows for the removal of old messages. This ensures that the total token count of the messages does not exceed the limit.
When continuing a thread, the continueThread function is used to add completion to the reply message. The modifyLastLine function is used to modify the last line. The modified answer is then passed to the newPost function to be posted, allowing the thread to continue. Additionally, debug information is added to the log.
  • Loading branch information
takuya-o committed Jul 19, 2023
1 parent 537d514 commit 13bfe96
Show file tree
Hide file tree
Showing 13 changed files with 1,093 additions and 521 deletions.
65 changes: 65 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# # SaaS版
# engines:
# # ... CONFIG CONTENT ...
# tslint:
# enabled: true
# # ... CONFIG CONTENT ...
# checks:
# comment-format:
# enabled: false
# whitespace:
# enabled: false
# semicolon:
# enabled: false
# no-console:
# enabled: false
# # ... CONFIG CONTENT ...
---
version: "2"
plugins:
# csslint:
# enabled: true
# coffeelint:
# enabled: true
duplication:
enabled: true
config:
languages:
# https://docs.codeclimate.com/docs/duplication
- typescript
- ruby
- javascript
- python
- php
# https://docs.codeclimate.com/docs/list-of-engines
# https://docs.codeclimate.com/docs/tslint
# $ ./node_modules/.bin/tslint src/**/*.ts
# tslint:
# enabled: true
# config: tslint.json
eslint:
enabled: true
channel: "stable"
config: .eslintrc.json
fixme:
enabled: true
rubocop:
enabled: true
exclude_patterns:
- config/
- db/
- dist/
- features/
- "**/node_modules/"
- script/
- "**/spec/"
- "**/test/"
- "**/tests/"
- Tests/
- "**/vendor/"
- "**/*_test.go"
- "**/*.d.ts"
- "**/*.min.js"
- "**/*.min.css"
- "**/__tests__/"
- "**/__mocks__/"
32 changes: 30 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,43 @@
//"packageManager": "npm",
"env": { "node": true },
"rules": {
"max-lines-per-function": ["warn", {"max": 75}], //GitLab25
"max-lines": ["warn", {"max": 500}], //GitLab250
//"complexity": ["error", { "max": 5 }], //GitLab5
"import/order": "off",
"sort-imports": "off",
"sort-imports": "warn",
// "simple-import-sort/imports": "error",
// "simple-import-sort/exports": "error",
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/no-unused-vars": ["error", {
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^[A-Z]"
}],
/** 命名規則 */
"@typescript-eslint/naming-convention": [
"error",
{ // classやtypeなどは頭大文
"selector": "typeLike",
"format": ["PascalCase"]
},
{ // グローバル定数はアッパーケース
"selector": "variable",
"modifiers": ["global", "const"],
"format": ["camelCase", "UPPER_CASE"]
},
{ // 変数名はキャメルケース
"selector": "variable",
"format": ["camelCase", "UPPER_CASE"]
}
],
// 未使用の変数や関数は宣言禁止、ただし大文字で始まっているものはクラスなので許す
"no-unused-vars": ["error", {
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^[A-Z]"
}],
"no-console": "error"
}
}
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"arrowParens": "avoid"
}
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ or when [running the docker image](#using-the-ready-made-image) or when configur
| MATTERMOST_TOKEN | yes | `abababacdcdcd` | The authentication token from the logged in mattermost bot |
| OPENAI_API_KEY | yes | `sk-234234234234234234` | The OpenAI API key to authenticate with OpenAI |
| OPENAI_MODEL_NAME | no | `gpt-3.5-turbo` | The OpenAI language model to use, defaults to `gpt-3.5-turbo` |
| OPENAI_MAX_TOKENS | no | `2000` | The maximum number of tokens to pass to the OpenAI API, defaults to 2000 |
| 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 |
| 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. |
| AZURE_OPENAI_API_KEY | no | `0123456789abcdefghijklmno` | The Azure OpenAI Service API key to authoenticate |
| AZURE_OPENAI_API_INSTANCE_NAME | no | `example-name` | The instance name on the Azure OpenAI Service |
| AZURE_OPENAI_API_DEPLOYMENT_NAME | no | `gpt-35-turbo` | The name of the deployed model on the Azure OpenAI Service |
| AZURE_OPENAI_API_VERSION | no | `2023-03-15-preview` | The Azure OpenAI version |
| YFILES_SERVER_URL | no | `http://localhost:3835` | The URL to the yFiles graph service for embedding auto-generated diagrams. |
| 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 |
| MATTERMOST_BOTNAME | no | `"@chatgpt"` | the name of the bot user in Mattermost, defaults to '@chatgpt' |
| DEBUG_LEVEL | no | `TRACE` | a debug level used for logging activity, defaults to `INFO` |
| YFILES_SERVER_URL | no | `http://localhost:3835` | The URL to the yFiles graph service for embedding auto-generated diagrams. |
| 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 |
| MATTERMOST_BOTNAME | no | `"@chatgpt"` | the name of the bot user in Mattermost, defaults to '@chatgpt' |
| MAX_PROMPT_TOKENS | no | `2000` | Maximum token count of the prompt passed to the OpenAI API. default is 2000 |
| DEBUG_LEVEL | no | `TRACE` | a debug level used for logging activity, defaults to `INFO` |

> **Note**
> The `YFILES_SERVER_URL` is used for automatically converting text information created by the bot into diagrams.
Expand All @@ -53,17 +54,17 @@ or when [running the docker image](#using-the-ready-made-image) or when configur
* Splitting message that are too long
* Support GitLab AutoDevOps by test dummy

## Using the docker image
## Using the ready-made image

Use your builted and pushed image.
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)

```bash
docker run -d --restart unless-stopped \
-e MATTERMOST_URL=https://mattermost.server \
-e MATTERMOST_TOKEN=abababacdcdcd \
-e OPENAI_API_KEY=234234234234234234 \
--name chatbot \
<Your Docker Registry>/chatgpt-mattermost-bot:latest
gitlab.on-o.com/docker/chatgpt-mattermost-bot/release:latest
```

As Azure OpenAI Service case
Expand All @@ -74,7 +75,7 @@ docker run -d --restart unless-stopped \
-e AZURE_OPENAI_API_KEY=234234234234234234 \
-e AZURE_OPENAI_API_INSTANCE_NAME=example-name \
--name chatbot \
<Your Docker Registry>/chatgpt-mattermost-bot:latest
gitlab.on-o.com/docker/chatgpt-mattermost-bot/release:latest
```


Expand Down
8 changes: 7 additions & 1 deletion chatgpt-mattermost-bot.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
"path": "."
}
],
"settings": {}
"settings": {},
"extensions": {
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
}
Loading

0 comments on commit 13bfe96

Please sign in to comment.