Skip to content

Commit 2582c3d

Browse files
committed
Linter agent (WIP)
1 parent 81a340e commit 2582c3d

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

code_it/agents/linter.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from code_it.agents.base import BaseAgent
2+
3+
4+
class Linter(BaseAgent):
5+
def __init__(self, llm) -> None:
6+
super().__init__(llm)
7+
self.start_string = "NewCode:"
8+
self.stop_string = "ExistingSourceCode:"
9+
self.prompt_template = """"You're AI tool that applies a linter to a Python Code and fixes the issues found. Think step-by-step.
10+
You should fulfill your role like in the example below:
11+
12+
ExistingSourceCode:
13+
import os
14+
import os
15+
files = os.listdir()
16+
************* Module persistent_source
17+
persistent_source.py:3:0: C0304: Final newline missing (missing-final-newline)
18+
persistent_source.py:1:0: C0114: Missing module docstring (missing-module-docstring)
19+
persistent_source.py:2:0: W0404: Reimport 'os' (imported line 1) (reimported)
20+
21+
------------------------------------------------------------------
22+
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
23+
24+
25+
Programmer AI: I need to perform some modifications on the source code
26+
1. There is a misssing newline.
27+
2. Missing module docstring, I should add one
28+
3. There are duplicated imports, I should remove one
29+
NewCode:
30+
\"\"\"Module to list files in current directory \"\"\"
31+
import os
32+
files = os.listdir()
33+
34+
ExistingSourceCode:
35+
36+
Notice that you once you finish the subtask, you should add the word 'ExistingSourceCode:' in a new line,
37+
like in the example above.
38+
39+
Now please help with the subtask below.
40+
41+
ExistingSourceCode: {source_code}
42+
Lint Stdout: {stdout}
43+
Programmer AI:
44+
"""
45+
46+
def parse_output(self, result):
47+
print("Linter result", result)
48+
if self.stop_string not in result:
49+
result = result.split(self.stop_string)[0]
50+
51+
if self.start_string not in result:
52+
return None
53+
54+
result = result.split(self.start_string)[1]
55+
print("Parsed linter", result)
56+
return result

code_it/task_executor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,17 @@ def execute(self, task: str):
8989
for _ in range(self.config.dependency_samples):
9090
dep = self.dependency_tracker.execute_task(plan="\n".join(plan))
9191
for d in dep:
92-
d = d.replace("-", "")
93-
if d in DEPENDENCY_BLACKLIST:
92+
d = d.replace("-", "").strip()
93+
if " " in d:
94+
d = d.split(" ")[0]
95+
96+
if len(d) < 2 or d in DEPENDENCY_BLACKLIST:
9497
continue
9598
dependencies.append(d)
9699

100+
if not dependencies:
101+
break
102+
97103
dependencies = list(set(dependencies))
98104
logger.info("Dependencies: %s", dependencies)
99105

task.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
Your job is to plot an example chart using matplotlib. Create your own random data.
2-
Run this code only when you're finished.
3-
DO NOT add code and run into a single step.
1+
Your job is to generate cat jokes and save in a file called 'cat_jokes.txt'. Be creative!

task_chuck_norris.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Question: The endpoint https://api.chucknorris.io/jokes/random returns a joke about Chuck Norries
2+
3+
1. Write a python Program that fetches a joke from this endpoint.
4+
2. Extract the joke from the response. Access the 'value' in the JSON to extract it.
5+
3. Prints the joke to the screen.

task_plot.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Your job is to plot an example chart using matplotlib. Create your own random data.
2+
Run this code only when you're finished.
3+
DO NOT add code and run into a single step.

0 commit comments

Comments
 (0)