Skip to content

Commit

Permalink
Added predicted outputs to file writer
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Nov 7, 2024
1 parent 260dce6 commit 7390e8b
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions agency_swarm/agents/Devid/tools/FileWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 7390e8b

Please sign in to comment.