From 8de342d30b5960ecef044eb11985ff0fa2cc49c3 Mon Sep 17 00:00:00 2001 From: Alvin Bellero Date: Sat, 28 Sep 2024 15:34:00 +0800 Subject: [PATCH] feat(extension): add systemMessage param and other openAI models --- firestore-chatgpt-bot/CHANGELOG.md | 11 +++++++++- firestore-chatgpt-bot/extension.yaml | 21 ++++++++++++++++++- firestore-chatgpt-bot/functions/src/index.ts | 3 ++- .../functions/src/utils/config.ts | 2 ++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/firestore-chatgpt-bot/CHANGELOG.md b/firestore-chatgpt-bot/CHANGELOG.md index baa79e5..f886253 100644 --- a/firestore-chatgpt-bot/CHANGELOG.md +++ b/firestore-chatgpt-bot/CHANGELOG.md @@ -10,4 +10,13 @@ ## Version 0.0.3 -- Added new `GPT-4o` to the `MODEL` options. [Learn more here.](https://platform.openai.com/docs/models/gpt-4o) \ No newline at end of file +- Added new `GPT-4o` to the `MODEL` options. [Learn more here.](https://platform.openai.com/docs/models/gpt-4o) + +## Version 0.1.0 + +- Added `systemMessage` to configurable paramaters. +- Included (4) language models to the `MODEL` option. [Learn more here.](https://platform.openai.com/docs/models) + - GPT-4o mini `GPT-4o mini` + - o1-preview `o1-preview` + - o1-mini `o1-mini` + - GPT-4 Turbo `gpt-4-turbo` \ No newline at end of file diff --git a/firestore-chatgpt-bot/extension.yaml b/firestore-chatgpt-bot/extension.yaml index c24b1e1..d2e11a5 100644 --- a/firestore-chatgpt-bot/extension.yaml +++ b/firestore-chatgpt-bot/extension.yaml @@ -1,5 +1,5 @@ name: firestore-chatgpt-bot -version: 0.0.3 # Follow semver versioning +version: 0.1.0 # Follow semver versioning specVersion: v1beta # Version of the Firebase Extensions specification displayName: Chatbot with ChatGPT @@ -113,6 +113,15 @@ params: required: true immutable: false + - param: SYSTEM_MESSAGE + label: System Message + description: >- + The default message that acts as an instruction for the model, ensuring it responds appropriately to the your queries. + type: string + example: You're an AI language model developed by OpenAI. Provide the user with clear and helpful assistance. + required: false + immutable: false + - param: LOCATION label: Cloud Functions Location description: >- @@ -174,8 +183,18 @@ params: options: - label: GPT-4o value: gpt-4o + - label: GPT-4o mini + value: gpt-4o-mini + - label: o1-preview + value: o1-preview + - label: o1-mini + value: o1-mini + - label: GPT-4 Turbo + value: gpt-4-turbo - label: GPT-4 Turbo Preview value: gpt-4-turbo-preview + - label: GPT-4 0125 Preview + value: gpt-4-0125-preview - label: GPT-4 1106 Preview value: gpt-4-1106-preview - label: GPT-4 diff --git a/firestore-chatgpt-bot/functions/src/index.ts b/firestore-chatgpt-bot/functions/src/index.ts index 7c9b30d..6dd5a5e 100644 --- a/firestore-chatgpt-bot/functions/src/index.ts +++ b/firestore-chatgpt-bot/functions/src/index.ts @@ -12,6 +12,7 @@ const { apiKey, promptField, responseField, + systemMessage, collectionName, parentMessageIdField, } = config; @@ -20,7 +21,7 @@ const { const completionParams = logs.initialize(config); // ChatGPT API Initialization -const chatgpt = new ChatGPTAPI({ apiKey, completionParams }); +const chatgpt = new ChatGPTAPI({ apiKey, completionParams, ...(systemMessage ? { systemMessage } : {}) }); /** * This is triggered whenever a document in the specified ${param:COLLECTION_NAME} is written. diff --git a/firestore-chatgpt-bot/functions/src/utils/config.ts b/firestore-chatgpt-bot/functions/src/utils/config.ts index 98402f0..9757db9 100644 --- a/firestore-chatgpt-bot/functions/src/utils/config.ts +++ b/firestore-chatgpt-bot/functions/src/utils/config.ts @@ -4,6 +4,7 @@ export interface Config { model: string; promptField: string; responseField: string; + systemMessage: string; collectionName: string; temperature?: number; topP?: number; @@ -22,6 +23,7 @@ const config: Config = { model: process.env.MODEL || "gpt-3.5-turbo", promptField: process.env.PROMPT_FIELD || "prompt", responseField: process.env.RESPONSE_FIELD || "response", + systemMessage: process.env.SYSTEM_MESSAGE || undefined, collectionName: process.env.COLLECTION_NAME || "users/{userID}/messages", temperature: process.env.TEMPERATURE ? parseFloat(process.env.TEMPERATURE)