Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nimbus v1.0 #112

Draft
wants to merge 383 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
383 commits
Select commit Hold shift + click to select a range
734779a
create yaml utilities
mfekadu Feb 28, 2020
dff98fb
Create settings.yml_SAMPLE
mfekadu Feb 28, 2020
47a0f1f
automate local commands with invoke
mfekadu Feb 28, 2020
7c239d5
Dockerfile that auto-generates secret files
mfekadu Feb 28, 2020
cb95b3a
Create test_new_data_courses_endpoint.py
mfekadu Feb 28, 2020
0f0661e
noticed test failure & fixed
mfekadu Feb 28, 2020
9fda969
still passing but now with printouts
mfekadu Feb 28, 2020
9979137
Create test_new_data_clubs_endpoint.py
mfekadu Feb 28, 2020
4c50a2b
Merge pull request #73 from calpoly-csai/get-entity-property
cameron-toy Feb 28, 2020
1554b08
Merge pull request #80 from calpoly-csai/mf-patch-and-test
cameron-toy Feb 28, 2020
f4f71cf
reinserted NIMBUS_NLP.py
chidiewenike Feb 28, 2020
45e35e8
added modified NIMBUS_NLP.py
chidiewenike Feb 28, 2020
d94b173
Merge branch 'dev' into nimbus-nlp
chidiewenike Feb 28, 2020
0a7e7b3
added modified NIMBUS_NLP.py
chidiewenike Feb 28, 2020
02fe6db
Merge pull request #78 from calpoly-csai/nimbus-nlp
chidiewenike Feb 28, 2020
c1f41d1
working ask endpoint
cameron-toy Feb 28, 2020
ffd3d98
working ask endpoint
cameron-toy Feb 28, 2020
b5bde14
Merge pull request #81 from calpoly-csai/cameron_t
cameron-toy Feb 28, 2020
f6c8bd2
changed fuzzy-wuzzy to fuzzywuzzy
cameron-toy Feb 28, 2020
581c607
Create test_new_data_wakeword_endpoint.py
mfekadu Feb 29, 2020
824ffda
Create happy.wav
mfekadu Feb 29, 2020
abbfdd2
add more tests
mfekadu Feb 29, 2020
62e97a9
Update requirements.txt
mfekadu Feb 29, 2020
3a27169
fix #77
mfekadu Feb 29, 2020
4528f22
Update Clubs.py
mfekadu Feb 29, 2020
389a274
Merge pull request #83 from calpoly-csai/mf-patch-and-test
mfekadu Feb 29, 2020
89d8a63
Update requirements.txt
mfekadu Feb 29, 2020
f16a7eb
wakey wakey Heroku Dynos
snekiam Feb 29, 2020
a7b590b
Generic save_entity method
Jason-Ku Feb 28, 2020
125f8ba
Remove save_audio_sample_meta_data
Jason-Ku Feb 29, 2020
6c7c45a
Fix for scikit-learn version and nimbus_nlp model imports
adamperlin Feb 29, 2020
317642a
Merge pull request #84 from calpoly-csai/fixes
mfekadu Feb 29, 2020
9e025d8
Fix gunicorn_config to be compatible with Heroku virtualization
snekiam Feb 29, 2020
f7a6561
Updated gunicorn config to be compatible with Heroku
snekiam Feb 29, 2020
4045a8a
Merge pull request #85 from calpoly-csai/snekiam-gunicorn-config
mfekadu Feb 29, 2020
37d2610
mvp
cameron-toy Feb 29, 2020
c57791a
Merge pull request #86 from calpoly-csai/cameron_t
cameron-toy Feb 29, 2020
3ac68aa
nl -> nltk
cameron-toy Feb 29, 2020
dc39220
downloads stopwords corpus
cameron-toy Feb 29, 2020
0d17a9f
nlp stuff
mfekadu Feb 29, 2020
ad3c989
this requirement is handled by ./download_nlp_stuff
mfekadu Feb 29, 2020
0c69303
Merge pull request #87 from calpoly-csai/cameron_t
mfekadu Feb 29, 2020
8106013
Merge pull request #74 from calpoly-csai/calendars
mfekadu Feb 29, 2020
51bc8cd
Update .gitignore
mfekadu Feb 29, 2020
3e88490
This should be OK to delete since we have nimbus_nlp
snekiam Mar 1, 2020
580061a
Merge branch 'dev' of https://github.com/calpoly-csai/api into dev
cameron-toy Mar 1, 2020
40bb9f3
Update NLP scripts and question_classifier code
Mar 1, 2020
c23d8a9
Merge pull request #92 from calpoly-csai/snekiam
mfekadu Mar 1, 2020
cde2527
Merge pull request #93 from calpoly-csai/snekiam-delete-dead-code
mfekadu Mar 1, 2020
7e042ff
remove old models
mfekadu Mar 1, 2020
629c037
pip3
mfekadu Mar 1, 2020
69b7dc6
This fixes the segfaults on Ubuntu and Debian. The import does
Mar 1, 2020
8214be8
no threads needed
mfekadu Mar 1, 2020
1afc248
Update deploy.sh
mfekadu Mar 1, 2020
483fe03
Update requirements.txt
mfekadu Mar 1, 2020
cf13c50
pipenv!!
mfekadu Mar 1, 2020
345f1ca
Update tasks.py
mfekadu Mar 1, 2020
a1617df
Merge pull request #95 from calpoly-csai/mf-pipenv
snekiam Mar 1, 2020
ef02ea4
Merge branch 'dev' of https://github.com/calpoly-csai/api into dev
cameron-toy Mar 1, 2020
03bd1b5
Split save_entity into insert_entity and update_entity
Jason-Ku Mar 1, 2020
a6feedf
Updated comment on phantom import.
Mar 1, 2020
be77f70
Merge pull request #94 from calpoly-csai/snekiam
snekiam Mar 1, 2020
1799f9c
Merge pull request #96 from calpoly-csai/calendars
mfekadu Mar 1, 2020
99cdf07
Remove extra print statement
Jason-Ku Mar 1, 2020
862fb54
Create cases.py
taylor-nguyen-987 Mar 2, 2020
4dfd45c
Merge pull request #97 from calpoly-csai/camel_to_snake_case_attempt
taylor-nguyen-987 Mar 2, 2020
3f190f6
dockerfile works with ubuntu
mfekadu Mar 2, 2020
f55a926
Merge pull request #98 from calpoly-csai/mf-pipenv
mfekadu Mar 2, 2020
3420182
hopefully resolves permissionError with six on heroku
mfekadu Mar 2, 2020
30f939c
Merge pull request #99 from calpoly-csai/mf-pipenv
mfekadu Mar 2, 2020
dfbb567
a working heroku deploy even if workflow fails
mfekadu Mar 2, 2020
dc5076d
refactor the dockerfile to direct download
mfekadu Mar 2, 2020
1d9c805
well I hope this resolves #100
mfekadu Mar 2, 2020
122ff4d
Update Dockerfile for #100
mfekadu Mar 2, 2020
a9c087a
#100 th times the charm
mfekadu Mar 2, 2020
48336b0
#100 verbose dockerfile, reduce six/idna versions
mfekadu Mar 2, 2020
4eb1f80
ensures people dont reference #9 on accident
mfekadu Mar 2, 2020
c6fbbe2
install the dev-dependencies
mfekadu Mar 9, 2020
95fdd28
Merge pull request #115 from calpoly-csai/mfekadu-patch-pytest
Jason-Ku Mar 12, 2020
bd46fb5
Remove raw_data_dict reference, add some tests
Jason-Ku Mar 8, 2020
ccd94b5
Merge pull request #114 from calpoly-csai/calendars
Jason-Ku Mar 14, 2020
715e6e2
Get code coverage up
Jason-Ku Mar 22, 2020
35b8876
Merge pull request #118 from calpoly-csai/calendars
Jason-Ku Mar 24, 2020
57f726f
Create coverage.sh
mfekadu Mar 25, 2020
df611f1
pipenv install --dev coverage
mfekadu Mar 25, 2020
ea8d4da
Merge pull request #104 from calpoly-csai/mf-fix-pr-template
mfekadu Mar 26, 2020
7e24774
Merge pull request #119 from calpoly-csai/mf-coverage
mfekadu Mar 27, 2020
9a0592a
added the OfficeHours entity schema
chidiewenike Mar 29, 2020
1c09edb
Added the ability to save new phrases from csai-recorder to the sql s…
Mar 31, 2020
c93f586
Added and tested Miles' feedback
Apr 1, 2020
0429608
added office_hours_post_request.py which reads in the office hours cs…
chidiewenike Apr 1, 2020
5bfa253
added office_hours_post_request.py which reads in the office hours cs…
chidiewenike Apr 1, 2020
11a8fdc
Merge pull request #121 from calpoly-csai/submit-query-phrases
snekiam Apr 2, 2020
0647903
-Created FeedbackValidator, FeedbackValidatorError, FeedbackValidator…
thegooman Apr 5, 2020
f45ba23
Merge branch 'dev' into chidiewenike-add-office-hours
chidiewenike Apr 6, 2020
63117cc
Merge pull request #120 from calpoly-csai/chidiewenike-add-office-hours
chidiewenike Apr 7, 2020
a4fcdf9
added answerable question query function
richagadgil Apr 12, 2020
24154d8
replace csvs in nlp model w api
richagadgil Apr 12, 2020
9eab5de
clean up
richagadgil Apr 12, 2020
c121ab7
Feedback pipeline completed
Apr 12, 2020
10e8aa7
Fix scraper APIs
austinsilveria Apr 19, 2020
3d7a0a5
Made feedback issues mutually exlusive in fix loop
Apr 19, 2020
0334238
Merge pull request #134 from calpoly-csai/feedback-data-pipeline
snekiam Apr 19, 2020
e16ab03
fixed comment and trained latest model
richagadgil Apr 21, 2020
5d4bfad
performance, dependency removal, multivariable questions
cameron-toy Apr 24, 2020
8142fb9
formatting
cameron-toy Apr 24, 2020
c25c6e5
Merge pull request #136 from calpoly-csai/multivar
chidiewenike Apr 24, 2020
fa48492
Update Dockerfile
snekiam Apr 24, 2020
dcb7825
Merge pull request #137 from calpoly-csai/snekiam-patch-1
snekiam Apr 25, 2020
9948a79
Merge pull request #135 from calpoly-csai/scraperUpdate
Jason-Ku Apr 26, 2020
58fe85b
Merge branch 'dev' into standardize_qa_pairs
richagadgil Apr 26, 2020
f6ef4cb
Merge pull request #131 from calpoly-csai/standardize_qa_pairs
richagadgil Apr 26, 2020
f9b9490
remove question set csv
richagadgil Apr 26, 2020
ba74189
retrained model; global variable fixes in flask_api.py
cameron-toy Apr 27, 2020
802d1dd
Update database_wrapper.py
Jason-Ku May 3, 2020
656f3b5
Merge pull request #140 from calpoly-csai/ctbuxfixes
cameron-toy May 3, 2020
aded41b
Revert "retrained model; global variable fixes in flask_api.py"
mfekadu May 3, 2020
9841c0c
Merge pull request #142 from calpoly-csai/revert-140-ctbuxfixes
Jason-Ku May 3, 2020
7114884
undo redo
cameron-toy May 3, 2020
6a8e428
Merge pull request #143 from calpoly-csai/ctbugfixes3
cameron-toy May 3, 2020
395c9d6
initial flask_api tests and fix some bugs
Jason-Ku Apr 26, 2020
b642a7b
support for list properties
cameron-toy May 4, 2020
e3a8465
Merge pull request #138 from calpoly-csai/jason
chidiewenike May 4, 2020
a8f151a
lets not have 80 commits
snekiam May 10, 2020
af360f2
Merge branch 'dev' into dev
snekiam May 10, 2020
54b4b7f
Flask app new wakeword data endpoint tests
Jason-Ku May 10, 2020
be01d52
Added gce deploy script.
snekiam May 10, 2020
ac5802a
Fix typo in dockerfile, update config and git commit message.
snekiam May 10, 2020
ad7687d
Merge pull request #146 from snekiam/dev
snekiam May 11, 2020
cc91cbd
Merge pull request #147 from calpoly-csai/jason
Jason-Ku May 13, 2020
0a6c550
AudioMetadata lives again!!!!
May 15, 2020
3f17ea7
added fields to tests
May 16, 2020
30ae749
fixed misplaced quote
May 16, 2020
6a1a520
updated first two tests to reflect the new wake word upload
May 16, 2020
3badb76
Update README.md
snekiam May 17, 2020
94eaada
Merge branch 'dev' into listprops
cameron-toy May 17, 2020
d329427
Merge pull request #144 from calpoly-csai/listprops
cameron-toy May 17, 2020
6531966
Tested validation in the WakeWordValidator
May 17, 2020
b1efede
Update README.md
snekiam May 17, 2020
cf128e5
Merge pull request #149 from calpoly-csai/snekiam-readme-update
mfekadu May 17, 2020
35762df
Merge pull request #148 from calpoly-csai/resurrecting-audio-metadata
Waidhoferj May 17, 2020
dfba15b
Merge branch 'dev' of https://github.com/calpoly-csai/api into dev
richagadgil May 17, 2020
d79444e
remove old code
richagadgil May 17, 2020
34b7027
Added SonarCloud project badges
thegooman May 17, 2020
e321930
Bump httplib2 from 0.17.0 to 0.18.0
dependabot[bot] May 20, 2020
aee7c6f
Merge pull request #153 from calpoly-csai/remove_old_code
richagadgil May 24, 2020
ad90605
nlp model fixes to remove wh word
richagadgil May 24, 2020
e697d94
lint fixes
richagadgil May 24, 2020
f399463
Merge pull request #155 from calpoly-csai/fix_nlp_model
snekiam May 24, 2020
c2d4bdb
Merge init_db and init_nimbus and add pre-ping
Jason-Ku May 24, 2020
c156564
Merge pull request #157 from calpoly-csai/jason
snekiam May 24, 2020
9d68b57
correct sklearn model
richagadgil May 24, 2020
bd1c844
Merge pull request #158 from calpoly-csai/fix_nlp_model
mfekadu May 24, 2020
8e2a5a5
make simple & colorful script for build
mfekadu May 27, 2020
5ab8fe8
comment scripts
mfekadu May 27, 2020
2c6eb9c
remove dead code
mfekadu May 27, 2020
781716d
whoops, that could've been a bug
mfekadu May 27, 2020
3d8984d
a cleaner 'running...' printout
mfekadu May 27, 2020
265057d
comments && a --no-overwrite-secrets flag
mfekadu May 27, 2020
5934437
specify certificate files config in Dockerfile only
mfekadu May 27, 2020
222257d
make sure root route always return SUCCESS for health check
mfekadu May 27, 2020
9ea2828
oops almost forgot colorama
mfekadu May 27, 2020
71c2175
delete dead scripts
mfekadu May 27, 2020
2d1f641
make sure deploy just ONLY that. DEPLOY.
mfekadu May 27, 2020
ff43530
format & include GET THE `en_core_web_sm` SPACY MODEL
mfekadu May 27, 2020
76ca44b
fix typo
mfekadu May 27, 2020
06074b8
gce should choose SSL_PORT without affecting local machine choice of …
mfekadu May 27, 2020
fb4884a
yaml naml calpoly-csai/nimbus-config-secrets@ac8fcb6
mfekadu May 27, 2020
87a14d0
Update .gitignore
mfekadu May 27, 2020
56a2843
resolve failing test
mfekadu May 28, 2020
687a4e1
make executable
mfekadu May 28, 2020
5b32a62
en_core_web_sm
mfekadu May 28, 2020
d97d51c
Merge pull request #160 from calpoly-csai/mf-script-cleanup
mfekadu May 28, 2020
a03f71a
database migration
cameron-toy May 28, 2020
0d290f6
Merge branch 'dev' of https://github.com/calpoly-csai/api into dev
cameron-toy May 28, 2020
ff05408
database migration 2
cameron-toy May 28, 2020
9ef2e16
updated test
cameron-toy May 28, 2020
49075a9
deleted models
cameron-toy May 28, 2020
02c8ea7
updated gitignore to ignore pickle files
cameron-toy May 28, 2020
5c8e75f
re-added classification directory in nimbus-nlp/models
cameron-toy May 28, 2020
cb5384d
change joblib version
richagadgil May 28, 2020
e324445
see what is being loaded
richagadgil May 28, 2020
569177b
changed script to find pkl file
richagadgil May 28, 2020
ddad890
Merge pull request #162 from calpoly-csai/database_migration
snekiam May 28, 2020
bdacdf0
Added error handler for OperationalErrors.
snekiam May 28, 2020
6e57518
Merge branch 'dev' of github.com:calpoly-csai/api into dev
snekiam May 28, 2020
7033513
fix spacy
richagadgil May 28, 2020
05071ae
Merge pull request #163 from calpoly-csai/branch_rgadgil
snekiam May 28, 2020
ab5b994
Merge branch 'dev' of github.com:calpoly-csai/api into snekiam
snekiam May 29, 2020
afe7500
Merge pull request #151 from calpoly-csai/readme-updates
Jason-Ku May 29, 2020
de9b7fc
Added question logging
May 31, 2020
d6a99d8
Update flask_api.py
Waidhoferj May 31, 2020
256ee72
Update .gitignore
mfekadu May 31, 2020
93454a0
updates build.py quiet by def, spacy small
mfekadu May 31, 2020
2e60ce0
Update overall_features.json
mfekadu May 31, 2020
97676f1
Merge pull request #170 from calpoly-csai/log-questions-reborn
mfekadu May 31, 2020
fbb22c2
Pull out EXPECTED_KEYS_BY_ENTITY and update tests
Jason-Ku May 31, 2020
0057581
Merge pull request #168 from calpoly-csai/snekiam
snekiam May 31, 2020
2c1b4c2
updates build.py to emphasize behavior
mfekadu Jun 1, 2020
de6dcbc
Entity Token Endpoints
Jun 6, 2020
ca7b6e7
handles errors inside add_entity
Jun 7, 2020
d8365ff
Merge pull request #175 from calpoly-csai/entity-identifiers-endpoint
Jason-Ku Jun 14, 2020
9b2fd03
Merge pull request #154 from calpoly-csai/dependabot/pip/httplib2-0.18.0
snekiam Jun 14, 2020
408fc9a
Added REST hooks for validator app to update and delete QAPairs
Jun 15, 2020
5459762
Merge pull request #176 from calpoly-csai/update-delete-questionanswe…
Waidhoferj Jun 15, 2020
f2b2312
Merge branch 'dev' into jason
Jason-Ku Jun 20, 2020
2634506
Merge pull request #172 from calpoly-csai/jason
Jason-Ku Jun 20, 2020
bf51860
Created GET route for unvalidated QA pairs (#178)
thegooman Jul 8, 2020
6990c3b
Update dev environment instructions and other small improvements
snekiam Jul 19, 2020
f83c729
Merge pull request #180 from calpoly-csai/snekiam-readme-updates
snekiam Jul 19, 2020
b5b1aab
fixed index issue
chidiewenike Jul 19, 2020
719ca8b
Added Setup info to README
ethanahlquist Jul 20, 2020
d8bc234
Added setup info to README
ethanahlquist Jul 20, 2020
5818955
Merge pull request #184 from calpoly-csai/ethanahlquist-readme-updates
snekiam Jul 22, 2020
96d91ea
First issue 182 commit
ethanahlquist Jul 22, 2020
83c32f2
Merge pull request #183 from calpoly-csai/chidiewenike
chidiewenike Jul 24, 2020
998cecc
Second Commit, additions of code catching answer responce errors. (al…
ethanahlquist Jul 26, 2020
16218b0
Flask catchall is functional!😀 Just need database changes!👌
ethanahlquist Jul 26, 2020
3b31a53
Flask catchall is functional!👌 Just need database changes!
ethanahlquist Jul 26, 2020
bb76bde
Update README.md
snekiam Jul 26, 2020
be9efda
Created endpoint for fetching entity information for use in autocompl…
masonmcelvain Jul 26, 2020
9d02536
Updated synonyms and prop names
masonmcelvain Jul 29, 2020
ed702aa
After Database change:
ethanahlquist Jul 31, 2020
42011db
Database Errorlogging is functional 👍
ethanahlquist Jul 31, 2020
fb6af17
Merge pull request #185 from calpoly-csai/snekiam-readme-update-1
snekiam Aug 1, 2020
56b3fb3
Merge pull request #186 from calpoly-csai/iss182_catchall_logger
ethanahlquist Aug 2, 2020
43e64bb
Quick TypeError fix in NLP 👍
ethanahlquist Aug 2, 2020
0c6dc51
Merge pull request #187 from calpoly-csai/ethanQuickFix
ethanahlquist Aug 2, 2020
0da44b4
Cast google-container type → list, Removed try-except in flask_api
ethanahlquist Aug 2, 2020
2f9315b
Cast google-container type → list, Removed try-except in flask_api
ethanahlquist Aug 2, 2020
cf08cec
skeleton of entity synonyms retrieval
masonmcelvain Aug 2, 2020
ccc93e8
Updated workflow to use secret, cron now outputs reasonably
snekiam Aug 9, 2020
f2e6a7d
Merge pull request #191 from calpoly-csai/ssl_cert_updates
snekiam Aug 9, 2020
ce80333
Updated to work properly with SSH cert. Moved scripts to certs direct…
snekiam Aug 9, 2020
927963c
Merge pull request #192 from calpoly-csai/ssl_cert_updates
snekiam Aug 9, 2020
4bf555f
made some scripts executable, because git made them not executable wh…
Aug 9, 2020
14d6ec9
Update git url
snekiam Aug 10, 2020
6fa36d3
Merge pull request #189 from calpoly-csai/ethanQuickFix
ethanahlquist Aug 11, 2020
05122b1
Synonyms in place for locations and profs
masonmcelvain Aug 12, 2020
5a9426a
remove bad import
masonmcelvain Aug 12, 2020
fc6aaed
Merge pull request #194 from calpoly-csai/get-entity-structure
masonmcelvain Aug 16, 2020
875a16b
Merge pull request #193 from calpoly-csai/ssl_cert_updates
snekiam Aug 16, 2020
36fb2d7
Handle InvalidRequestErrors by re-initializing the database session.
snekiam Aug 23, 2020
671064f
Merge pull request #196 from calpoly-csai/InvalidRequestErrorHandling
snekiam Aug 23, 2020
74341b6
Empty string answers now return None 👍
ethanahlquist Sep 13, 2020
334467c
Updates to error handling.
snekiam Sep 15, 2020
ba143f7
Merge pull request #199 from calpoly-csai/iss198_Empty_Answers
Jason-Ku Sep 15, 2020
9961396
Merge pull request #200 from calpoly-csai/error_handling_updates
snekiam Sep 16, 2020
a7e75b9
Delete annoying print statement
masonmcelvain Oct 11, 2020
947ed36
Merge pull request #201 from calpoly-csai/remove-unnecessary-print
masonmcelvain Oct 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updates to error handling.
Added question to error handler.
Added get_question method to get the current question from the request object.
Initiate a rollback for all exceptions, since we don't know what has succeeded/failed, and we could be in a bad state.
  • Loading branch information
snekiam authored and GCE_GIT_BOT committed Sep 15, 2020
commit 334467c858fa439ccddc2ee6765ed04b2eaceb27
55 changes: 36 additions & 19 deletions flask_api.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
from sqlalchemy.exc import OperationalError, InvalidRequestError

from flask import Flask, jsonify, request
from werkzeug.exceptions import BadRequest

# traceback added for stacktrace logging
import traceback
@@ -93,15 +94,29 @@ def init_nimbus_db():
nimbus = Nimbus(db)


# returns the question from the request body, if applicable
def get_question() -> str:
if request.is_json is False:
raise BadRequest(description="request must be JSON")
request_body = request.get_json()
question = request_body.get("question", None)
# no reason for a custom exception here
if question is None:
raise BadRequest(description="request body should include the question")
else:
return question


def handle_database_error(error):
global db
if db is None:
# reinit the database
init_nimbus_db()
else:
# checks if the session has any changes (new objects, changed objects,
# or deleted objects) - these should be rolled back in the case of an exception
if db.session.new or db.session.dirty or db.session.deleted:
print("Rolling back")
db.session.rollback()
if isinstance(error, OperationalError) or db is None:
# we *probably* have a bad session - try and roll it back,
# then create a new database connection.
db.session.rollback()
db.session.close()
db = None
init_nimbus_db()
@@ -114,10 +129,16 @@ def log_error(error, question):

@app.errorhandler(Exception)
def handle_all_errors(e):
# InvalidRequestError happens when the transaction is broken
if isinstance(e, OperationalError) or isinstance(e, InvalidRequestError):
handle_database_error(e)
log_error(e, None)
# we should still be able to extract the question from the request, if one
# was asked. We can retry the question once.
handle_database_error(e)
question = None
try:
question = get_question()
except BadRequest as e:
# the question is already None, but we need to catch this exception
pass
log_error(e, question)
return jsonify({"ErrorLog": type(e).__name__}), SUCCESS


@@ -151,23 +172,19 @@ def handle_question():

init_nimbus_db()

if request.is_json is False:
return "request must be JSON", BAD_REQUEST

request_body = request.get_json()

question = request_body.get("question", None)

if "question" not in request_body:
return "request body should include the question", BAD_REQUEST
try:
question = get_question()
except (BadRequest) as e:
return e.description, BAD_REQUEST

try:
entity = db.insert_entity(QuestionLog, {"question": question})
except (Exception) as e:
print("Could not store question upon user ask: ", str(e))

response = {"answer": nimbus.answer_question(question)}

# extracting the question checks if we have json, so we should be good here
request_body = request.get_json()
if "session" in request_body:
response["session"] = request_body["session"]
else: