From 260dce6eb404e8c7c730fd4555745fd1b7bb0c77 Mon Sep 17 00:00:00 2001 From: Arsenii Shatokhin Date: Thu, 7 Nov 2024 10:45:32 +0400 Subject: [PATCH 1/3] bump openai --- pyproject.toml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 803be38f..17254123 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/requirements.txt b/requirements.txt index f2100dfe..6d7b06c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 From 7390e8bb08bef3985f0dc6b9fe3c1270d6dec84b Mon Sep 17 00:00:00 2001 From: Arsenii Shatokhin Date: Thu, 7 Nov 2024 10:57:42 +0400 Subject: [PATCH 2/3] Added predicted outputs to file writer --- agency_swarm/agents/Devid/tools/FileWriter.py | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/agency_swarm/agents/Devid/tools/FileWriter.py b/agency_swarm/agents/Devid/tools/FileWriter.py index e714fd51..f070fd0d 100644 --- a/agency_swarm/agents/Devid/tools/FileWriter.py +++ b/agency_swarm/agents/Devid/tools/FileWriter.py @@ -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}' @@ -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 @@ -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()) From ca2f929380d526195a772bb4bef66fce00ac31f1 Mon Sep 17 00:00:00 2001 From: Arsenii Shatokhin Date: Thu, 7 Nov 2024 11:01:45 +0400 Subject: [PATCH 3/3] Adjusted prompt when mode is modify --- agency_swarm/agents/Devid/tools/FileWriter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agency_swarm/agents/Devid/tools/FileWriter.py b/agency_swarm/agents/Devid/tools/FileWriter.py index f070fd0d..79b48b8d 100644 --- a/agency_swarm/agents/Devid/tools/FileWriter.py +++ b/agency_swarm/agents/Devid/tools/FileWriter.py @@ -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}."