Skip to content

Commit

Permalink
Merge pull request #185 from VRSEN/dev/devid-predicted-outputs
Browse files Browse the repository at this point in the history
Dev/devid-predicted-outputs
  • Loading branch information
VRSEN authored Nov 11, 2024
2 parents fbf3cb6 + ca2f929 commit 3de9f27
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
44 changes: 32 additions & 12 deletions agency_swarm/agents/Devid/tools/FileWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def run(self):
if self.mode == "write":
message = f"Please write {filename} file that meets the following requirements: '{self.requirements}'.\n"
else:
message = f"Please rewrite the {filename} file according to the following requirements: '{self.requirements}'.\n"
message = f"Please rewrite the {filename} file according to the following requirements: '{self.requirements}'.\n Only output the file content, without any other text."

if file_dependencies:
message += f"\nHere are the dependencies from other project files: {file_dependencies}."
Expand All @@ -78,11 +78,11 @@ def run(self):

if self.mode == "modify":
message += f"\nThe existing file content is as follows:"

try:
with open(self.file_path, 'r') as file:
prev_content = file.read()
message += f"\n\n```{prev_content}```"
file_content = file.read()
message += f"\n\n```{file_content}```"
except Exception as e:
return f'Error reading {self.file_path}: {e}'

Expand All @@ -102,11 +102,22 @@ def run(self):
n = 0
error_message = ""
while n < 3:
resp = client.chat.completions.create(
messages=messages,
model="gpt-4o",
temperature=0,
)
if self.mode == "modify":
resp = client.chat.completions.create(
messages=messages,
model="gpt-4o",
temperature=0,
prediction={
"type": "content",
"content": file_content
}
)
else:
resp = client.chat.completions.create(
messages=messages,
model="gpt-4o",
temperature=0,
)

content = resp.choices[0].message.content

Expand Down Expand Up @@ -236,9 +247,18 @@ def validate_documentation(cls, v):


if __name__ == "__main__":
tool = FileWriter(
# Test case for 'write' mode
tool_write = FileWriter(
requirements="Write a program that takes a list of integers as input and returns the sum of all the integers in the list.",
mode="write",
file_path="test.py",
file_path="test_write.py",
)
print(tool_write.run())

# Test case for 'modify' mode
tool_modify = FileWriter(
requirements="Modify the program to also return the product of all the integers in the list.",
mode="modify",
file_path="test_write.py",
)
print(tool.run())
print(tool_modify.run())
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ classifiers = [
"License :: OSI Approved :: MIT License",
]
dependencies = [
"openai==1.51.2",
"openai==1.54.3",
"docstring_parser==0.16",
"pydantic==2.8.2",
"datamodel-code-generator==0.26.1",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openai==1.51.2
openai==1.54.3
docstring_parser==0.16
pydantic==2.8.2
datamodel-code-generator==0.26.1
Expand Down

0 comments on commit 3de9f27

Please sign in to comment.