From 20b85bf1b4dbdb867b1822a355a566ff6dd7d393 Mon Sep 17 00:00:00 2001 From: Lukas Rump Date: Fri, 27 Sep 2024 15:30:15 +0200 Subject: [PATCH] fixes --- .github/workflows/black.yml | 2 +- .github/workflows/pylint.yml | 4 ++-- crllm_config.toml | 4 ++-- git_diff.txt | 1 - pyproject.toml | 4 ++++ src/crllm/app.py | 1 + src/crllm/cli.py | 1 - src/crllm/code/loaders/git_stage.py | 15 +++++---------- src/crllm/config/config_service.py | 9 ++++----- src/crllm/model/model.py | 4 ++-- src/crllm/model/provider/__init__.py | 2 +- src/crllm/model/provider/azure.py | 2 +- src/crllm/model/provider/huggingface.py | 4 ++-- src/crllm/prompt_builder.py | 16 ++++++---------- 14 files changed, 31 insertions(+), 38 deletions(-) delete mode 100644 git_diff.txt diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index b2cd244..35bd9f0 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -1,4 +1,4 @@ -name: Lint +name: Black on: [push, pull_request] diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 8a41d41..a261ae4 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -3,11 +3,11 @@ name: Pylint on: [push] jobs: - build: + lint: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.10"] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} diff --git a/crllm_config.toml b/crllm_config.toml index 734b396..b131288 100644 --- a/crllm_config.toml +++ b/crllm_config.toml @@ -3,5 +3,5 @@ description = "A cli tool that used large language model to generate code review [crllm] loader = "git_staging" -model = "llama3.1" -git_changed_lines=false \ No newline at end of file +model = "llama3.2" +git_changed_lines=true \ No newline at end of file diff --git a/git_diff.txt b/git_diff.txt deleted file mode 100644 index 257cc56..0000000 --- a/git_diff.txt +++ /dev/null @@ -1 +0,0 @@ -foo diff --git a/pyproject.toml b/pyproject.toml index 99d721b..ccd6a9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,3 +22,7 @@ build-backend = "hatchling.build" [project.scripts] crllm = "crllm.cli:cli" + +[tool.black] +line-length = 88 +target-version = ['py37'] \ No newline at end of file diff --git a/src/crllm/app.py b/src/crllm/app.py index d4f05fa..c48c677 100644 --- a/src/crllm/app.py +++ b/src/crllm/app.py @@ -23,5 +23,6 @@ def app(path: str, isRepo: bool = True): parser = ResultParser() md = Markdown(parser.parse(result)) + console = Console() console.print(md) diff --git a/src/crllm/cli.py b/src/crllm/cli.py index 52f5738..5237e25 100644 --- a/src/crllm/cli.py +++ b/src/crllm/cli.py @@ -1,7 +1,6 @@ import argparse import logging -# Works in build fix everywhere from crllm.app import app diff --git a/src/crllm/code/loaders/git_stage.py b/src/crllm/code/loaders/git_stage.py index ed29044..f100b61 100644 --- a/src/crllm/code/loaders/git_stage.py +++ b/src/crllm/code/loaders/git_stage.py @@ -1,12 +1,11 @@ import logging - -from crllm.code.ignored_files_filter import filter_ignored_files from git import Repo from crllm.config.config_service import config_service -# ToDo: not staged https://stackoverflow.com/questions/33733453/get-changed-files-using-gitpython +# ToDo: not staged +# https://stackoverflow.com/questions/33733453/get-changed-files-using-gitpython def git_stage(path): config = config_service.getConfig() use_changed_lines = config["crllm"]["git_changed_lines"] @@ -14,17 +13,15 @@ def git_stage(path): repo = Repo(path) diff = repo.index.diff(None, create_patch=True) - print(str(diff[0])) - if len(diff) == 0: raise Exception("No changed files found!") code = "" if not use_changed_lines: - changedFiles = [item.a_path for item in diff if item.a_path != None] - changedFiles = filter_ignored_files(changedFiles) - + changedFiles = [ + item.a_path for item in diff if item.a_path is not None] + logging.info(f"Found changed files: {changedFiles}") for file in changedFiles: @@ -35,6 +32,4 @@ def git_stage(path): for line in diff: code += str(line) + "\n" - print(code) - return code diff --git a/src/crllm/config/config_service.py b/src/crllm/config/config_service.py index d070a23..bab0b64 100644 --- a/src/crllm/config/config_service.py +++ b/src/crllm/config/config_service.py @@ -6,7 +6,6 @@ from crllm.config import CONFIG_DIR -# config loader? class ConfigService: configPath = os.path.join(CONFIG_DIR, "config.toml") config = None @@ -16,14 +15,14 @@ def getConfig(self, path="./crllm_config.toml"): return self.config self.config = toml.load(self.configPath) - + if not os.path.isfile(path): return self.config - + project_config = toml.load(path) - + self.config = always_merger.merge(self.config, project_config) - + logging.debug(self.config) return self.config diff --git a/src/crllm/model/model.py b/src/crllm/model/model.py index 899fa47..9560bb6 100644 --- a/src/crllm/model/model.py +++ b/src/crllm/model/model.py @@ -12,11 +12,11 @@ def generate(self, promptTemplate, promptArgs): llm_chain = promptTemplate | model result = llm_chain.invoke(promptArgs) - + logging.debug(result) return result.content - + @abstractmethod def _getModel(self, model_config): pass diff --git a/src/crllm/model/provider/__init__.py b/src/crllm/model/provider/__init__.py index 65b750d..21bda9a 100644 --- a/src/crllm/model/provider/__init__.py +++ b/src/crllm/model/provider/__init__.py @@ -6,5 +6,5 @@ providers = { "ollama": OllamaModel, "azure": AzureModel, - "huggingface": HuggingFaceModel + "huggingface": HuggingFaceModel, } diff --git a/src/crllm/model/provider/azure.py b/src/crllm/model/provider/azure.py index 23591ee..9e8750d 100644 --- a/src/crllm/model/provider/azure.py +++ b/src/crllm/model/provider/azure.py @@ -2,6 +2,6 @@ from crllm.model.model import Model -class AzureModel(Model): +class AzureModel(Model): def _getModel(self, model_config): return AzureChatOpenAI(**model_config) diff --git a/src/crllm/model/provider/huggingface.py b/src/crllm/model/provider/huggingface.py index fdf2d5b..d72fcc3 100644 --- a/src/crllm/model/provider/huggingface.py +++ b/src/crllm/model/provider/huggingface.py @@ -1,8 +1,8 @@ -from langchain_huggingface import ChatHuggingFace,HuggingFaceEndpoint +from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint from crllm.model.model import Model -class HuggingFaceModel(Model): +class HuggingFaceModel(Model): def _getModel(self, model_config): llm = HuggingFaceEndpoint(**model_config) diff --git a/src/crllm/prompt_builder.py b/src/crllm/prompt_builder.py index ed23d2d..b25e883 100644 --- a/src/crllm/prompt_builder.py +++ b/src/crllm/prompt_builder.py @@ -15,15 +15,11 @@ def build(self): logging.debug(config["prompt"]) - prompt = ChatPromptTemplate.from_messages([ - ( - "system", - config["prompt"]["template"] - ), - ( - "human", - "Do code review for the following code: \n {code}" - ) - ]) + prompt = ChatPromptTemplate.from_messages( + [ + ("system", config["prompt"]["template"]), + ("human", "Do code review for the following code: \n {code}"), + ] + ) return prompt