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

fix typo and add whitelist endpoint #161

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ __pycache__
**/.env
**/files/*
**/testing*
**/dist/
**/dist/
**/env
3 changes: 3 additions & 0 deletions src/apps/slackapp/slackapp/bolt_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:

Expand Down
26 changes: 26 additions & 0 deletions src/apps/slackapp/slackapp/routes/whitelist.py
Original file line number Diff line number Diff line change
@@ -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})
2 changes: 1 addition & 1 deletion src/sherpa_ai/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)


Expand Down