Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrump committed Sep 27, 2024
1 parent 42e6cc1 commit 20b85bf
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: Black

on: [push, pull_request]

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions crllm_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
model = "llama3.2"
git_changed_lines=true
1 change: 0 additions & 1 deletion git_diff.txt

This file was deleted.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ build-backend = "hatchling.build"

[project.scripts]
crllm = "crllm.cli:cli"

[tool.black]
line-length = 88
target-version = ['py37']
1 change: 1 addition & 0 deletions src/crllm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ def app(path: str, isRepo: bool = True):

parser = ResultParser()
md = Markdown(parser.parse(result))

console = Console()
console.print(md)
1 change: 0 additions & 1 deletion src/crllm/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse
import logging

# Works in build fix everywhere
from crllm.app import app


Expand Down
15 changes: 5 additions & 10 deletions src/crllm/code/loaders/git_stage.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
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"]

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:
Expand All @@ -35,6 +32,4 @@ def git_stage(path):
for line in diff:
code += str(line) + "\n"

print(code)

return code
9 changes: 4 additions & 5 deletions src/crllm/config/config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from crllm.config import CONFIG_DIR


# config loader?
class ConfigService:
configPath = os.path.join(CONFIG_DIR, "config.toml")
config = None
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/crllm/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/crllm/model/provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
providers = {
"ollama": OllamaModel,
"azure": AzureModel,
"huggingface": HuggingFaceModel
"huggingface": HuggingFaceModel,
}
2 changes: 1 addition & 1 deletion src/crllm/model/provider/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/crllm/model/provider/huggingface.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
16 changes: 6 additions & 10 deletions src/crllm/prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 20b85bf

Please sign in to comment.