Skip to content
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 backend/app/agents/devrel/github/github_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .tools.github_support import handle_github_supp
from .tools.contributor_recommendation import handle_contributor_recommendation
from .tools.general_github_help import handle_general_github_help
from .tools.repo_support import handle_repo_support

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -114,7 +115,7 @@ async def execute(self, query: str) -> Dict[str, Any]:
result = await handle_github_supp(query, org=org)
result["org_used"] = org
elif classification == "repo_support":
result = "Not implemented"
result = await handle_repo_support(query)
elif classification == "issue_creation":
result = "Not implemented"
elif classification == "documentation_generation":
Expand Down
27 changes: 17 additions & 10 deletions backend/app/agents/devrel/github/prompts/intent_analysis.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
GITHUB_INTENT_ANALYSIS_PROMPT = """You are an expert GitHub DevRel AI assistant. Analyze the user query and classify the intent.

AVAILABLE FUNCTIONS:
- github_support: Questions about repository information, structure, stats, issues, stars, forks, description, or any repository metadata
- web_search: Search the web for general information
- contributor_recommendation: Finding the right people to review PRs, assign issues, or collaborate
- repo_support: Questions about codebase structure, dependencies, impact analysis, architecture
- issue_creation: Creating bug reports, feature requests, or tracking items
- documentation_generation: Generating docs, READMEs, API docs, guides, or explanations
- find_good_first_issues: Finding beginner-friendly issues to work on across repositories
- general_github_help: General GitHub-related assistance and guidance
- github_support: Repository metadata (stars, forks, issues count, description)
- repo_support: Code structure queries (WHERE code is, WHAT implements feature, HOW it works)
* "Where is authentication in X repo?"
* "Show me API endpoints"
* "Find database models"
* NOTE: Repo must be indexed first
- contributor_recommendation: Find people for PRs/issues
- web_search: External information
- issue_creation: Create bugs/features
- documentation_generation: Generate docs
- find_good_first_issues: Beginner issues
- general_github_help: General GitHub help

USER QUERY: {user_query}

Expand Down Expand Up @@ -38,12 +42,15 @@
- web_search: Only for information that cannot be found through GitHub API (like news, articles, external documentation)
- general_github_help: General GitHub questions not covered above

IMPORTANT: Repository information queries (issues count, stars, forks, description) should ALWAYS use github_support, not web_search.
IMPORTANT:
- Repository information queries (issues count, stars, forks, description) should ALWAYS use github_support, not web_search.
- github_support: "How many stars does X have?" (metadata)
- repo_support: "Where is auth in X?" (code structure)

CRITICAL: Return ONLY raw JSON. No markdown, no code blocks, no explanation text.

{{
"classification": "function_name_from_list_above",
"reasoning": "Brief explanation of why you chose this function",
"confidence": "high|medium|low"
}}"""
}}"""
43 changes: 43 additions & 0 deletions backend/app/agents/devrel/github/tools/repo_support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import logging
import re
from typing import Dict, Any, Optional
from app.services.codegraph.repo_service import RepoService

logger = logging.getLogger(__name__)


async def handle_repo_support(query: str) -> Dict[str, Any]:
"""Handle repository code graph queries."""
try:
service = RepoService()
repo_name = _extract_repo_name(query)

if not repo_name:
return {
"status": "error",
"sub_function": "repo_support",
"message": "Please specify repository: 'Where is X in owner/repo?'"
}

result = await service.query_repo(query, repo_name)

return {
"status": result["status"],
"sub_function": "repo_support",
"repository": repo_name,
**{k: v for k, v in result.items() if k != "status"}
}

except Exception as e:
logger.exception("Repository support error")
return {
"status": "error",
"sub_function": "repo_support",
"message": "Query failed. Please try again."
}

def _extract_repo_name(query: str) -> Optional[str]:
"""Extract repository name from query (owner/repo format)"""
pattern = r'\b([a-zA-Z0-9][-a-zA-Z0-9]*)/([a-zA-Z0-9_.-]+)\b'
match = re.search(pattern, query)
return match.group(0) if match else None
8 changes: 8 additions & 0 deletions backend/app/database/falkor/code-graph-backend/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FALKORDB_HOST=<host>
FALKORDB_PORT=<port>
FALKORDB_USERNAME=<username>
FALKORDB_PASSWORD=<password>
OPENAI_API_KEY=<openai_api_key>
GEMINI_API_KEY=<gemini_api_key>
SECRET_TOKEN=<secret_token>

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
target-branch: "staging"
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

# - name: Test with pytest
# run: |
# pytest
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release image to DockerHub

on:
workflow_dispatch:
push:
tags: ["v*.*.*"]
branches:
- main

jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set tags
run: |
if ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}; then
echo "TAGS=falkordb/code-graph-backend:latest,falkordb/code-graph-backend:${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "TAGS=falkordb/code-graph-backend:edge" >> $GITHUB_ENV
fi

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ env.TAGS }}
44 changes: 44 additions & 0 deletions backend/app/database/falkor/code-graph-backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Byte-compiled files
*.pyc
*.pyo
*.pyd
__pycache__/

# Virtual environments
venv/
env/
.virtualenv/

# Distribution/build files
build/
dist/
*.egg-info/
.eggs/

# IDE settings
.vscode/
.idea/
*.swp

# Logs and debugging
*.log
*.trace

# OS-specific files
.DS_Store
Thumbs.db

# Testing and coverage
htmlcov/
*.cover
.coverage
.cache/
pytest_cache/

# Jupyter Notebook checkpoints
.ipynb_checkpoints/

# Custom settings
.env
*.sqlite3
.vercel
21 changes: 21 additions & 0 deletions backend/app/database/falkor/code-graph-backend/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 FalkorDB

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
59 changes: 59 additions & 0 deletions backend/app/database/falkor/code-graph-backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[![Try Free](https://img.shields.io/badge/Try%20Free-FalkorDB%20Cloud-FF8101?labelColor=FDE900&link=https://app.falkordb.cloud)](https://app.falkordb.cloud)
[![Dockerhub](https://img.shields.io/docker/pulls/falkordb/falkordb?label=Docker)](https://hub.docker.com/r/falkordb/falkordb/)
[![Discord](https://img.shields.io/discord/1146782921294884966?style=flat-square)](https://discord.com/invite/6M4QwDXn2w)

## Getting Started

[Live Demo](https://code-graph.falkordb.com/)

## Running locally

### Run FalkorDB

Free cloud instance: https://app.falkordb.cloud/signup

Or by running locally with docker:

```bash
docker run -p 6379:6379 -p 3000:3000 -it --rm falkordb/falkordb:latest
```

### Config

Create your own `.env` file from the `.env.template` file

Start the server:
```bash
flask --app api/index.py run --debug
```

### Creating a graph

Process a local source folder:

```bash
curl -X POST http://127.0.0.1:5000/analyze_folder -H "Content-Type: application/json" -d '{"path": "<FULL_PATH_TO_FOLDER>", "ignore": [<OPTIONAL_IGNORE_LIST>]}' -H "Authorization: <.ENV_SECRET_TOKEN>"
```

For example:

```bash
curl -X POST http://127.0.0.1:5000/analyze_folder -H "Content-Type: application/json" -d '{"path": "/Users/roilipman/Dev/GraphRAG-SDK", "ignore": ["./.github", "./build"]}' -H "Authorization: OpenSesame"
```

## Working with your graph

Once the source code analysis completes your FalkorDB DB will be populated with
a graph representation of your source code, the graph name should be the same as
the name of the folder you've requested to analyze, for the example above a graph named:
"GraphRAG-SDK".

At the moment only the Python and C languages are supported, we do intend to support additional languages.

At this point you can explore and query your source code using various tools
Here are several options:

1. [Code-Graph UI](https://github.com/FalkorDB/code-graph)
1. FalkorDB [Browser](https://github.com/FalkorDB/falkordb-browser/)
2. One of FalkorDB's [clients](https://docs.falkordb.com/clients.html)
3. Use FalkorDB [GraphRAG-SDK](https://github.com/FalkorDB/GraphRAG-SDK) to connect an LLM for natural language exploration.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .info import *
from .llm import ask
from .graph import *
from .project import *
from .entities import *
from .git_utils import *
from .code_coverage import *
from .analyzers.source_analyzer import *
from .auto_complete import prefix_search
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .source_analyzer import SourceAnalyzer
Loading