Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
73 changes: 56 additions & 17 deletions api/index.py
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
Expand All @@ -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__)
Expand Down Expand Up @@ -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():
Copy link
Contributor

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:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
    return 'Home Page'

@app.route('/about')
def about():
    return 'About Page'

@app.route('/contact', methods=['GET', 'POST'])
def contact():
    return 'Contact Page'

# Function to list all endpoints
def list_routes(app):
    routes = []
    for rule in app.url_map.iter_rules():
        routes.append({
            "endpoint": rule.endpoint,
            "methods": list(rule.methods),
            "url": rule.rule
        })
    return routes

if __name__ == '__main__':
    # Print all routes before running the app
    for route in list_routes(app):
        print(f"Endpoint: {route['endpoint']}, Methods: {route['methods']}, URL: {route['url']}")
    
    app.run(debug=True)

"""
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():
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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):
Expand All @@ -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():
Expand All @@ -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():
Expand All @@ -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)
Expand All @@ -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():
Expand All @@ -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

Expand All @@ -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():
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the ask function is properly imported.

The static analysis tool indicates that the ask function may be undefined. While it might be imported via the star import from api, it's better to explicitly import it.

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 ask Function

The verification confirms that the ask function is defined in api/llm.py. However, in api/index.py at line 350 the function is invoked without an explicit import. Please update the file by explicitly importing ask (e.g., add from api.llm import ask at the top of the file) rather than relying on a star import, to ensure clarity and prevent potential undefined reference issues.

🧰 Tools
🪛 Ruff (0.8.2)

350-350: ask may be undefined, or defined from star imports

(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():
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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', [])
Expand All @@ -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
Expand All @@ -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)
Expand Down
Loading