Skip to content

Commit

Permalink
Merge pull request #73 from zacowan/feat/round-robin-1-release
Browse files Browse the repository at this point in the history
Feat/round robin 1 release
  • Loading branch information
zacowan authored Nov 8, 2021
2 parents c4328a3 + afb19c7 commit 5683447
Show file tree
Hide file tree
Showing 79 changed files with 15,424 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
service_key_file.json
.vscode
.project
.pydevproject
__pycache__/
.DS_Store
andy_response.mp3
andy_response.wav
shelve/
stockfish_engine/
UCI_engine/
19 changes: 19 additions & 0 deletions andy_api/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
google-cloud-dialogflow = "==2.9.0"
Flask = "==2.0.1"
google-cloud-speech = "==2.9.1"
google-cloud-storage = "==1.42.3"
flask-cors = "*"
google-cloud-texttospeech = "==2.6.0"
chess = "==1.7.0"
google-cloud-firestore = "==2.3.4"

[dev-packages]

[requires]
python_version = "3.9"
563 changes: 563 additions & 0 deletions andy_api/Pipfile.lock

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions andy_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Andy API

This API will be used to communicate with Andy.

## Getting Started

### Getting Python Set Up

1. Make sure you have Python version 3.9 installed.
2. Install pipenv by following the instructions [here](https://github.com/pypa/pipenv).
3. Inside of the project directory, run `pipenv install`. This will install the required packages specified in `Pipfile`.

### Give the Proper Permissions to the Run Script

> Note: this section assumes a Mac/Linux environment. For windows instructions, do the equivalent actions.
1. Run `chmod +x run_dev.sh` to get the right privledges for using a script to run the app.

### Getting Google Cloud SDK Set Up

Follow the instructions for setting up the Google Cloud SDK locally on your computer here: https://cloud.google.com/sdk/docs/install.

### Getting the Account Service Key Set Up

Getting access to the Dialogflow API requries the use of a service account. To access a service account from our application, we need to set an environment variable with the **secret** key associated with the service account.

> For access to the key, check Discord. For detailed instructions on setting the key, see https://cloud.google.com/docs/authentication/production#passing_variable.
1. Make sure you have completed (Getting Google Cloud SDK Set Up)[#getting-google-cloud-sdk-set-up].
2. Make sure you have a key for the service account. Name it `service_key_file.json` and make sure it is somewhere easily accessible (like the root directory of this project). You will need to know the **absolute** path of the key file. Make sure that this file is correctly hidden by the `.gitignore`.
3. Update the path of the key file using the `ABSOLUTE_PATH_TO_KEY` variable in `run_YOUR_NAME.sh`.
4. Run the command `gcloud auth activate-service-account --key-file=ABSOLUTE_PATH_TO_KEY_FILE` using the **absolute** path of the key file (the same one set in `run.sh`).

## Running the App

1. Make sure you have completed [Getting Started](#getting-started).
2. To open a shell for the python virtual environment, run `pipenv shell` inside of the project directory.
3. While in the python virtual environment, run `sh run_YOUR_NAME.sh` to run a script that starts the app.
4. To stop the app, use `ctrl + c`. To exit the virtual environment, type `exit`.

> Note: for a shortcut command that runs the python virtual environment shell and runs the scripts, run `pipenv run sh run_YOUR_NAME.sh`.
38 changes: 38 additions & 0 deletions andy_api/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Initialization of flask app.
This module serves the purpose of initializing the flask application.
"""
from pathlib import Path
from flask import Flask
from flask_cors import CORS
from . import api_routes
from .state_manager import SHELVE_DIRECTORY


def create_app(test_config=None):
# Create shelve directory
Path(SHELVE_DIRECTORY).mkdir(parents=True, exist_ok=True)
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
CORS(app, resources={r"/*": {"origins": "*"}})
app.config.from_mapping(
SECRET_KEY="dev",
)

if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile("config.py", silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)

# Display the routes available
@app.route("/")
def health_check():
return "Successfully running api!"

# Register the API blueprint
app.register_blueprint(api_routes.bp)

return app
65 changes: 65 additions & 0 deletions andy_api/api/api_route_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Helper functions for api_routes to use.
"""

from .state_manager import get_fulfillment_params, get_game_state
from .intent_processing import error_fulfillment


TTS_ERROR_AUDIO_FILENAME = "./static_audio/tts-error.wav"


def get_static_error_audio():
"""Returns the data of a static audio file for TTS errors.
Returns:
bytes: the raw bytes of the audio file.
"""
# Read the audio file
data = None
with open(TTS_ERROR_AUDIO_FILENAME, "rb") as f:
data = f.read()

return data


def get_response_error_return(session_id, board_str):
"""Returns a generic error response.
Args:
board_str: FEN representation of board from client.
Returns:
A dictionary that should be returned for the get-response route using jsonify().
{
'response_text': str,
'board_str': str
'fulfillment_info': dict
}
response_text (str): the response generated by Andy, as text.
fulfillment_info (dict): the intent information detected from the user
and the game state.
{
'intent_name': str,
'success': boolean
}
intent_name (str): the name of the detected intent (always ERROR).
success (boolean): always False for an error.
board_str (str): the state of the board, as a FEN string.
"""
# Get error fulfillment information
response_text, fulfillment_info = error_fulfillment.get_error_fulfillment()

return {
"response_text": response_text,
"fulfillment_info": fulfillment_info,
'fulfillment_params': get_fulfillment_params(session_id),
"board_str": board_str,
'game_state': get_game_state(session_id)
}
Loading

0 comments on commit 5683447

Please sign in to comment.