diff --git a/.github/workflows/azure-functions-app-python.yml b/.github/workflows/azure-functions-app-python.yml new file mode 100644 index 0000000..0ae9256 --- /dev/null +++ b/.github/workflows/azure-functions-app-python.yml @@ -0,0 +1,65 @@ +# This workflow will build a Python app and deploy it to an Azure Functions App on Linux when a commit is pushed to your default branch. +# +# This workflow assumes you have already created the target Azure Functions app. +# For instructions see https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python?pivots=python-mode-configuration +# +# To configure this workflow: +# 1. Set up the following secrets in your repository: +# - AZURE_FUNCTIONAPP_PUBLISH_PROFILE +# 2. Change env variables for your configuration. +# +# For more information on: +# - GitHub Actions for Azure: https://github.com/Azure/Actions +# - Azure Functions Action: https://github.com/Azure/functions-action +# - Publish Profile: https://github.com/Azure/functions-action#using-publish-profile-as-deployment-credential-recommended +# - Azure Service Principal for RBAC: https://github.com/Azure/functions-action#using-azure-service-principal-for-rbac-as-deployment-credential +# +# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples/tree/master/FunctionApp + +name: Deploy Python project to Azure Function App + +on: + push: + branches: ["main"] + +env: + AZURE_FUNCTIONAPP_NAME: 'UniqueLuisGithubFunction' # set this to your function app name on Azure + AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your function app project, defaults to the repository root + PYTHON_VERSION: '3.11' # set this to the python version to use (e.g. '3.6', '3.7', '3.8') + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + environment: dev + steps: + - name: 'Checkout GitHub Action' + uses: actions/checkout@v3 + + # If you want to use Azure RBAC instead of Publish Profile, then uncomment the task below + # - name: 'Login via Azure CLI' + # uses: azure/login@v1 + # with: + # creds: ${{ secrets.AZURE_RBAC_CREDENTIALS }} # set up AZURE_RBAC_CREDENTIALS secrets in your repository + + - name: Setup Python ${{ env.PYTHON_VERSION }} Environment + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: 'Resolve Project Dependencies Using Pip' + shell: bash + run: | + pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}' + python -m pip install --upgrade pip + pip install -r requirements.txt --target=".python_packages/lib/site-packages" + popd + + - name: 'Run Azure Functions Action' + uses: Azure/functions-action@v1 + id: fa + with: + app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }} + package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} + publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }} # Remove publish-profile to use Azure RBAC + scm-do-build-during-deployment: true + enable-oryx-build: true diff --git a/README.md b/README.md index debba4a..a83cd5f 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,10 @@ SMS Helper is an AI-powered, function-calling text assistant designed to process 2. Create required environment variables on your function. - `ACCOUNT_SID` - `AUTH_TOKEN` - - `TWIL_NUMBER` - - `TWIL_EXAMPLE_NUMBER` - `OPENAI_API_KEY` - `SENTRY_DSN` - ![Setting Env variables in Azure](images\azure_func_env_variables.png) + Setting Env variables in Azure 2. In VS Code, install the Azure Functions extension (this will make it way easier). Extension @@ -29,7 +27,7 @@ SMS Helper is an AI-powered, function-calling text assistant designed to process * **(Optional)** If using the 'schedule reminders' function, edit system message and API call to get the current time and date if you want something different than pacific time. 4. Go to the extension, and under 'Workspace' click on the little thunder sign and select 'Deploy to existing function...'. - ![Deploy](images\deploy.png) + Deploy 5. Follow the prompts and done. Get your URL endpoint from Azure & load on Twilio. @@ -40,7 +38,7 @@ SMS Helper is an AI-powered, function-calling text assistant designed to process 2. Go to Phone Numbers > Manage > Active Numbers > Your number > Messaging configuration. 3. Set when a message comes in to use a webhook with your Azure Function endpoint (see image below) - ![Twilio config](images\messaging_configuration.png) + Twilio config *Note: Your endpoint will look like this: `https://YOUR-FUNCTION-NAME.azurewebsites.net/api/sms_helper`* diff --git a/alternative_helper.py b/alternative_helper.py index 56cd312..71747c4 100644 --- a/alternative_helper.py +++ b/alternative_helper.py @@ -11,8 +11,6 @@ #------------------------------------# ACCOUNT_SID = os.environ["ACCOUNT_SID"] AUTH_TOKEN = os.environ["AUTH_TOKEN"] -TWIL_NUMBER = os.environ["TWIL_NUMBER"] -TWIL_EXAMPLE_NUMBER = os.environ["TWIL_EXAMPLE_NUMBER"] #------------------------------------# # OpenAI and Twilio Clients diff --git a/helper.py b/helper.py index a77641d..8ea8c18 100644 --- a/helper.py +++ b/helper.py @@ -11,8 +11,6 @@ #------------------------------------# ACCOUNT_SID = os.environ["ACCOUNT_SID"] AUTH_TOKEN = os.environ["AUTH_TOKEN"] -TWIL_NUMBER = os.environ["TWIL_NUMBER"] -TWIL_EXAMPLE_NUMBER = os.environ["TWIL_EXAMPLE_NUMBER"] #------------------------------------# # OpenAI and Twilio Clients diff --git a/sms-helper/__init__.py b/sms-helper/__init__.py index 9fb4f63..0a5fe13 100644 --- a/sms-helper/__init__.py +++ b/sms-helper/__init__.py @@ -16,8 +16,6 @@ # For initial testing capture 100% of transactions for monitoring traces_sample_rate=1.0, ) -ACCOUNT_SID = os.environ["ACCOUNT_SID"] - #------------------------------------# # Main function @@ -48,4 +46,4 @@ def main(req: func.HttpRequest) -> func.HttpResponse: send_to, send_from, incoming_message) - return func.HttpResponse(response_for_user, status_code=200) \ No newline at end of file + return func.HttpResponse(response_for_user, status_code=200)