Skip to content

Commit

Permalink
✨feat(src/AIProvider.ts): Support Cohere Command R+
Browse files Browse the repository at this point in the history
Support Cohere Command R+ and Anthropic Claude 3 by AI provider interface.

Implemented a series of changes related to the development environment, code quality management, and project configuration. This includes updating the development container settings, adding samples for environment variables, introducing Textlint settings, updating VSCode workspace settings, improving Docker Compose configuration, refactoring source code, updating packages, adding a synchronization script, and adjusting TypeScript settings. These changes aim to streamline the development process, improve code readability and maintainability, and enhance the flexibility of project configuration.

Updated the development environment settings to use a new Docker image. Added new variables to the environment variable sample file and introduced Textlint to improve document quality. Updated VSCode workspace settings with added debug configurations. Improved Docker Compose configuration for more flexible environment variable management. The source code includes abstraction of AI providers, refactoring, and addition of new features. Updated package dependencies and added a script to facilitate project synchronization. Finally, adjusted TypeScript settings to improve the development experience.
  • Loading branch information
takuya-o committed Apr 9, 2024
1 parent 8cf103b commit c2f8bc0
Show file tree
Hide file tree
Showing 16 changed files with 8,515 additions and 3,837 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Node.js & TypeScript",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-16-bookworm"
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bookworm"

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Expand All @@ -20,3 +20,4 @@
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
// 新しいイメージを持ってきたらsudo "apt udpate && apt install git-secrets connect-proxy"や.ssh以下が必要
40 changes: 22 additions & 18 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
MATTERMOST_URL=https://mattermost.server.example
MATTERMOST_TOKEN=abababacdcdcd
#MATTERMOST_BOTNAME=@chatgpt
# MATTERMOST_BOTNAME=@chatgpt
PLUGINS=image-plugin

# MAX_PROMPT_TOKEN=3000
# OPENAI_MAX_TOKENS=2000
# OPENAI_TEMPERATURE=1

OPENAI_API_KEY=sk-234234234234234234
# OPENAI_MODEL_NAME=gpt-3.5-turbo
# OPENAI_VISION_MODEL_NAME=gpt-4-vision-preview
# OPENAI_IMAGE_MODEL_NAME=dall-e-2
# OPENAI_VISION_MODEL_NAME=gpt-4-vision-preview

# AZURE_OPENAI_API_KEY=0123456789abcdefghijklmno
# AZURE_OPENAI_API_INSTANCE_NAME=example-name
# AZURE_OPENAI_API_DEPLOYMENT_NAME=gpt-35-turbo
# AZURE_OPENAI_API_VERSION=2023-12-01-preview

#AZURE_OPENAI_API_KEY=0123456789abcdefghijklmno
#AZURE_OPENAI_API_INSTANCE_NAME=example-name
#AZURE_OPENAI_API_DEPLOYMENT_NAME=gpt-35-turbo
#AZURE_OPENAI_API_VERSION=2023-09-01-preview
#MAX_PROMPT_TOKEN=3000
#OPENAI_MAX_TOKENS=2000
#OPENAI_TEMPERATURE=1
# AZURE_OPENAI_IMAGE_API_KEY=0123456789abcdefghijklmno
# AZURE_OPENAI_IMAGE_API_INSTANCE_NAME=example-name
# AZURE_OPENAI_IMAGE_API_DEPLOYMENT_NAME=dall-e-2

#AZURE_OPENAI_VISION_API_KEY=0123456789abcdefghijklmno
#AZURE_OPENAI_VISION_API_INSTANCE_NAME=example-name
#AZURE_OPENAI_VISION_API_DEPLOYMENT_NAME=gpt-4-vision-prewview
# AZURE_OPENAI_VISION_API_KEY=0123456789abcdefghijklmno
# AZURE_OPENAI_VISION_API_INSTANCE_NAME=example-name
# AZURE_OPENAI_VISION_API_DEPLOYMENT_NAME=gpt-4-vision-preview

#AZURE_OPENAI_IMAGE_API_KEY=0123456789abcdefghijklmno
#AZURE_OPENAI_IMAGE_API_INSTANCE_NAME=example-name
#AZURE_OPENAI_IMAGE_API_DEPLOYMENT_NAME=dall-e-2
# DEBUG_LEVEL=INFO
# DEBUG_JSON=true
# DEBUG_COLORS=true

#DEBUG_LEVEL=INFO
#DEBUG_JSON=true
#DEBUG_COLORS=true
# CI_REGISTRY_IMAGE=gitlab.example.com/user/chatgpt-mattermost-bot
# CI_COMMIT_REF_NAME=local
63 changes: 63 additions & 0 deletions .textlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// see: https://www.forcia.com/blog/002374.html
{
"plugins": {
"@textlint/markdown": {
"extensions": [".md"], // マークダウン用の拡張
}
},
"filters": {},
"rules": {
// https://github.com/textlint-rule/textlint-rule-prh
"prh": { // 文字揺れ校正 prhをプラグインで使う
"checkBlockQuote": true,
"checkEmphasis": true,
"rulePaths": ["./prh.yml"],
},
// textlint-rule-preset-jtf-styleの設定
"preset-jtf-style": {
"1.2.1.句点(。)と読点(、)": false, // 文中のピリオドとカンマを許容
//"1.1.3.箇条書き": false, // 箇条書きの文末に句点(。)以外を許可
//"2.1.8.算用数字": false, // 算用数字以外も許容する。1桁は全角でも入力できるように。
"2.2.1.ひらがなと漢字の使い分け": true, // ひらがなにしたほうが良い漢字をサジェスト
"4.1.3.ピリオド(.)、カンマ(,)": false, // 文中のピリオドとカンマを許容
"4.2.2.疑問符(?)": false, //半角:を許容
"4.2.7.コロン(:)": false, //半角:を許容
"4.3.1.丸かっこ()": false, // 半角丸括弧を許容
"4.3.2.大かっこ[]": false, // 半角大括弧を許容
},
// textlint-rule-preset-ja-technical-writingの設定
// https://github.com/textlint-ja/textlint-rule-preset-ja-technical-writing
"preset-ja-technical-writing": {
"no-exclamation-question-mark": {
// https://github.com/textlint-rule/textlint-rule-no-exclamation-question-mark
// "allow": ["Yahoo!"],
"allowHalfWidthExclamation": true,
"allowHalfWidthQuestion": true,
"allowFullWidthExclamation": true,
"allowFullWidthQuestion": true,
},
"no-doubled-joshi": {
"strict": false,
"allow": ["か", "が", "に"], // これらの助詞は同一文中に多く登場しても許容
},
"max-ten": { "max": 5 }, // 文中の「、」の数は5個まで
"sentence-length": false, // 文の長さは指定なし
"ja-no-weak-phrase": false, // 弱い表現を許容
"max-comma": false, // カンマの数は指定なし
},
// textlint-rule-preset-ja-spacingの設定
"preset-ja-spacing": {
"ja-space-around-code": { // インラインコードの前後にスペースを入れなくてもよい
"before": false,
"after": false,
},
},

// textlint init
"no-mixed-zenkaku-and-hankaku-alphabet": true,
//"preset-ja-spacing": true,
//"preset-ja-technical-writing": true,
//"preset-jtf-style": true,
//"prh": true
}
}
127 changes: 125 additions & 2 deletions chatgpt-mattermost-bot.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,134 @@
"path": "."
}
],
"settings": {},
"settings": {
"textlint.run": "onType"
},
"launch": {
"version": "0.2.0",
"configurations": [
{ // https://www.npmjs.com/package/tsx#debugging-method-1-run-tsx-directly-from-vscode
"name": "tsx - workspace",
"type": "node",
"request": "launch",
"envFile": "${workspaceFolder}/.env.debug",
//"envFile": "${workspaceFolder}/.env",
// Debug current file in VSCode
"program": "${workspaceFolder}/src/botservice.ts", //"${file}",
//"stopOnEntry": true,
/*
Path to tsx binary
Assuming locally installed
*/
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",
/*
Open terminal when debugging starts (Optional)
Useful to see console.logs
*/
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen", //デバッグ セッション中の [デバッグ コンソール] パネルの表示/非表示を制御
//"outputCapture": "std", //LogがDEBUG CONSOLEに出る
// Files to exclude from debugger (e.g. call stack)
"skipFiles": [
// Node.js internal core modules
"<node_internals>/**",
// Ignore all dependencies (optional)
"${workspaceFolder}/node_modules/**",
],
},
{ // https://www.npmjs.com/package/tsx#debugging-method-1-run-tsx-directly-from-vscode
"name": "tsx Cohere",
"type": "node",
"request": "launch",
"envFile": "${workspaceFolder}/.env.cohere.debug",
"program": "${workspaceFolder}/src/botservice.ts", //"${file}",
/*
Path to tsx binary
Assuming locally installed
*/
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",
/*
Open terminal when debugging starts (Optional)
Useful to see console.logs
*/
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen", //デバッグ セッション中の [デバッグ コンソール] パネルの表示/非表示を制御
"skipFiles": [
// Node.js internal core modules
"<node_internals>/**",
// Ignore all dependencies (optional)
"${workspaceFolder}/node_modules/**",
],
},
{
"name": "Launch via NPM", //自動的に出てるVSCODEのおすすめ
"request": "launch",
"envFile": "${workspaceFolder}/.env.debug",
"runtimeArgs": [
"run-script",
"debug"
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**",
// Ignore all dependencies (optional)
"${workspaceFolder}/node_modules/**",
],
"type": "node", //Logが出ない
"outputCapture": "std" //LogがDEBUG CONSOLEに出る。
},
{
"name": "Run npm start by env.debug",
"request": "launch",
"envFile": "${workspaceFolder}/.env.debug",
"command": "npm start",
"type": "node-terminal"
},
{
"name": "Run npm start by OpenAI",
"request": "launch",
"envFile": "${workspaceFolder}/.env.openai",
"command": "npm start",
"type": "node-terminal"
},
{
"name": "Run production by env.debug",
"request": "launch",
"envFile": "${workspaceFolder}/.env.debug",
"command": "npm run production",
"type": "node-terminal"
},
{
"name": "TypeScriptプログラムの起動 via NPM",
"request": "launch",
"runtimeArgs": [
"run",
"start"
],
"envFile": "${workspaceFolder}/.env.debug",
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"name": "Launch Program",
"program": "${workspaceFolder}/dist/botservice.mjs",
"envFile": "${workspaceFolder}/.env.debug",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
]
},
"extensions": {
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
"esbenp.prettier-vscode",
"taichi.vscode-textlint"
]
}
}
57 changes: 36 additions & 21 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
---
services:
chatbot:
image: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}
build: .
chatcpt:
image: ${CI_REGISTRY_IMAGE:-gitlab.example.com/user/chatgpt-mattermost-bot}:${CI_COMMIT_REF_NAME:+local}
build:
context: .
args:
NODE_ENV: ${NODE_ENV:-production}
restart: always
environment:
MATTERMOST_URL: ${MATTERMOST_URL}
MATTERMOST_TOKEN: ${MATTERMOST_TOKEN}
MATTERMOST_BOTNAME: ${MATTERMOST_BOTNAME}
OPENAI_API_KEY: ${OPENAI_API_KEY}
OPENAI_MODEL_NAME: ${OPENAI_MODEL_NAME}
OPENAI_IMAGE_MODEL_NAME: ${OPENAI_IMAGE_MODEL_NAME}
OPENAI_VISION_MODEL_NAME: ${OPENAI_VISION_MODEL_NAME}
OPENAI_MAX_TOKENS: ${OPENAI_MAX_TOKENS}
MAX_PROMPT_TOKENS: ${MAX_PROMPT_TOKENS}
PLUGINS: ${PLUGINS}
AZURE_OPENAI_API_KEY: ${AZURE_OPENAI_API_KEY}
AZURE_OPENAI_API_INSTANCE_NAME: ${AZURE_OPENAI_API_INSTANCE_NAME}
AZURE_OPENAI_API_DEPLOYMENT_NAME: ${AZURE_OPENAI_API_DEPLOYMENT_NAME}
AZURE_OPENAI_API_VERSION: ${AZURE_OPENAI_API_VERSION}
DEBUG_LEVEL: ${DEBUG_LEVEL}
DEBUG_JSON: ${DEBUG_JSON}
DEBUG_COLORS: ${DEBUG_COLORS}
env_file: .env # Dockerfileでも有効にするために必須
# .envファイルより環境変数を有効にする場合
# environment:
# MATTERMOST_URL: ${MATTERMOST_URL}
# MATTERMOST_TOKEN: ${MATTERMOST_TOKEN}
# MATTERMOST_BOTNAME: ${MATTERMOST_BOTNAME}
# OPENAI_API_KEY: ${OPENAI_API_KEY}
# OPENAI_MODEL_NAME: ${OPENAI_MODEL_NAME}
# OPENAI_IMAGE_MODEL_NAME: ${OPENAI_IMAGE_MODEL_NAME}
# OPENAI_VISION_MODEL_NAME: ${OPENAI_VISION_MODEL_NAME}
# OPENAI_MAX_TOKENS: ${OPENAI_MAX_TOKENS}
# MAX_PROMPT_TOKENS: ${MAX_PROMPT_TOKENS}
# PLUGINS: ${PLUGINS}
# AZURE_OPENAI_API_KEY: ${AZURE_OPENAI_API_KEY}
# AZURE_OPENAI_API_INSTANCE_NAME: ${AZURE_OPENAI_API_INSTANCE_NAME}
# AZURE_OPENAI_API_DEPLOYMENT_NAME: ${AZURE_OPENAI_API_DEPLOYMENT_NAME}
# AZURE_OPENAI_API_VERSION: ${AZURE_OPENAI_API_VERSION}
# DEBUG_LEVEL: ${DEBUG_LEVEL}
# DEBUG_JSON: ${DEBUG_JSON}
# DEBUG_COLORS: ${DEBUG_COLORS}

cohere:
image: ${CI_REGISTRY_IMAGE:-gitlab.example.com/user/chatgpt-mattermost-bot}:${CI_COMMIT_REF_NAME:+local}
build:
context: .
args:
NODE_ENV: ${NODE_ENV:-production}
restart: always
env_file: .env.cohere

Loading

0 comments on commit c2f8bc0

Please sign in to comment.