Skip to content

Commit

Permalink
Refactored code to include spinner animations during code parsing and…
Browse files Browse the repository at this point in the history
… vector store indexing/loading, and added prompts for search pattern and chat question inputs.
  • Loading branch information
fynnfluegge committed Sep 24, 2023
1 parent 7cc5034 commit 7ece232
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions codeqai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rich.syntax import Syntax
from yaspin import yaspin

from codeqai import codeparser, repo
from codeqai import codeparser, repo, utils
from codeqai.config import (create_cache_dir, create_config, get_cache_path,
load_config)
from codeqai.constants import EmbeddingsModel, LllmHost
Expand Down Expand Up @@ -47,17 +47,25 @@ def run():
)

# check if faiss.index exists
if not os.path.exists(os.path.join(get_cache_path(), f"{repo_name}.index")):
if not os.path.exists(os.path.join(get_cache_path(), f"{repo_name}.faiss")):
# sync repo
spinner = yaspin(text="🔧 Parsing codebase...", color="green")
files = repo.load_files()
documents = codeparser.parse_code_files(files)
spinner.stop()
spinner = yaspin(text="💾 Indexing vector store...", color="green")
spinner.start()
vector_store = VectorStore(
repo_name,
embeddings=embeddings_model.embeddings,
documents=documents,
)
spinner.stop()
else:
spinner = yaspin(text="💾 Loading vector store...", color="green")
spinner.start()
vector_store = VectorStore(repo_name, embeddings=embeddings_model.embeddings)
spinner.stop()

llm = LLM(
llm_host=LllmHost[config["llm-host"].upper().replace("-", "_")],
Expand All @@ -73,22 +81,25 @@ def run():
while True:
choice = None
if args.action == "search":
search_pattern = input("🤖 Enter a search pattern: ")
search_pattern = input("🔎 Enter a search pattern: ")
spinner = yaspin(text="🤖 Processing...", color="green")
spinner.start()
similarity_result = vector_store.similarity_search(search_pattern)
spinner.stop()
for doc in similarity_result:
language = utils.get_programming_language(
utils.get_file_extension(doc.metadata["filename"])
)
syntax = Syntax(
doc.page_content, "python", theme="monokai", line_numbers=True
doc.page_content, language.value, theme="monokai", line_numbers=True
)
console = Console()
console.print(syntax)

choice = input("[?] (C)ontinue search or (E)xit [C]:").strip().lower()

elif args.action == "chat":
question = input("🤖 Ask me anything about the codebase: ")
question = input("💬 Ask anything about the codebase: ")
spinner = yaspin(text="🤖 Processing...", color="green")
spinner.start()
result = qa(question)
Expand All @@ -102,8 +113,8 @@ def run():
)

if choice == "r":
print("Resetting chat...")
memory.clear()
print("Chat history cleared.")

if choice == "" or choice == "c":
continue
Expand Down

0 comments on commit 7ece232

Please sign in to comment.