diff --git a/src/.gitignore b/src/.gitignore index 405a2a37..07073e09 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -2,4 +2,5 @@ __pycache__ **/.env **/files/* **/testing* -**/dist/ \ No newline at end of file +**/dist/ +**/env \ No newline at end of file diff --git a/src/apps/slackapp/slackapp/bolt_app.py b/src/apps/slackapp/slackapp/bolt_app.py index 73bbb66c..9f51d7ef 100644 --- a/src/apps/slackapp/slackapp/bolt_app.py +++ b/src/apps/slackapp/slackapp/bolt_app.py @@ -21,6 +21,7 @@ from sherpa_ai.utils import count_string_tokens, log_formatter, show_commands_only from sherpa_ai.verbose_loggers import DummyVerboseLogger, SlackVerboseLogger from sherpa_ai.verbose_loggers.base import BaseVerboseLogger +from slackapp.routes.whitelist import whitelist_blueprint ####################################################################################### # Set up Slack client and Chroma database @@ -215,6 +216,8 @@ def update_home_tab(client, event): ########################################################################### flask_app = Flask(__name__) handler = SlackRequestHandler(app) +flask_app.register_blueprint(whitelist_blueprint, url_prefix='/auth') + if cfg.FLASK_DEBUG: diff --git a/src/apps/slackapp/slackapp/routes/whitelist.py b/src/apps/slackapp/slackapp/routes/whitelist.py new file mode 100644 index 00000000..d0c06fe1 --- /dev/null +++ b/src/apps/slackapp/slackapp/routes/whitelist.py @@ -0,0 +1,26 @@ +from flask import Blueprint, jsonify, request + +from sherpa_ai.database.user_usage_tracker import UserUsageTracker + +whitelist_blueprint = Blueprint('auth', __name__) + + +@whitelist_blueprint.route('/add', methods=['POST']) +def add_to_whitelist(): + data = request.get_json() + user_id = data.get('user_id') + + db = UserUsageTracker() + if user_id: + db.add_to_whitelist(user_id) + return jsonify({'message': f'User {user_id} added to whitelist.'}), 201 + else: + return jsonify({'error': 'User ID not provided.'}), 400 + + +@whitelist_blueprint.route('/', methods=['GET']) +def get_all_whitelists(): + db = UserUsageTracker() + + data = db.get_all_whitelisted_ids() + return jsonify({'whitelisted_ids': data}) diff --git a/src/sherpa_ai/config.py b/src/sherpa_ai/config.py index fd16daf9..cc2022d9 100644 --- a/src/sherpa_ai/config.py +++ b/src/sherpa_ai/config.py @@ -48,7 +48,7 @@ TEMPRATURE = environ.get("TEMPRATURE") or 0 DAILY_LIMIT_REACHED_MESSAGE = ( environ.get("DAILY_LIMIT_REACHED_MESSAGE") - or "I for the inconvenience, but it seems that you have exceeded your daily token limit. As a result, you will need to try again after 24 hours. Thank you for your understanding." + or "Sorry for the inconvenience, but it seems that you have exceeded your daily token limit. As a result, you will need to try again after 24 hours. Thank you for your understanding." )