Skip to content

Commit e9298f9

Browse files
authored
Merge pull request #1 from masterismail/apibranch
Apibranch
2 parents 11e163b + 4dd355e commit e9298f9

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
2+
# More GitHub Actions for Azure: https://github.com/Azure/actions
3+
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions
4+
5+
name: Build and deploy Python app to Azure Web App - InterviewMate
6+
7+
on:
8+
push:
9+
branches:
10+
- apibranch
11+
workflow_dispatch:
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python version
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.10'
24+
25+
- name: Create and start virtual environment
26+
run: |
27+
python -m venv venv
28+
source venv/bin/activate
29+
30+
- name: Install dependencies
31+
run: pip install -r requirements.txt
32+
33+
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)
34+
35+
- name: Zip artifact for deployment
36+
run: zip release.zip ./* -r
37+
38+
- name: Upload artifact for deployment jobs
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: python-app
42+
path: |
43+
release.zip
44+
!venv/
45+
46+
deploy:
47+
runs-on: ubuntu-latest
48+
needs: build
49+
environment:
50+
name: 'Production'
51+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
52+
permissions:
53+
id-token: write #This is required for requesting the JWT
54+
55+
steps:
56+
- name: Download artifact from build job
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: python-app
60+
61+
- name: Unzip artifact for deployment
62+
run: unzip release.zip
63+
64+
65+
- name: Login to Azure
66+
uses: azure/login@v2
67+
with:
68+
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_5DF0714E93954EF4B0A77A75DFB1EF48 }}
69+
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_B187656150C84D549BC4E1445C91EE98 }}
70+
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_7D94DC64223541FEA49237FF5A201C3A }}
71+
72+
- name: 'Deploy to Azure Web App'
73+
uses: azure/webapps-deploy@v3
74+
id: deploy-to-webapp
75+
with:
76+
app-name: 'InterviewMate'
77+
slot-name: 'Production'
78+

my-api-app/app.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from flask import Flask, request, jsonify
2+
import os
3+
from openai import OpenAI
4+
5+
from dotenv import load_dotenv
6+
7+
# Load environment variables from .env file
8+
load_dotenv()
9+
10+
# Fetch the OpenAI API key from environment variables
11+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
12+
client = OpenAI(api_key=OPENAI_API_KEY)
13+
14+
if OPENAI_API_KEY is None:
15+
raise ValueError("The OpenAI API key is missing. Please set the OPENAI_API_KEY environment variable.")
16+
17+
# Set up OpenAI API key
18+
19+
app = Flask(__name__)
20+
21+
@app.route('/')
22+
def index():
23+
return "Welcome to the Poem Generator API. Use the /generate-poem endpoint to generate a poem."
24+
25+
@app.route('/generate-poem', methods=['POST'])
26+
def generate_poem():
27+
data = request.get_json()
28+
29+
if not data or 'prompt' not in data:
30+
return jsonify({'error': 'Invalid input'}), 400
31+
32+
prompt = data['prompt']
33+
34+
try:
35+
response = client.chat.completions.create(model="gpt-4",
36+
messages=[
37+
{"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
38+
{"role": "user", "content": prompt}
39+
])
40+
41+
return jsonify({
42+
'message': response.choices[0].message.content
43+
})
44+
45+
except Exception as e:
46+
return jsonify({'error': str(e)}), 500
47+
48+
if __name__ == '__main__':
49+
app.run(debug=True)

my-api-app/requirements.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
annotated-types==0.7.0
2+
anyio==4.4.0
3+
blinker==1.8.2
4+
certifi==2024.7.4
5+
click==8.1.7
6+
distro==1.9.0
7+
exceptiongroup==1.2.2
8+
Flask==3.0.3
9+
h11==0.14.0
10+
httpcore==1.0.5
11+
httpx==0.27.0
12+
idna==3.7
13+
itsdangerous==2.2.0
14+
Jinja2==3.1.4
15+
MarkupSafe==2.1.5
16+
openai==1.36.1
17+
pydantic==2.8.2
18+
pydantic_core==2.20.1
19+
python-dotenv==1.0.1
20+
sniffio==1.3.1
21+
tqdm==4.66.4
22+
typing_extensions==4.12.2
23+
Werkzeug==3.0.3

0 commit comments

Comments
 (0)