From e394b05c87f0e1fa4be17d59204dca0d8acbe9fc Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Sat, 16 Nov 2024 21:37:04 +0200 Subject: [PATCH 1/3] add default path --- api/index.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/api/index.py b/api/index.py index 2153a3e..3212140 100644 --- a/api/index.py +++ b/api/index.py @@ -35,6 +35,34 @@ def decorated_function(*args, **kwargs): return f(*args, **kwargs) return decorated_function +@app.route('/', methods=['GET']) +def index(): + """ + Return a list of all the available routes as HTML response with clickable links. + """ + + return """ + + + + Falkor Code-Graph-Backend API + + + +

Welcome to the Falkor Code-Graph-Backend API

+

Available Routes:

+ + + """ + @app.route('/graph_entities', methods=['GET']) @token_required # Apply token authentication decorator def graph_entities(): From 5d762597d5c20bb9855595ad94573e05e7a0d511 Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Sat, 16 Nov 2024 21:41:43 +0200 Subject: [PATCH 2/3] remove sizes --- api/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/index.py b/api/index.py index 3212140..1762efe 100644 --- a/api/index.py +++ b/api/index.py @@ -46,7 +46,7 @@ def index(): Falkor Code-Graph-Backend API - +

Welcome to the Falkor Code-Graph-Backend API

From 7f65b71d6da9560a710ccf542c79b5aeaeb7435e Mon Sep 17 00:00:00 2001 From: Guy Korland Date: Sun, 16 Feb 2025 20:24:17 +0200 Subject: [PATCH 3/3] Refactor code formatting and import logging. --- api/index.py | 53 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/api/index.py b/api/index.py index d8b2a5d..02bc87d 100644 --- a/api/index.py +++ b/api/index.py @@ -1,4 +1,5 @@ import os +import logging from api import * from pathlib import Path from functools import wraps @@ -12,7 +13,6 @@ load_dotenv() # Configure the logger -import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) @@ -43,14 +43,14 @@ def decorated_function(*args, **kwargs): return jsonify(message="Unauthorized"), 401 return f(*args, **kwargs) return decorated_function - - + + @app.route('/', methods=['GET']) def index(): """ Return a list of all the available routes as HTML response with clickable links. """ - + return """ @@ -58,7 +58,7 @@ def index(): Falkor Code-Graph-Backend API - +

Welcome to the Falkor Code-Graph-Backend API

Available Routes:

    @@ -71,7 +71,8 @@ def index():
  • /chat
- """ + """ + @app.route('/graph_entities', methods=['GET']) @token_required # Apply token authentication decorator @@ -132,7 +133,7 @@ def get_neighbors(): data = request.get_json() # Get query parameters - repo = data.get('repo') + repo = data.get('repo') node_ids = data.get('node_ids') # Validate 'repo' parameter @@ -166,6 +167,7 @@ def get_neighbors(): return jsonify(response), 200 + @app.route('/auto_complete', methods=['POST']) @token_required # Apply token authentication decorator def auto_complete(): @@ -182,12 +184,12 @@ def auto_complete(): # Validate that 'repo' is provided repo = data.get('repo') if repo is None: - return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "repo"'}), 400 # Validate that 'prefix' is provided prefix = data.get('prefix') if prefix is None: - return jsonify({'status': f'Missing mandatory parameter "prefix"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "prefix"'}), 400 # Validate repo exists if not graph_exists(repo): @@ -204,6 +206,7 @@ def auto_complete(): return jsonify(response), 200 + @app.route('/list_repos', methods=['GET']) @token_required # Apply token authentication decorator def list_repos(): @@ -225,6 +228,7 @@ def list_repos(): return jsonify(response), 200 + @app.route('/repo_info', methods=['POST']) @token_required # Apply token authentication decorator def repo_info(): @@ -248,7 +252,7 @@ def repo_info(): # Validate the 'repo' parameter repo = data.get('repo') if repo is None: - return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "repo"'}), 400 # Initialize the graph with the provided repository name g = Graph(repo) @@ -270,6 +274,7 @@ def repo_info(): return jsonify(response), 200 + @app.route('/find_paths', methods=['POST']) @token_required # Apply token authentication decorator def find_paths(): @@ -294,19 +299,19 @@ def find_paths(): # Validate 'repo' parameter repo = data.get('repo') if repo is None: - return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "repo"'}), 400 # Validate 'src' parameter src = data.get('src') if src is None: - return jsonify({'status': f'Missing mandatory parameter "src"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "src"'}), 400 if not isinstance(src, int): return jsonify({'status': "src node id must be int"}), 400 # Validate 'dest' parameter dest = data.get('dest') if dest is None: - return jsonify({'status': f'Missing mandatory parameter "dest"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "dest"'}), 400 if not isinstance(dest, int): return jsonify({'status': "dest node id must be int"}), 400 @@ -321,10 +326,11 @@ def find_paths(): paths = g.find_paths(src, dest) # Create and return a successful response - response = { 'status': 'success', 'paths': paths } + response = {'status': 'success', 'paths': paths} return jsonify(response), 200 + @app.route('/chat', methods=['POST']) @token_required # Apply token authentication decorator def chat(): @@ -334,20 +340,21 @@ def chat(): # Validate 'repo' parameter repo = data.get('repo') if repo is None: - return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "repo"'}), 400 # Get optional 'label' and 'relation' parameters msg = data.get('msg') if msg is None: - return jsonify({'status': f'Missing mandatory parameter "msg"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "msg"'}), 400 answer = ask(repo, msg) # Create and return a successful response - response = { 'status': 'success', 'response': answer } + response = {'status': 'success', 'response': answer} return jsonify(response), 200 + @app.route('/analyze_folder', methods=['POST']) @token_required # Apply token authentication decorator def analyze_folder(): @@ -367,8 +374,8 @@ def analyze_folder(): data = request.get_json() # Get query parameters - path = data.get('path') - ignore = data.get('ignore', []) + path = data.get('path') + ignore = data.get('ignore', []) # Validate input parameters if not path: @@ -401,6 +408,7 @@ def analyze_folder(): } return jsonify(response), 200 + @app.route('/analyze_repo', methods=['POST']) @public_access # Apply public access decorator @token_required # Apply token authentication decorator @@ -421,7 +429,7 @@ def analyze_repo(): data = request.get_json() url = data.get('repo_url') if url is None: - return jsonify({'status': f'Missing mandatory parameter "url"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "url"'}), 400 logger.debug(f'Received repo_url: {url}') ignore = data.get('ignore', []) @@ -437,6 +445,7 @@ def analyze_repo(): return jsonify(response), 200 + @app.route('/switch_commit', methods=['POST']) @public_access # Apply public access decorator @token_required # Apply token authentication decorator @@ -454,12 +463,12 @@ def switch_commit(): # Validate that 'repo' is provided repo = data.get('repo') if repo is None: - return jsonify({'status': f'Missing mandatory parameter "repo"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "repo"'}), 400 # Validate that 'commit' is provided commit = data.get('commit') if commit is None: - return jsonify({'status': f'Missing mandatory parameter "commit"'}), 400 + return jsonify({'status': 'Missing mandatory parameter "commit"'}), 400 # Attempt to switch the repository to the specified commit change_set = switch_commit(repo, commit)