Skip to content
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

User Interface Requirement #10

Open
farhoud opened this issue Jul 31, 2024 · 4 comments
Open

User Interface Requirement #10

farhoud opened this issue Jul 31, 2024 · 4 comments
Labels

Comments

@farhoud
Copy link
Contributor

farhoud commented Jul 31, 2024

Stories

user can index a project by providing a project path and main function to lattice
user can search for code in human language

Lattice HTTP API Documentation

Base URL

we can also use http over linux socket

http://localhost:12345

Endpoints

1. Index Project

Index a project by providing the project path and main function.

Endpoint

POST /index

Request Body

{
  "path": "<project_path>",
  "main": "<main_function>"
}

Example Request

{
  "path": "/path/to/your/project",
  "main": "main.py"
}

Response

{
  "status": "success",
  "message": "Project indexed successfully."
}

2. Search Code

Search for code in human language.

Endpoint

GET /search

Query Parameters

  • query (required): The search query in human language.

Example Request

GET /search?query=function+that+calculates+factorial

Response

{
  "status": "success",
  "results": [
    {
      "file": "utils.py",
      "line": 10,
      "code": "def factorial(n):"
    },
    {
      "file": "math_helpers.py",
      "line": 5,
      "code": "def compute_factorial(number):"
    }
  ]
}

Detailed Endpoint Descriptions

Index Project Endpoint

Description:
This endpoint allows you to index a project, making it searchable by the Lattice system.

HTTP Method: POST

URL: /index

Request Body:

  • path (string, required): The path to the project directory you want to index.
  • main (string, required): The main function or entry point of your project.

Example Request:

curl -X POST http://api.lattice.com/index \
  -H "Content-Type: application/json" \
  -d '{
        "path": "/home/user/projects/my_project",
        "main": "app.py"
      }'

Example Response:

{
  "status": "success",
  "message": "Project indexed successfully."
}

Search Code Endpoint

Description:
This endpoint allows you to search your indexed codebase using human language.

HTTP Method: GET

URL: /search

Query Parameters:

  • query (string, required): The search query in human language describing what you are looking for.

Example Request:

curl -X GET "http://api.lattice.com/search?query=function+that+parses+JSON+data"

Example Response:

{
  "status": "success",
  "results": [
    {
      "file": "data_parser.py",
      "line": 20,
      "code": "def parse_json(json_string):"
    },
    {
      "file": "json_utils.py",
      "line": 15,
      "code": "def from_json(json_str):"
    }
  ]
}

Error Handling

Common Errors

  1. 400 Bad Request

    • Cause: Missing required fields in the request body or query parameters.
    • Response:
      {
        "status": "error",
        "message": "Missing required fields."
      }
  2. 404 Not Found

    • Cause: No matching results found for the search query.
    • Response:
      {
        "status": "error",
        "message": "No matching results found."
      }
  3. 500 Internal Server Error

    • Cause: An unexpected error occurred on the server.
    • Response:
      {
        "status": "error",
        "message": "An unexpected error occurred. Please try again later."
      }

Conclusion

This HTTP API allows you to index projects and search for code using human language, facilitating easy navigation and management of your codebase. Follow the endpoint guidelines and examples to integrate these capabilities into your applications.

Lattice CLI Documentation

Overview

The Lattice CLI allows you to index your projects and search for code using human language. This makes it easier to manage and navigate through your codebase, especially for larger projects.

Commands

1. index

Index a project by providing the project path and main function to Lattice.

Usage

lattice index --path <project_path> --main <main_function>

Arguments

  • --path (required): The path to the project directory you want to index.
  • --main (required): The main function or entry point of your project.

Example

lattice index --path /path/to/your/project --main main.py

2. search

Search for code in human language.

Usage

lattice search --query "<search_query>"

Arguments

  • --query (required): The search query in human language describing what you are looking for.

Example

lattice search --query "function that calculates factorial"

Detailed Command Descriptions

Index Command

The index command allows you to index your project, making it searchable by the Lattice system. This is useful for setting up your project in Lattice so that you can leverage advanced search capabilities.

Steps to Use

  1. Ensure your project is located in a specific directory.
  2. Identify the main function or entry point of your project.
  3. Run the index command with the appropriate arguments.

Example Explained

lattice index --path /home/user/projects/my_project --main app.py
  • This command will index the project located at /home/user/projects/my_project.
  • It will use app.py as the main function or entry point for the project.

Search Command

The search command enables you to search your indexed codebase using human language. This makes it easier to find specific functions, classes, or code snippets without having to remember exact code syntax or file locations.

Steps to Use

  1. Ensure your project has been indexed using the index command.
  2. Formulate a query in human language describing what you are looking for.
  3. Run the search command with your query.

Example Explained

lattice search --query "function that parses JSON data"
  • This command will search the indexed project for a function that parses JSON data.

Troubleshooting

Common Issues

  1. Project Not Indexed

    • Ensure you have run the index command before attempting to use the search command.
    • Verify the project path and main function are correct.
  2. No Results Found

    • Check the query for accuracy and try using different keywords.
    • Ensure the project was indexed correctly.

Getting Help

For additional help, use the --help flag with any command to display usage information.

lattice index --help
lattice search --help

Conclusion

The Lattice CLI simplifies the process of navigating and managing your codebase by enabling human language search and efficient project indexing. Follow the usage guidelines and examples to make the most out of these powerful features.

@farhoud
Copy link
Contributor Author

farhoud commented Jul 31, 2024

@rekino do we agree on the input for index?

@amrhssn are we on the same page on the provided response?

@amrhssn
Copy link

amrhssn commented Jul 31, 2024

@farhoud This is neat! I like it 🙌🏻

@farhoud
Copy link
Contributor Author

farhoud commented Jul 31, 2024

@amrhssn
Does user need to provide a project as an optional input?

do we need to change the Response to:

Response

{
  "status": "success",
  "results": [
    {
      "project": "path or name?"
      "file": "utils.py",
      "line": 10,
      "code": "def factorial(n):"
    },
    {
     "project": "path or name?"
      "file": "math_helpers.py",
      "line": 5,
      "code": "def compute_factorial(number):"
    }
  ]
}

@farhoud farhoud changed the title User Interface User Interface Requirement Jul 31, 2024
@rekino
Copy link
Contributor

rekino commented Aug 1, 2024

@rekino do we agree on the input for index?

@farhoud According to ast module standards, we need to keep the column number and end line as well as the start line number to uniquely specify a piece of code in a pyhton file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants