-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Code Search Basic Scripts (#217)
* Add Code Search Basic Scripts * [BOT] Set version for this branch * add code search app logo and update metadata.yaml file * Update code search scripts for review * Update code search metadata.yaml --------- Co-authored-by: Team Service <[email protected]>
- Loading branch information
1 parent
d9efbd4
commit 9b0d4e8
Showing
18 changed files
with
195,671 additions
and
3 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Saagie-Code-Search | ||
|
||
|
||
## Description | ||
|
||
Saagie Code Search is a web application built using Flask and Python, designed to help developers efficiently search and retrieve Python functions. It provides a user-friendly interface for searching code snippets in a default codebase or in code repositories hosted on GitHub. | ||
|
||
## How to use | ||
|
||
To deploy the app: you need to create the app with port `5000` exposed, `Base path variable:SAAGIE_BASE_PATH`, and select `Use rewrite url` and set the port access as `PROJECT`. | ||
|
||
In Saagie, create the project environment variable $COPILOT_GITHUB_API_KEY containing your GitHub API key. | ||
|
||
Once the app is up, you can open the page of port 5000. | ||
|
||
## Search Functionality | ||
|
||
Saagie Code Search enables users to search for Python functions within the available codebases. The search functionality supports various search criteria, including function names and keywords. Users can enter their search queries and obtain relevant code snippets as search results. | ||
|
||
## Default Codebase | ||
|
||
The application comes preloaded with a default codebase containing 10,000 Python functions. Users can search for code snippets directly within this default codebase. The default codebase serves as a starting point for users to explore and find relevant code examples. | ||
|
||
## GitHub Repository Integration | ||
|
||
Saagie Code Search offers integration with GitHub repositories. To enable this functionality, you need to provide a GitHub access token. The access token should be saved in the environment variable `$COPILOT_GITHUB_API_KEY` in Saagie. This token allows the application to fetch the necessary information from the specified GitHub repositories. By providing the GitHub repository link, the application retrieves all the Python functions from the repository and adds them to a separate codebase within the application. This allows users to search for code within the specified repository. | ||
|
||
## Supported Language | ||
|
||
Saagie Code Search currently supports searching for Python functions only. The application is optimized to handle Python code specifically and does not support other programming languages. | ||
|
||
## Usage Instructions | ||
|
||
- To search within the default codebase, simply enter your search query in the search interface, specifying the function name or keywords related to the code you are looking for. | ||
- To search within a specific GitHub repository, provide the application with the link to the repository. Saagie Code Search will extract all Python functions from the repository and create a separate codebase for searching within that repository. | ||
- Browse through the search results to find the desired code snippets. Each search result will provide the function name, code snippet, and relevant metadata to assist in code exploration. |
17 changes: 17 additions & 0 deletions
17
technologies/app/saagie-code-search/docker_flask_app/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# Use an official Python runtime as the base image | ||
FROM python:3.10 | ||
|
||
# Set the working directory in the container | ||
WORKDIR /code-search-app | ||
|
||
# Copy the requirements.txt file and install the Python dependencies | ||
COPY requirements.txt requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
||
# Copy the entire project into the container | ||
COPY . . | ||
|
||
# Start the Flask app when the container launches | ||
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"] |
44 changes: 44 additions & 0 deletions
44
technologies/app/saagie-code-search/docker_flask_app/app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from flask import Flask, render_template, request | ||
from utils import get_databases, get_results, load_model, load_codes_and_embeddings, get_functions_from_repo, encode_new_database | ||
app = Flask(__name__) | ||
|
||
# Get the list of previously saved databases | ||
# databases = get_databases() | ||
|
||
# Load the model and the databases | ||
load_model() | ||
load_codes_and_embeddings() | ||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
def index(): | ||
# Get the list of previously saved databases | ||
databases = get_databases() | ||
|
||
if request.method == 'POST': | ||
query = request.form['query'] | ||
selected_database = request.form['database'] | ||
new_database = request.form.get('new-db', '') | ||
|
||
# If a new GitHub repository is provided | ||
if new_database: | ||
# Parse the GitHub repository to get all the Python functions inside | ||
functions, paths = get_functions_from_repo(new_database) | ||
# Encode those functions | ||
encode_new_database(new_database, functions, paths) | ||
# Update the list of databases | ||
load_codes_and_embeddings() | ||
databases = get_databases() | ||
|
||
|
||
# Get the search results | ||
results, path_results, similarities, colors = get_results(query, selected_database, databases, N=10) | ||
|
||
# Render the HTML page with the search results | ||
return render_template('results_v2.html', query=query, selected_database=selected_database, results=results, path_results=path_results, similarities=similarities, colors=colors, databases=databases) | ||
else: | ||
# Render the HTML page without search results (no query submitted yet) | ||
return render_template('results_v2.html', databases=databases) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(debug=True, host='0.0.0.0') |
Oops, something went wrong.