Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factor extraction pipeline ready #16

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@ jobs:
- run: env | sort
- run: make dev
- env:
AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT: ${{ secrets.AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT }}
AZURE_DOCUMENT_INTELLIGENCE_KEY: ${{ secrets.AZURE_DOCUMENT_INTELLIGENCE_KEY }}
CHAT_AZURE_API_BASE: ${{ secrets.CHAT_AZURE_API_BASE }}
CHAT_AZURE_API_VERSION: ${{ secrets.CHAT_AZURE_API_VERSION }}
CHAT_MAX_TOKENS: ${{ secrets.CHAT_MAX_TOKENS }}
CHAT_MODEL: ${{ secrets.CHAT_MODEL }}
CHAT_OPENAI_API_KEY: ${{ secrets.CHAT_OPENAI_API_KEY }}
CHAT_TEMPERATURE: ${{ secrets.CHAT_TEMPERATURE }}
CONTINOUS_MODE: ${{ secrets.CONTINOUS_MODE }}
EMBEDDING_AZURE_API_BASE: ${{ secrets.CHAT_AZURE_API_BASE }}
EMBEDDING_AZURE_API_VERSION: ${{ secrets.CHAT_AZURE_API_VERSION }}
EMBEDDING_MODEL: ${{ secrets.EMBEDDING_MODEL }}
EMBEDDING_OPENAI_API_KEY: ${{ secrets.CHAT_OPENAI_API_KEY }}
MAX_RETRY: ${{ secrets.MAX_RETRY }}
RETRY_WAIT_SECONDS: ${{ secrets.RETRY_WAIT_SECONDS }}
USE_AZURE: ${{ secrets.USE_AZURE }}
name: lint test docs and build
run: make lint test docs build
strategy:
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,26 @@ constraints: deepclean

# Check lint with black.
black:
$(PIPRUN) python -m black --check . --exclude finco --extend-exclude test/scripts --extend-exclude git_ignore_folder -l 120
$(PIPRUN) python -m black --check . --extend-exclude test/scripts --extend-exclude git_ignore_folder -l 120

# Check lint with isort.
isort:
$(PIPRUN) python -m isort --check . -s FinCo -s finco -s git_ignore_folder -s test/scripts
$(PIPRUN) python -m isort --check . -s git_ignore_folder -s test/scripts

# Check lint with mypy.
mypy:
$(PIPRUN) python -m mypy . --exclude FinCo --exclude finco --exclude rdagent/scripts --exclude test/scripts --exclude git_ignore_folder

# Check lint with ruff.
ruff:
$(PIPRUN) ruff check . --exclude FinCo,finco,rdagent/scripts,test/scripts,git_ignore_folder
$(PIPRUN) ruff check . --exclude FinCo,finco,rdagent/scripts,test/scripts,git_ignore_folder --line-length 120

# Check lint with toml-sort.
toml-sort:
$(PIPRUN) toml-sort --check pyproject.toml

# Check lint with all linters.
lint: mypy ruff toml-sort
lint: black isort mypy ruff toml-sort

# Run pre-commit with autofix against all files.
pre-commit:
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ requires = [
"setuptools",
"setuptools-scm",
]
root= "rdagent"

[project]
authors = [
Expand Down Expand Up @@ -33,8 +34,6 @@ name = "rdagent"
readme = "README.md"
requires-python = ">=3.8"

[project.scripts]
rdagent-cli = "rdagent.cli:app"

[project.urls]
homepage = "https://github.com/microsoft/RD-Agent/"
Expand Down Expand Up @@ -99,7 +98,7 @@ select = ["ALL"]
"test/*" = ["S101"]

[tool.setuptools]
py-modules = ["rdagent"]
packages = ["rdagent"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
Expand Down
107 changes: 70 additions & 37 deletions rdagent/app/CI/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
from pathlib import Path
from typing import Dict, List, Tuple, Union, cast

from rich import print
from rich.panel import Panel
from rich.prompt import Prompt
from rich.rule import Rule
from rich.syntax import Syntax
from rich.table import Table
from rich.text import Text

from rdagent.core.evolving_framework import (
Evaluator,
EvoAgent,
Expand All @@ -21,13 +29,6 @@
Knowledge,
)
from rdagent.oai.llm_utils import APIBackend
from rich import print
from rich.panel import Panel
from rich.prompt import Prompt
from rich.rule import Rule
from rich.syntax import Syntax
from rich.table import Table
from rich.text import Text

from .prompts import (
linting_system_prompt_template,
Expand Down Expand Up @@ -64,7 +65,6 @@ def __init__(self, path: Union[Path, str]):
self.path = Path(path)
self.load()


def load(self) -> None:
code = self.path.read_text(encoding="utf-8")
self.code_lines = code.split("\n")
Expand All @@ -76,32 +76,31 @@ def load(self) -> None:
for i, code_line in enumerate(self.code_lines):
self.code_lines_with_lineno.append(f"{i+1: >{self.lineno_width}} | {code_line}")


def get(self, start = 0, end = None, add_line_number: bool = False, return_list: bool = False) -> Union[List[str], str]:
def get(self, start=0, end=None, add_line_number: bool = False, return_list: bool = False) -> Union[List[str], str]:
start -= 1
if start < 0: start = 0
end = self.lineno if end is None else end-1
if start < 0:
start = 0
end = self.lineno if end is None else end - 1

res = self.code_lines_with_lineno[start:end] if add_line_number else self.code_lines[start:end]

return res if return_list else "\n".join(res)


def apply_changes(self, changes: List[Tuple[int, int, str]]) -> None:
offset = 0
for start, end, code in changes:
start -= 1
if start < 0: start = 0
if start < 0:
start = 0
end -= 1

new_code = code.split("\n")
self.code_lines[start+offset:end+offset] = new_code
self.code_lines[start + offset : end + offset] = new_code
offset += len(new_code) - (end - start)

self.path.write_text("\n".join(self.code_lines), encoding="utf-8")
self.load()


def __str__(self):
return f"{self.path}"

Expand Down Expand Up @@ -151,6 +150,7 @@ class RuffRule:
"preview": false
}
"""

name: str
code: str
linter: str
Expand All @@ -172,7 +172,6 @@ def __init__(self, command: str = None):
else:
self.command = command


def explain_rule(self, error_code: str) -> RuffRule:
explain_command = "ruff rule {error_code} --output-format json"
try:
Expand All @@ -186,7 +185,6 @@ def explain_rule(self, error_code: str) -> RuffRule:

return json.loads(out.decode())


def evaluate(self, evo: Repo, **kwargs) -> CIFeedback:
"""Simply run ruff to get the feedbacks."""
try:
Expand Down Expand Up @@ -217,19 +215,21 @@ def evaluate(self, evo: Repo, **kwargs) -> CIFeedback:
errors = defaultdict(list)
for match in matches:
raw_str, file_path, line_number, column_number, error_code, error_message, error_hint = match
error = CIError(raw_str=raw_str,
file_path=file_path,
line=int(line_number),
column=int(column_number),
code=error_code,
msg=error_message,
hint=error_hint)
error = CIError(
raw_str=raw_str,
file_path=file_path,
line=int(line_number),
column=int(column_number),
code=error_code,
msg=error_message,
hint=error_hint,
)
errors[file_path].append(error)

return CIFeedback(errors=errors)

class MypyEvaluator(Evaluator):

class MypyEvaluator(Evaluator):
def __init__(self, command: str = None):
if command is None:
self.command = "mypy . --explicit-package-bases"
Expand All @@ -251,7 +251,6 @@ def evaluate(self, evo: Repo, **kwargs) -> CIFeedback:


class CIEvoStr(EvolvingStrategy):

def evolve(
self,
evo: Repo,
Expand Down Expand Up @@ -302,9 +301,23 @@ def evolve(

errors_str = "\n".join([f"{error.raw_str}\n" for error in group])

print(Panel.fit(Syntax("\n".join([f"{error.line}: {error.msg}" for error in group]), lexer="python", background_color="default"), title=f"{len(group)} Errors"))
print(
Panel.fit(
Syntax(
"\n".join([f"{error.line}: {error.msg}" for error in group]),
lexer="python",
background_color="default",
),
title=f"{len(group)} Errors",
)
)
# print(f"[bold yellow]original code:[/bold yellow]\n\n{code_snippet_with_lineno}")
print(Panel.fit(Syntax(code_snippet_with_lineno, lexer="python", background_color="default"), title="Original Code"))
print(
Panel.fit(
Syntax(code_snippet_with_lineno, lexer="python", background_color="default"),
title="Original Code",
)
)
user_prompt = session_normal_template.format(
code=code_snippet_with_lineno,
lint_info=errors_str,
Expand All @@ -321,10 +334,14 @@ def evolve(
table = Table(show_header=False, box=None)
table.add_column()
for i in diff:
if i.startswith("+"): table.add_row(Text(i, style="green"))
elif i.startswith("-"): table.add_row(Text(i, style="red"))
elif i.startswith("?"): table.add_row(Text(i, style="yellow"))
else: table.add_row(Syntax(i, lexer="python", background_color="default"))
if i.startswith("+"):
table.add_row(Text(i, style="green"))
elif i.startswith("-"):
table.add_row(Text(i, style="red"))
elif i.startswith("?"):
table.add_row(Text(i, style="yellow"))
else:
table.add_row(Syntax(i, lexer="python", background_color="default"))
print(Panel.fit(table, title="Repair Status"))

operation = input("Input your operation: ")
Expand Down Expand Up @@ -407,13 +424,29 @@ def evolve(

total_errors_count = skipped_errors_count + directly_fixed_errors_count + manually_fixed_errors_count
table.add_row("Total Errors", "", str(total_errors_count), "")
table.add_row("Skipped Errors", skipped_errors_statistics, str(skipped_errors_count), f"{skipped_errors_count / total_errors_count:.2%}")
table.add_row("Directly Fixed Errors", directly_fixed_errors_statistics, str(directly_fixed_errors_count), f"{directly_fixed_errors_count / total_errors_count:.2%}")
table.add_row("Manually Fixed Errors", manually_fixed_errors_statistics, str(manually_fixed_errors_count), f"{manually_fixed_errors_count / total_errors_count:.2%}")
table.add_row(
"Skipped Errors",
skipped_errors_statistics,
str(skipped_errors_count),
f"{skipped_errors_count / total_errors_count:.2%}",
)
table.add_row(
"Directly Fixed Errors",
directly_fixed_errors_statistics,
str(directly_fixed_errors_count),
f"{directly_fixed_errors_count / total_errors_count:.2%}",
)
table.add_row(
"Manually Fixed Errors",
manually_fixed_errors_statistics,
str(manually_fixed_errors_count),
f"{manually_fixed_errors_count / total_errors_count:.2%}",
)

print(table)
operation = Prompt.ask("Start next round? (y/n): ", choices=["y", "n"])
if operation == "n": break
if operation == "n":
break


end_time = time.time()
Expand Down
Loading
Loading