Skip to content

Commit

Permalink
Refactored code, added console output for syntax highlighting, and sk…
Browse files Browse the repository at this point in the history
…ipped unknown programming languages in code parsing.
  • Loading branch information
fynnfluegge committed Sep 26, 2023
1 parent 6879e39 commit 6f00743
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
13 changes: 9 additions & 4 deletions codeqai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from yaspin import yaspin

from codeqai import codeparser, repo, utils
from codeqai.config import (create_cache_dir, create_config, get_cache_path,
load_config)
from codeqai.config import create_cache_dir, create_config, get_cache_path, load_config
from codeqai.constants import EmbeddingsModel, LllmHost
from codeqai.embeddings import Embeddings
from codeqai.llm import LLM
Expand Down Expand Up @@ -42,7 +41,7 @@ def run():
create_cache_dir()

embeddings_model = Embeddings(
local=True,
local=config["local"],
model=EmbeddingsModel[config["embeddings"].upper().replace("-", "_")],
deployment=config["embeddings-deployment"]
if "embeddings-deployment" in config
Expand Down Expand Up @@ -94,11 +93,17 @@ def run():
language = utils.get_programming_language(
utils.get_file_extension(doc.metadata["filename"])
)

syntax = Syntax(
doc.page_content, language.value, theme="monokai", line_numbers=True
doc.page_content,
language.value,
theme="monokai",
line_numbers=True,
)
console = Console()
print(doc.metadata["filename"] + " -> " + doc.metadata["method_name"])
console.print(syntax)
print()

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

Expand Down
5 changes: 1 addition & 4 deletions codeqai/codeparser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re

from langchain.schema import Document
from langchain.text_splitter import RecursiveCharacterTextSplitter
Expand All @@ -19,9 +18,7 @@ def parse_code_files(code_files: list[str]) -> list[Document]:
file_extension = utils.get_file_extension(code_file)
programming_language = utils.get_programming_language(file_extension)
if programming_language == Language.UNKNOWN:
print(
f"Skipping file {code_file} with unsupported programming language"
)
continue

langchain_language = utils.get_langchain_language(programming_language)

Expand Down
3 changes: 2 additions & 1 deletion codeqai/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def create_config():
"llm-host",
message="Which remote LLM do you want to use?",
choices=[
"OpenAI" "Azure-OpenAI",
"OpenAI",
"Azure-OpenAI",
],
default="OpenAI",
),
Expand Down
6 changes: 2 additions & 4 deletions codeqai/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ def __init__(
if not local:
if model == EmbeddingsModel.OPENAI_TEXT_EMBEDDING_ADA_002:
self.embeddings = OpenAIEmbeddings(
client=None, model="text_embedding_ada_002"
client=None, model="text-embedding-ada-002"
)
elif model == EmbeddingsModel.AZURE_OPENAI and deployment:
self.embeddings = OpenAIEmbeddings(
client=None, model="text_embedding_ada_002", deployment=deployment
)
self.embeddings = OpenAIEmbeddings(client=None, deployment=deployment)
else:
try:
import sentence_transformers # noqa: F401
Expand Down

0 comments on commit 6f00743

Please sign in to comment.