diff --git a/.github/workflows/main_volucy-gateway.yml b/.github/workflows/main_volucy-gateway.yml index 57d008f1..e33366c4 100644 --- a/.github/workflows/main_volucy-gateway.yml +++ b/.github/workflows/main_volucy-gateway.yml @@ -66,6 +66,9 @@ jobs: - name: Unzip artifact for deployment run: unzip release.zip + - name: Set environment variable for Flask + run: echo "FLASK_ENV=production" >> $GITHUB_ENV + - name: 'Deploy to Azure Web App' uses: azure/webapps-deploy@v2 id: deploy-to-webapp diff --git a/main.py b/main.py index e87d0839..d4afbdc6 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,4 @@ -# pip install Flask requests -# pip install openai +# pip install Flask requests gunicorn from flask import Flask, request, jsonify import requests @@ -7,7 +6,6 @@ import openai openai.api_key = "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" - app = Flask(__name__) # Define the routes for the gateway @@ -30,7 +28,7 @@ def gpt4_proxy(): data = request.json prompt = data.get('prompt', '') model = 'gpt-4' - response = openai.chat.completions.create( + response = openai.ChatCompletion.create( messages=[ { "role": "user", @@ -41,6 +39,8 @@ def gpt4_proxy(): ) return jsonify({'response': response.choices[0].message.content.strip()}) - if __name__ == '__main__': app.run(host='0.0.0.0', port=8000) + +# start with: gunicorn -w 4 -b 0.0.0.0:8000 app:app +# export FLASK_ENV=production \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 295c998c..9ecd9896 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,6 @@ django-cors-headers djangorestframework whitenoise openai +Flask requests -flask \ No newline at end of file +gunicorn \ No newline at end of file