Skip to content

Commit

Permalink
Merge pull request #48 from chriswebb09/dev-branch
Browse files Browse the repository at this point in the history
Dev branch
  • Loading branch information
chriswebb09 authored Dec 14, 2023
2 parents e027271 + c071750 commit b0d4600
Show file tree
Hide file tree
Showing 58 changed files with 2,062 additions and 586 deletions.
1 change: 1 addition & 0 deletions DirectReport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
from .browserview import *
from .models import *
from .tests import *
from .datadependencies import *

__version__ = "1.0.0"
2 changes: 0 additions & 2 deletions DirectReport/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

from DirectReport.commandline import commandline


def main():
commandline.cli()


if __name__ == "__main__":
main()
196 changes: 41 additions & 155 deletions DirectReport/browserview/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
#!/usr/bin/env python3
import flask
# Flask
from flask import Flask, render_template, request, redirect, jsonify, json, url_for
from werkzeug.security import generate_password_hash, check_password_hash
from DirectReport.models.user_model import User, UserModel

from flask import Flask, render_template, request, redirect, json, url_for
from werkzeug.security import generate_password_hash
from DirectReport.models.user_model import UserModel
from DirectReport.models.list_builder import ListBuilder
from DirectReport.models.report_model import ReportModel
from DirectReport.models.report_builder import ReportBuilder
from DirectReport.models.report import Report
from DirectReport.browserview.prompt_logic import generate_email
from DirectReport.browserview.github import GithubClient
from DirectReport.browserview.github import GoogleAIClient
from DirectReport.browserview.github import HuggingFaceClient
from flask_login import LoginManager, login_user, login_required, logout_user, current_user
# OpenAI
import openai
import appsecrets
import prompts
from DirectReport.datadependencies import appsecrets
from .auth.auth import auth
from .reportbp import reportsbp
from .modelclient import TEST_DATA_ELEMENTS
from .modelclient import RAW_REPORT_DATA
from .modelclient import RAW_REPORT_DATA_2

import sys
from pathlib import Path

file = Path(__file__).resolve()
package_root_directory = file.parents[1]
sys.path.append(str(package_root_directory))

openai.api_key = appsecrets.SECRET_KEY
login_manager = LoginManager()
app = Flask(__name__, template_folder="templates")
app.register_blueprint(auth)
app.register_blueprint(reportsbp)
app.secret_key = appsecrets.SECRET_KEY
login_manager.init_app(app)
login_manager.login_view = "login"
Expand All @@ -36,179 +53,48 @@ def page_not_found(e):
"""
return render_template('404.html', error=e), 404

@app.route('/signup')
def signup():
return render_template('signup.html')

@app.route('/signup', methods=['POST'])
def signup_post():
# code to validate and add user to database goes here
email = request.form.get('email')
name = request.form.get('name')
passwordtext = request.form.get('password')
password = generate_password_hash(passwordtext)
user_model.insert_user(name, email, password)
return redirect(url_for('login'))

@app.route('/login', methods=['POST', 'GET'])
def login():
email = request.form.get('email')
password = request.form.get('password')
# remember = True if request.form.get('remember') else False
user = user_loader(email)
if request.method == 'POST':
login_user(user, remember=True, force=True)
if current_user.is_authenticated():
return redirect(url_for('account'))
return render_template('login.html')

@app.route('/logout')
@login_required
def logout():
logout_user()
return redirect(url_for('team_report'))

@login_manager.user_loader
def user_loader(email):
user = user_model.get_user_by_email(email)
return user


@login_manager.request_loader
def request_loader(request):
email = request.form.get('email')
user = user_model.get_user_by_email(email)
return user

@app.route("/account", methods=['GET', 'POST'])
@app.route("/new", methods=['GET', 'POST'])
@login_required
def account():
print(current_user.is_authenticated())
return render_template('account.html', title='Account', name=current_user.username, userid=current_user.id)
def new():
"""
Retrieves and renders the list of all entries.
:return: Rendered HTML template for the list page.
"""
return render_template('list.html', title='New Entry', data=[])

@login_manager.unauthorized_handler
def unauthorized_handler():
print("unauthorized_handler")
if request.headers.get("X-Requested-With") == "XMLHttpRequest":
return redirect(url_for('login'))
return redirect(url_for('auth.login'))
else:
if current_user.is_authenticated:
return redirect(url_for('account'))
return redirect(url_for('auth.account'))
else:
return redirect(url_for('login'))
return redirect(url_for('auth.login'))

@app.route("/teamreport", methods=['GET', 'POST'])
def team_report():
if request.method == "POST":
print("POST")
return render_template('teamreport.html', title='Team Report', data=[])

@app.route("/report", methods=['GET', 'POST'])
def report():
prompt = ""
if request.method == "POST":
prompt = request.get_json()["prompt"]
# print(prompt)
# elements = {
# "team": [
# {
# "name": "AdrianPrantl",
# "accomplishments": "AdrianmadesignificantcontributionstotheDebugInfoandSILGen,includingaddingsupportfordebuginfoforcoroutineallocas,inlinedandspecializedgenericvariables.Healsoworkedonthemanglingtestcase,fixedsourcelocationsofvariableassignmentsandfunctioncalls,andaddedbuild-scriptsupportforSwiftLLDBbackwards-compatibilitytests.",
# "commits": "67"
# },
# {
# "name": "AhmadAlhashemi",
# "accomplishments": "AhmadworkedontheParser,detectingnonbreakingspaceU+00A0andprovidingafix.Healsomademinorstyleeditsandaddedmorenon-breakingspacetestcases.",
# "commits": "5"
# },
# {
# "name": "AkshayShrimali",
# "accomplishments": "AkshayupdatedtheREADME.mdfile.",
# "commits": "1"
# },
# {
# "name": "AlanZeino",
# "accomplishments": "AlanfixedatypointhecodeexampleinlibSyntaxREADME.",
# "commits": "1"
# },
# {
# "name": "Albin\"albinek\"Sadowski",
# "accomplishments": "AlbinfixedsyntaxhighlightinginCHANGELOG.",
# "commits": "1"
# },
# {
# "name": "Alejandro",
# "accomplishments": "Alejandroremovedawarning,madesomedocumentationfixes,fixedBinaryFloatingPoint.random(in:)openrangereturningupperBound,andfixedaminorcodetypoinSILPro..Man..md.",
# "commits": "3"
# },
# {
# "name": "AlexBlewitt",
# "accomplishments": "Alexworkedonseveralfixesincludingcompareforlhsandrhs,using||insteadof&&forkindcomparison,removingduplicateconditionalcheckandduplicateifstatement.",
# "commits": "5"
# }
# ],
# "report": {
# "summary": "Theteammadesignificantprogressthisweekwithatotalof83commits.ThemainfocuswasonDebugInfoandSILGenenhancements,Parserimprovements,andvariousfixes.",
# "highlights": [
# {
# "title": "DebugInfoandSILGenEnhancements",
# "description": "AdrianPrantlmadesignificantcontributionstotheDebugInfoandSILGen,includingaddingsupportfordebuginfoforcoroutineallocas,inlinedandspecializedgenericvariables."
# },
# {
# "title": "ParserImprovements",
# "description": "AhmadAlhashemiworkedontheParser,detectingnonbreakingspaceU+00A0andprovidingafix."
# },
# {
# "title": "VariousFixes",
# "description": "Theteamworkedonseveralfixesincludingcompareforlhsandrhs,using||insteadof&&forkindcomparison,removingduplicateconditionalcheckandduplicateifstatement."
# }
# ],
# "conclusion": "Theteamdemonstratedgoodprogressthisweek,withafocusonenhancingDebugInfoandSILGen,improvingtheParser,andimplementingvariousfixes.Theteamshouldcontinuetofocusontheseareasinthecomingweek."
# }
# }
elements = {}
if prompt is not "":
report = get_team_summarys_from_git_shortlog(prompt)
elements = report.choices[0].message.content
elements = elements.replace("'", '"')
elements = elements.replace('"albinek"', '')
json_object = json.loads(elements)
return elements, 201
@app.route("/team", methods=['GET'])
def team():
return render_template('team.html', title='Team', data=[])

@app.route("/generate_email", methods=['POST'])
def generate_email():
prompt = ""
if request.method == "POST":
prompt = json.dumps(request.get_json()["prompt"])
print(prompt)
report = generate_email(prompt)
elements = {"email": report.choices[0].message.content}
return elements, 201

def get_team_summarys_from_git_shortlog(data):
prompt = prompts.GENERATE_SUMMARY_PROMPT_PREIX + data
message=[{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model="gpt-4",
messages = message,
temperature=0.1,
max_tokens=1000,
frequency_penalty=0.0
)
return response

def generate_email(data):
prompt = prompts.GENERATE_EMAIL_PROMPT_PREFIX + data
message=[{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model="gpt-4",
messages = message,
temperature=0.1,
max_tokens=1000,
frequency_penalty=0.0
)
return response


if __name__ == "__main__":
app.run()
app.run(debug=True, port=5000)
File renamed without changes.
84 changes: 84 additions & 0 deletions DirectReport/browserview/auth/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env python3

from flask import render_template, request, redirect, url_for, flash
from flask import Blueprint
from werkzeug.security import generate_password_hash
from DirectReport.models.user_model import UserModel
from flask_login import login_user, login_required, logout_user, current_user
from DirectReport.browserview import app
from DirectReport.models.report_builder import ReportBuilder
from DirectReport.browserview.github import GithubClient

auth = Blueprint('auth', __name__)

user_model = UserModel()

@auth.route('/signup', methods=['POST', 'GET'])
def signup():
if request.method == 'POST':
# code to validate and add user to database goes here
email = request.form.get('email')
username = request.form.get('username')
firstname = request.form.get('firstname')
lastname = request.form.get('lastname')
password_text = request.form.get('password')
password = generate_password_hash(password_text)
user_model.insert_user(email, username, firstname, lastname, email, password)
return redirect(url_for('auth.login'))
return render_template('auth/signup.html')

@auth.route('/logout')
@login_required
def logout():
logout_user()
return redirect(url_for('reportsbp.team_report'))

@auth.route('/login', methods=['POST', 'GET'])
def login():
if request.method == 'POST':
email = request.form.get('email')
password = request.form.get('password')
remember = True if request.form.get('remember') else False
user = app.user_loader(email)
if user.check_password(password):
login_user(user, remember=remember, force=True)
if current_user.is_authenticated():
return redirect(url_for('auth.account'))
else:
print("password no match")
flash("Please check your login details and try again.")
return render_template('auth/login.html')

@auth.route("/account", methods=['GET', 'POST'])
@login_required
def account():
return render_template('account.html', title='Account', name=current_user.username, userid=current_user.id)

@auth.route("/account_data", methods=['GET'])
@login_required
def account_data():
saved_reports = ReportBuilder.get_reports_for_user_id(current_user.id)
logitem = "Adrian Prantl (67):\n add mangling testcase\n Debug Info: Represent private discriminators in DWARF.\n Revert Debug Info: Represent private discriminators in DWARF.\"\n Debug Info: Represent private discriminators in DWARF.\n Un-XFAIL and update test.\n Move the logic for ignoring the debug locations for closure setup code into SILGen. NFC-ish.\n Debug Info: Associate a function call with the beginning of the expression.\n Debug Info / SILGen: fix the source location of variable assignments\n typo\n Fix the debug locations of inserted operations in AvailableValueAggregator.\n Don't emit shadow copies for anonymous variables.\n Remove dead API IRGenDebugInfo::setArtificialTrapLocation().\n Use compiler-generated location for func.-sig.-spec. thunks\n whitespace\n Fix the missing inlined-at field of function-level SILDebugScopes.\n Add debug info support for inlined and specialized generic variables.\n Revert Add debug info support for inlined and specialized generic variables.\"\n Add debug info support for inlined and specialized generic variables.\n Update mangling prefix in Mangling.rst\n Add initial support for debug info for coroutine allocas.\n Temporarily disable failing test case, rdar://problem/43340064\n Add build-script support for the Swift LLDB backwards-compatibility tests.\n Remove accidentally committed debugging code\n Deserialize Swift compatibility version in CompilerInvocation::loadFromSerializedAST()\n SILGen: Preserve function argument debug info for arguments needing alloc_stack\n Use as the filename for SILLocation-less functions to avoid misleading source locatio\nns in backtraces.\n Add a -verify-linetable LLVM option.\n Enable debug info for inlined generics by default. It works now.\n Fix nonasserts compilation\n\nAhmad Alhashemi (5):\n [Parser] Detect nonbreaking space U+00A0 and fixit\n Move non-breaking space handling to lexUnknown\n Add more non-breaking space test cases\n Minor style edits\n Add tests for non-breaking space detect and fix-it\n\nAkshay Shrimali (1):\n Update README.md\n\nAlan Zeino (1):\n Fix typo in code example in libSyntax README\n\nAlbin Sadowski (1):\n Fix syntax highlighting in CHANGELOG (#15107)\n\nAlejandro (3):\n Remove a warning, some doc fixes (#16863)\n [SR-8178] Fix BinaryFloatingPoint.random(in:) open range returning upperBound (#17794)\n [Docs] Fix minor code typo in SILPro..Man..md\n\nAlex Blewitt (5):\n [SR-7032] Fix compare for lhs and rhs\n [SR-7036] Use || instead of && for kind comparison\n [SR-7041] Remove duplicate conditional check\n Remove duplicate verb\n [SR-7043] Remove duplicate if statement"
client = GithubClient()
shortlog = client.parse_git_shortlog(logitem)
report_results = []
for report in saved_reports:
report_element = {
"report": report
}
report_results.append(report_element)

user_account = {
"name": current_user.firstname + " " + current_user.lastname,
"firstname": current_user.firstname,
"lastname": current_user.lastname,
"userid": current_user.id,
"username": current_user.username,
"email": current_user.email
}
user_element = {
"user": user_account,
"reports": report_results,
"shortlog": shortlog
}
return user_element, 201
File renamed without changes.
Loading

0 comments on commit b0d4600

Please sign in to comment.