-
Notifications
You must be signed in to change notification settings - Fork 8
Add default path #15
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
base: main
Are you sure you want to change the base?
Add default path #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,6 +43,37 @@ def decorated_function(*args, **kwargs): | |
return jsonify(message="Unauthorized"), 401 | ||
return f(*args, **kwargs) | ||
return decorated_function | ||
|
||
|
||
@app.route('/', methods=['GET']) | ||
def index(): | ||
gkorland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Return a list of all the available routes as HTML response with clickable links. | ||
""" | ||
|
||
return """ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Falkor Code-Graph-Backend API</title> | ||
<link rel="icon" href="https://code-graph.falkordb.com/favicon.ico" type="image/x-icon"/> | ||
</head> | ||
<body> | ||
<h1>Welcome to the Falkor Code-Graph-Backend API</h1> | ||
<h2>Available Routes:</h2> | ||
<ul> | ||
<li><a href="/graph_entities?repo=repo_name">/graph_entities?repo=repo_name</a></li> | ||
<li><a href="/get_neighbors?repo=repo_name&node_id=1">/get_neighbors?repo=repo_name&node_id=1</a></li> | ||
<li><a href="/auto_complete">/auto_complete</a></li> | ||
<li><a href="/list_repos">/list_repos</a></li> | ||
<li><a href="/repo_info">/repo_info</a></li> | ||
<li><a href="/find_paths">/find_paths</a></li> | ||
<li><a href="/chat">/chat</a></li> | ||
</ul> | ||
</body> | ||
""" | ||
|
||
|
||
@app.route('/graph_entities', methods=['GET']) | ||
@token_required # Apply token authentication decorator | ||
def graph_entities(): | ||
|
@@ -102,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 | ||
|
@@ -136,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(): | ||
|
@@ -152,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): | ||
|
@@ -174,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(): | ||
|
@@ -195,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(): | ||
|
@@ -218,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) | ||
|
@@ -240,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(): | ||
|
@@ -264,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 | ||
|
||
|
@@ -291,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(): | ||
|
@@ -304,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify the The static analysis tool indicates that the Run this script to verify the import: 🏁 Script executed: #!/bin/bash
# Description: Check if the `ask` function is defined in the codebase.
# Search for the definition of the `ask` function
ast-grep --pattern 'def ask($$$)'
# Search for exports of the `ask` function
rg -l "^def ask|^ask\s*=" Length of output: 74 Action Required: Explicit Import Needed for The verification confirms that the 🧰 Tools🪛 Ruff (0.8.2)350-350: (F405) |
||
|
||
# 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(): | ||
|
@@ -337,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: | ||
|
@@ -371,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 | ||
|
@@ -391,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', []) | ||
|
@@ -407,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 | ||
|
@@ -424,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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how you should generate the list of endpoints: