-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from masterismail/apibranch
Apibranch
- Loading branch information
Showing
3 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy | ||
# More GitHub Actions for Azure: https://github.com/Azure/actions | ||
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions | ||
|
||
name: Build and deploy Python app to Azure Web App - InterviewMate | ||
|
||
on: | ||
push: | ||
branches: | ||
- apibranch | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python version | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Create and start virtual environment | ||
run: | | ||
python -m venv venv | ||
source venv/bin/activate | ||
- name: Install dependencies | ||
run: pip install -r requirements.txt | ||
|
||
# Optional: Add step to run tests here (PyTest, Django test suites, etc.) | ||
|
||
- name: Zip artifact for deployment | ||
run: zip release.zip ./* -r | ||
|
||
- name: Upload artifact for deployment jobs | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: python-app | ||
path: | | ||
release.zip | ||
!venv/ | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
environment: | ||
name: 'Production' | ||
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | ||
permissions: | ||
id-token: write #This is required for requesting the JWT | ||
|
||
steps: | ||
- name: Download artifact from build job | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: python-app | ||
|
||
- name: Unzip artifact for deployment | ||
run: unzip release.zip | ||
|
||
|
||
- name: Login to Azure | ||
uses: azure/login@v2 | ||
with: | ||
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_5DF0714E93954EF4B0A77A75DFB1EF48 }} | ||
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_B187656150C84D549BC4E1445C91EE98 }} | ||
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_7D94DC64223541FEA49237FF5A201C3A }} | ||
|
||
- name: 'Deploy to Azure Web App' | ||
uses: azure/webapps-deploy@v3 | ||
id: deploy-to-webapp | ||
with: | ||
app-name: 'InterviewMate' | ||
slot-name: 'Production' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from flask import Flask, request, jsonify | ||
import os | ||
from openai import OpenAI | ||
|
||
from dotenv import load_dotenv | ||
|
||
# Load environment variables from .env file | ||
load_dotenv() | ||
|
||
# Fetch the OpenAI API key from environment variables | ||
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | ||
client = OpenAI(api_key=OPENAI_API_KEY) | ||
|
||
if OPENAI_API_KEY is None: | ||
raise ValueError("The OpenAI API key is missing. Please set the OPENAI_API_KEY environment variable.") | ||
|
||
# Set up OpenAI API key | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/') | ||
def index(): | ||
return "Welcome to the Poem Generator API. Use the /generate-poem endpoint to generate a poem." | ||
|
||
@app.route('/generate-poem', methods=['POST']) | ||
def generate_poem(): | ||
data = request.get_json() | ||
|
||
if not data or 'prompt' not in data: | ||
return jsonify({'error': 'Invalid input'}), 400 | ||
|
||
prompt = data['prompt'] | ||
|
||
try: | ||
response = client.chat.completions.create(model="gpt-4", | ||
messages=[ | ||
{"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."}, | ||
{"role": "user", "content": prompt} | ||
]) | ||
|
||
return jsonify({ | ||
'message': response.choices[0].message.content | ||
}) | ||
|
||
except Exception as e: | ||
return jsonify({'error': str(e)}), 500 | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
annotated-types==0.7.0 | ||
anyio==4.4.0 | ||
blinker==1.8.2 | ||
certifi==2024.7.4 | ||
click==8.1.7 | ||
distro==1.9.0 | ||
exceptiongroup==1.2.2 | ||
Flask==3.0.3 | ||
h11==0.14.0 | ||
httpcore==1.0.5 | ||
httpx==0.27.0 | ||
idna==3.7 | ||
itsdangerous==2.2.0 | ||
Jinja2==3.1.4 | ||
MarkupSafe==2.1.5 | ||
openai==1.36.1 | ||
pydantic==2.8.2 | ||
pydantic_core==2.20.1 | ||
python-dotenv==1.0.1 | ||
sniffio==1.3.1 | ||
tqdm==4.66.4 | ||
typing_extensions==4.12.2 | ||
Werkzeug==3.0.3 |