repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | from flask import Blueprint, jsonify, make_response, request |
| #2 | from models import APIKey, BotList, db |
| #3 | |
| #4 | dashboard_bp = Blueprint("dashboard", __name__) |
| #5 | |
| #6 | |
| #7 | # Set Open AI Key |
| #8 | @dashboard_bp.route("/api/set_key", methods=["POST"]) |
| #9 | def set_key(): |
| #10 | data = request.get_json() |
| #11 | api_key = data["openAIKey"] |
| #12 | existing_key = APIKey.query.first() |
| #13 | if existing_key: |
| #14 | existing_key.key = api_key |
| #15 | else: |
| #16 | new_key = APIKey(key=api_key) |
| #17 | db.session.add(new_key) |
| #18 | db.session.commit() |
| #19 | return make_response(jsonify(message="API key saved successfully"), 200) |
| #20 | |
| #21 | |
| #22 | # Check OpenAI Key |
| #23 | @dashboard_bp.route("/api/check_key", methods=["GET"]) |
| #24 | def check_key(): |
| #25 | existing_key = APIKey.query.first() |
| #26 | if existing_key: |
| #27 | return make_response(jsonify(status="ok", message="OpenAI Key exists"), 200) |
| #28 | else: |
| #29 | return make_response(jsonify(status="fail", message="No OpenAI Key present"), 200) |
| #30 | |
| #31 | |
| #32 | # Create a bot |
| #33 | @dashboard_bp.route("/api/create_bot", methods=["POST"]) |
| #34 | def create_bot(): |
| #35 | data = request.get_json() |
| #36 | name = data["name"] |
| #37 | slug = name.lower().replace(" ", "_") |
| #38 | existing_bot = BotList.query.filter_by(slug=slug).first() |
| #39 | if existing_bot: |
| #40 | return (make_response(jsonify(message="Bot already exists"), 400),) |
| #41 | new_bot = BotList(name=name, slug=slug) |
| #42 | db.session.add(new_bot) |
| #43 | db.session.commit() |
| #44 | return make_response(jsonify(message="Bot created successfully"), 200) |
| #45 | |
| #46 | |
| #47 | # Delete a bot |
| #48 | @dashboard_bp.route("/api/delete_bot", methods=["POST"]) |
| #49 | def delete_bot(): |
| #50 | data = request.get_json() |
| #51 | slug = data.get("slug") |
| #52 | bot = BotList.query.filter_by(slug=slug).first() |
| #53 | if bot: |
| #54 | db.session.delete(bot) |
| #55 | db.session.commit() |
| #56 | return make_response(jsonify(message="Bot deleted successfully"), 200) |
| #57 | return make_response(jsonify(message="Bot not found"), 400) |
| #58 | |
| #59 | |
| #60 | # Get the list of bots |
| #61 | @dashboard_bp.route("/api/get_bots", methods=["GET"]) |
| #62 | def get_bots(): |
| #63 | bots = BotList.query.all() |
| #64 | bot_list = [] |
| #65 | for bot in bots: |
| #66 | bot_list.append( |
| #67 | { |
| #68 | "name": bot.name, |
| #69 | "slug": bot.slug, |
| #70 | } |
| #71 | ) |
| #72 | return jsonify(bot_list) |
| #73 |