This Azure function connects the SMS gateway with Azure Cognitive Services and Azure Cosmos DB to interface with ChatGPT. The function is triggered by incoming Service Bus messages and sends SMS messages to the user based on the response from ChatGPT. Conversations are stored in Cosmos DB.
- Azure subscription
- Azure Service Bus namespace with ingress and egress queues
- Azure Cosmos DB account with a NoSQL database and a container
- Azure Cognitive Services account with a deployed Chatmodel
- Azure Functions app
- Node.js 20 and npm
- Azure Functions Core Tools
- Azure CLI
- Clone the repository.
git clone https://github.com/GuppyAI/Azure-Functions.git cd Azure-Functions - Install the dependencies.
npm install
- Create a
local.settings.jsonfile in the root directory of the project with the following content:Replace the placeholders with the appropriate values.{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "<connection_string>", "FUNCTIONS_WORKER_RUNTIME": "node", "AzureWebJobsFeatureFlags": "EnableWorkerIndexing", "INGRESS_QUEUE": "<ingress_queue>", "EGRESS_QUEUE": "<egress_queue>", "SERVICEBUS_CONNECTION_INGRESS": "<connection_string>", "SERVICEBUS_CONNECTION_EGRESS": "<connection_string>", "COSMOSDB_CONNECTION": "<connection_string>", "COSMOSDB_DATABASE": "<database>", "COSMOSDB_CONTAINER": "<container>", "OPENAI_ENDPOINT": "<endpoint>", "OPENAI_KEY": "<key>", "OPENAI_VERSION": "<version>", "OPENAI_DEPLOYMENT": "<deployment_id>", "OPENAI_SYSTEM_PROMPT": "You are a helpful assistant that helps people with their tasks. You are very friendly and always willing to help. You are a good listener and always try to help people solve their problems. You are a good friend.", "OPENAI_MAX_TOKENS": 50, "RESET_MESSAGE": "<Chat has been reset>\n\nHi I'm Guppy-AI how can I help you today?" } }
- Run the function locally.
func start
- Send a message to the ingress queue to trigger the function.
The message needs a custom property
addressthis acts as the unique identifier for the user. The function will respond with a message to the egress queue.
- Deploy the function to Azure.
func azure functionapp publish <function_app_name>
- Ensure the function app has the necessary environment variables set in the Azure portal.
All tests are written using Jest and can be run locally without any azure resources. To run the tests, use the following command:
npm run testThe function is set up with GitHub Actions workflows to test and build the function on every push. On every push to the main branch, a GitHub Release is created with the build function and the function is deployed to Azure. The workflows can be configured with the following environment variables:
- APP_NAME (Azure Function App name) and the following secrets:
- AZURE_CREDENTIALS (Azure Service Principal credentials)
GuppyAI SMS-Gateway (c) 2024 Kay Knöpfle and contributors
SPDX-License-Identifier: GPL-3.0