45 lines
1.0 KiB
Python
Raw Permalink Normal View History

2023-12-11 17:29:40 +08:00
import os
2024-01-12 12:21:15 +08:00
import sys
2023-12-11 17:35:04 +08:00
from typing import Optional
2023-12-11 17:29:40 +08:00
2023-12-11 17:35:04 +08:00
import click
2023-12-11 17:29:40 +08:00
from chat.ask_codebase.assistants.directory_structure.repo_explainer import (
RepoStructureExplainer,
)
2023-12-11 17:35:04 +08:00
2024-01-12 12:21:15 +08:00
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "libs"))
from chatmark import Step # noqa: E402
2023-12-11 17:35:04 +08:00
Languages = {
"en": "English",
"zh": "Chinese",
}
2023-12-11 17:29:40 +08:00
@click.command()
@click.argument("objective", required=False, default=None)
2023-12-11 17:35:04 +08:00
@click.option(
"-lang",
"--language",
type=click.Choice(list(Languages.keys()), case_sensitive=False),
)
2023-12-11 17:29:40 +08:00
def main(objective: Optional[str], language: str):
if not objective:
objective = "Help me understand the structure of this repo."
chat_lang = Languages.get(language, None)
repo_path = os.getcwd()
2023-12-11 17:35:04 +08:00
e = RepoStructureExplainer(root_path=repo_path, chat_language=chat_lang)
2023-12-11 17:29:40 +08:00
2024-01-12 12:21:15 +08:00
with Step("Analyzing codebase..."):
answer = e.analyze(user_query=objective)
print("Done.", flush=True)
2023-12-11 17:29:40 +08:00
print(f"\n{answer}\n", flush=True)
if __name__ == "__main__":
main()