Skip to content

Commit

Permalink
🚀 feat: Add support for integration with Google Gemini API
Browse files Browse the repository at this point in the history
    Added support for Google Gemini API by updating environment variables, README, adding a new GoogleGeminiAdapter class, and adjusting existing code. This enables the use of Google's latest AI models to provide more diverse responses and functionalities.

    🚀 feat(Dockerfile, eslint.config.js, package.json): Support ESLint V9
    Added an ESLint configuration file `eslint.config.js` and included a step in the Dockerfile to copy this file.
    Also, removed the unnecessary `--ext ts` option from the `lint` script in `package.json` and streamlined dependencies. These changes aim to maintain consistency in the code and make it easier for developers to uphold code quality.

    🔥 remove(.eslintrc.json): Remove old ESLint configuration file from the project
    To simplify the project setup and reduce maintenance efforts, the old ESLint configuration file has been removed. This opens up opportunities to explore alternative ways to maintain code quality.

    🚚 change(Dockerfile): Remove reference to .eslintrc.json from Dockerfile
    Following the removal of the ESLint configuration file from the project, its reference has been removed from the Dockerfile. This updates the build process and avoids copying unnecessary files.

    🔥 refactor(AIProvider.ts): Improve code for safely accessing inputTokens and outputTokens in NonStreamedChatResponse
    Previously, the implementation used the `any` type to access `inputTokens` and `outputTokens`, which was not type-safe. The new implementation uses optional chaining and the nullish coalescing operator to safely access these values, defaulting to -1 if they are not present. This enhances the readability and safety of the code.

    📦 package update(package.json): updated versions of dependencies and devDependencies
    Updating the versions of dependencies and devDependencies to their latest ensures that security vulnerabilities are addressed and the latest features are available. Notably, versions of "@anthropic-ai/sdk", "openai", "@swc/core", "@types/node", "@typescript-eslint/eslint-plugin", "@typescript-eslint/parser", "eslint", "tsx", and "typescript" have been updated, which is expected to improve performance and resolve compatibility issues.
     @anthropic-ai/sdk                   ^0.19.0  →   ^0.20.2
     @swc/core                           ^1.4.11  →   ^1.4.13
     @types/node                       ^20.11.30  →  ^20.12.6
     @typescript-eslint/eslint-plugin     ^7.4.0  →    ^7.6.0
     @typescript-eslint/parser            ^7.4.0  →    ^7.6.0
     eslint                              ^8.57.0  →    ^9.0.0
     openai                              ^4.29.2  →   ^4.33.0
     tsx                                  ^4.7.1  →    ^4.7.2
     typescript                           ^5.4.3  →    ^5.4.4
  • Loading branch information
takuya-o committed Apr 13, 2024
1 parent c2f8bc0 commit a7d3848
Show file tree
Hide file tree
Showing 14 changed files with 1,023 additions and 1,172 deletions.
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
// 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以下が必要
// 新しいイメージを持ってきたらsudo -E "apt update && apt install git-secrets connect-proxy"や~/.ssh/configが必要
// 鍵についてはssh-add -l で確認
// 環境変数http_proxyや~/.gitconfigは、コンテナ作成時の値が自動的に登録されている。
10 changes: 10 additions & 0 deletions .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ OPENAI_API_KEY=sk-234234234234234234
# AZURE_OPENAI_VISION_API_INSTANCE_NAME=example-name
# AZURE_OPENAI_VISION_API_DEPLOYMENT_NAME=gpt-4-vision-preview

# COHERE_API_KEY=abcdefghijklmnopqrstuvw
# OPENAI_MODEL_NAME=command-r-plus
# MAX_PROMPT_TOKENS=123904
# OPENAI_MAX_TOKENS=4000

# GOOGLE_API_KEY=abcdefghijklmnopqrstuvw
# OPENAI_MODEL_NAME=gemini-1.5-pro-latest
# MAX_PROMPT_TOKENS=1048576
# OPENAI_MAX_TOKENS=8192

# DEBUG_LEVEL=INFO
# DEBUG_JSON=true
# DEBUG_COLORS=true
Expand Down
63 changes: 0 additions & 63 deletions .eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ FROM node:20-slim as npm_builder

WORKDIR /app
COPY [ "package.json", "package-lock.json", ".npmrc", \
".eslintrc.json", ".prettierignore", ".prettierrc", \
".prettierignore", ".prettierrc", \
"tsconfig.json", \
"eslint.config.js", \
"esbuild.config.js", \
"./" ]
COPY [ "src/", "./src/" ]
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Enhanced from the [original yGuy/chatgpt-mattermost-bot](https://github.com/yGuy/chatgpt-mattermost-bot)

* Expimental support Cohere Command R+ and Google Gemini 1.5 Pro API. Text chat only.
* Support GPT-4V Vision API
+ Realization of multimodal text and images in conjunction with image plugins. **Limitation**: The plugins are not possible in threads that have been image attached, Under the 1106 gpt-4-vision-vewview.
![The screenshot depicts a fictional chat in Mattermost where a user asks a bot to describe a zoo scene, and to create an image that evokes positive emotions; the bot responds with a colorful zoo illustration and a vivid sunset beach scene.](./mattermost-gpt4v.png)
Expand Down Expand Up @@ -45,7 +46,7 @@ or when [running the docker image](#using-the-ready-made-docker-image) or when c
| 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_API_BASE | no | `http://example.com:8080/v1` | The address of an OpenAI compatible API. Overrides the default base path (`https://api.openai.com`) |
| OPENAI_MODEL_NAME | no | `gpt-3.5-turbo` | The OpenAI language model to use, defaults to `gpt-3.5-turbo` |
| OPENAI_MODEL_NAME | no | `gpt-3.5-turbo` | The OpenAI or Cohere 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_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. |
| MAX_PROMPT_TOKENS | no | `2096` | Maximum number of prompt tokens, default to 2000. For example on GPT-4 = 8196 - OPENAI_MAX_TOKENS. |
Expand All @@ -61,6 +62,8 @@ or when [running the docker image](#using-the-ready-made-docker-image) or when c
| AZURE_OPENAI_API_IMAGE_KEY | no | `0123456789abcdefghijklmno` | The Azure OpenAI Service API key to authoenticate. If this is set, Azure OpenAI is used for image generation. |
| AZURE_OPENAI_API_IMAGE_INSTANCE_NAME | no | `example-name` | The instance name on the Azure OpenAI Service for Image API if specially needed |
| AZURE_OPENAI_API_IMAGE_DEPLOYMENT_NAME | no | `Dalle3` | The name of the deployed model on the Azure OpenAI Service for Iamge API if specially needed. DALL-E 3 require 2023-12-01-preview API Version at least |
| COHERE_API_KEY | no | `0123456789abcdefghijklmno` | The Cohere API key to authoenticate. If OPENAI_API_KEY is also set, the original OpenAI is used for vision or image generation. |
| GOGGLE_API_KEY | no | `0123456789abcdefghijklmno` | The Gemini API key to authoenticate. If OPENAI_API_KEY is also set, the original OpenAI is used for vision or image generation. Tested model is only 'gemini-1.5-pro-latest' |
| 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' |
Expand Down
24 changes: 24 additions & 0 deletions chatgpt-mattermost-bot.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@
"${workspaceFolder}/node_modules/**",
],
},
{ // https://www.npmjs.com/package/tsx#debugging-method-1-run-tsx-directly-from-vscode
"name": "tsx Gemini",
"type": "node",
"request": "launch",
"envFile": "${workspaceFolder}/.env.gemini.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",
Expand Down
8 changes: 8 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ services:
restart: always
env_file: .env.cohere

gemini:
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.gemini
Loading

0 comments on commit a7d3848

Please sign in to comment.