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

Dev -> Main v0.0.9 #890

Merged
merged 101 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
e7026c3
first commit
Aryan-Singh-14 Jul 11, 2023
898c75f
instagram APIs implemented and AI generated caption utility added
Aryan-Singh-14 Jul 13, 2023
fce5808
Image upload to S3 and URL generation added
Aryan-Singh-14 Jul 14, 2023
ac457a5
added upload to s3 instagram bucket
Aryan-Singh-14 Jul 18, 2023
0ab34be
Merge branch 'dev' into instagram_tool
Aryan-Singh-14 Jul 18, 2023
59a95ed
fixing the send email attachement issue
Jul 18, 2023
35b5bc4
fixing schedule agent run
Jul 18, 2023
2551e8f
Refactored code
Aryan-Singh-14 Jul 19, 2023
281753f
Resource duplicate fix (#803)
luciferlinx101 Jul 19, 2023
6f3deb4
removed jpeg files used for testing
Aryan-Singh-14 Jul 19, 2023
c697937
Dalle fix (#812)
Tarraann Jul 19, 2023
2889187
fixed recurring run issues
Aryan-Singh-14 Jul 20, 2023
9f0a78d
Supercoder Improve tool addition (#755)
Autocop-Agent Jul 20, 2023
e37014e
fixed recurring issues
Aryan-Singh-14 Jul 20, 2023
0937ba5
Edit agent templates (#793)
anisha1607 Jul 20, 2023
ded659c
Readme added
Aryan-Singh-14 Jul 20, 2023
3708a30
instabot config folder deleted
Aryan-Singh-14 Jul 20, 2023
cdf3495
Read file s3 fix (#823)
luciferlinx101 Jul 20, 2023
0bb6000
refactored code
Aryan-Singh-14 Jul 20, 2023
1218fd6
Handled the case where stable diffusion generated multiple photos
Aryan-Singh-14 Jul 21, 2023
37bab8d
ui bug bash fixes
jedan2506 Jul 21, 2023
2607db3
docker compose.yaml version reverted to original
Aryan-Singh-14 Jul 21, 2023
9f6c045
removed the utility to add stable diffusion automatically
Aryan-Singh-14 Jul 21, 2023
e2dbae1
ui bug bash fixes
jedan2506 Jul 21, 2023
873a049
ui bug bash fixes
jedan2506 Jul 21, 2023
167c4bf
Edit agent templates fix (#838)
anisha1607 Jul 21, 2023
c76c453
ui bug bash fixes
jedan2506 Jul 21, 2023
8415dbe
Merge pull request #837 from TransformerOptimus/bugs_revamp_dev
nborthy Jul 21, 2023
b6587bf
added test cases and modified readme
Aryan-Singh-14 Jul 25, 2023
6595b1a
Frontend bugs (#849)
nborthy Jul 25, 2023
58355d3
Added instagram tool bucket entry in config_template.yaml
Aryan-Singh-14 Jul 25, 2023
bb0304f
added instagram tool bucket entry in config template
Aryan-Singh-14 Jul 25, 2023
e2c01bc
ui bug fixes
jedan2506 Jul 25, 2023
dab5ab7
Merge pull request #828 from TransformerOptimus/instagram_tool
Aryan-Singh-14 Jul 25, 2023
e57b8bc
ui bug fixes
jedan2506 Jul 25, 2023
802eeb1
ui bug fixes
jedan2506 Jul 25, 2023
de8189e
Merge pull request #853 from TransformerOptimus/apm_changes
nborthy Jul 25, 2023
1ea8d16
External repo support for marketplace (#847)
luciferlinx101 Jul 25, 2023
bddffb5
instagram image added
jedan2506 Jul 25, 2023
e3291fb
Merge pull request #856 from TransformerOptimus/instagram_pictures
nborthy Jul 25, 2023
84b593c
apm bug fixes
jedan2506 Jul 25, 2023
4b202ba
Dev rebase (#858)
nihiragarwal24 Jul 25, 2023
eca6e6d
apm bug fixes
jedan2506 Jul 25, 2023
8eeaca4
apm bug fixes
jedan2506 Jul 25, 2023
6392966
Merge pull request #859 from TransformerOptimus/instagram_pictures
nborthy Jul 25, 2023
97c5ee9
Docker image (#836)
Fluder-Paradyne Jul 25, 2023
b638d37
handled resource path change (#861)
Aryan-Singh-14 Jul 26, 2023
fdadbf0
Updated Expiry Time backward fix
luciferlinx101 Jul 26, 2023
a2d8e5e
Merge pull request #864 from TransformerOptimus/jwt-expiry-backward-fix
nborthy Jul 26, 2023
e105b2e
readme toolkit fix (#867)
luciferlinx101 Jul 26, 2023
d9c942f
Knowledge frontend (#860)
nborthy Jul 26, 2023
800bb30
Fixed Delete Agent Bug (#830)
anisha1607 Jul 26, 2023
20dfa29
close button fix
NishantBorthakur Jul 26, 2023
73fff67
Merge branch 'dev_fixes' of github.com:TransformerOptimus/SuperAGI in…
jedan2506 Jul 26, 2023
3fea732
refactor
NishantBorthakur Jul 26, 2023
799417e
centralise prevent default
NishantBorthakur Jul 26, 2023
b124288
Merge branch 'dev_fixes' of github.com:TransformerOptimus/SuperAGI in…
jedan2506 Jul 26, 2023
0ebd563
app.css fixes
jedan2506 Jul 26, 2023
c1f9ab9
Dev fixes (#869)
jedan2506 Jul 26, 2023
9973567
close icon issue
NishantBorthakur Jul 26, 2023
5707bdb
resolving conflcits
NishantBorthakur Jul 26, 2023
f74b781
Merge pull request #872 from TransformerOptimus/dev_fixes
nborthy Jul 26, 2023
ae6e620
Added tools.json (#868)
luciferlinx101 Jul 26, 2023
030e886
Updated Chat completion for tool selection prompt
luciferlinx101 Jul 26, 2023
9326e6c
Updated Prompt
luciferlinx101 Jul 26, 2023
32e31c0
Bug fixes afternoon (#875)
jedan2506 Jul 26, 2023
6eeb7f6
Docker image (#876)
Fluder-Paradyne Jul 26, 2023
b798985
Final knowledge backend (#870)
Tarraann Jul 26, 2023
caad111
very minor fix for naming
Jul 26, 2023
98ee15a
Merge pull request #877 from TransformerOptimus/minor_fix_knowledge
Tarraann Jul 26, 2023
4356fbc
Changes for HTTP EXception in Knowledge Controller
Jul 27, 2023
73efa91
HTTP changes for vector_dbs
Jul 27, 2023
db80c8c
Bug fixes afternoon (#878)
jedan2506 Jul 27, 2023
4c06c1d
Refactoring of vector embedding
Jul 27, 2023
f149e9b
adding of knowledge logo
namansleeps2 Jul 27, 2023
75930b2
Delete HTTP fixed
Jul 27, 2023
2d52781
Merge remote-tracking branch 'origin/knowledge_logo' into http_knowledge
Jul 27, 2023
a876859
Updated prompt
luciferlinx101 Jul 27, 2023
a59a1b6
changes in tests
Jul 27, 2023
d6bf83c
changes
Jul 27, 2023
7bc8e81
Merge pull request #882 from TransformerOptimus/prompt-fix
Jul 27, 2023
5085269
changes
Jul 27, 2023
129e00d
args fix in dalle
Jul 27, 2023
4672c07
bug fix
luciferlinx101 Jul 27, 2023
79928cb
Merge pull request #884 from TransformerOptimus/prompt-fix
Tarraann Jul 27, 2023
2fe3f0d
Merge remote-tracking branch 'origin/dev' into dalle_args_fix
Jul 27, 2023
1de727f
minor change
Jul 27, 2023
e440d63
Merge pull request #883 from TransformerOptimus/dalle_args_fix
Tarraann Jul 27, 2023
d80920e
Merge pull request #881 from TransformerOptimus/http_knowledge
Tarraann Jul 27, 2023
edec2f5
minor changes
namansleeps2 Jul 27, 2023
6a0df87
Merge pull request #885 from TransformerOptimus/knowledge_changes
Tarraann Jul 27, 2023
b901801
fixes (#886)
Tarraann Jul 27, 2023
98312be
the user will now be unable to select striked knowledges
namansleeps2 Jul 27, 2023
a1f2abe
minor fix
namansleeps2 Jul 27, 2023
bb27d3f
Merge pull request #888 from TransformerOptimus/minor_changes_launch
namansleeps Jul 27, 2023
a16526d
Fix for agent details - not fetching data
Jul 27, 2023
08d8ba1
minor change for details
Jul 27, 2023
7dfbe3a
Fixes
Jul 27, 2023
bb308fc
Merge pull request #889 from TransformerOptimus/agent_detail_fix
anisha1607 Jul 27, 2023
de12454
conflict resolved
luciferlinx101 Jul 27, 2023
d978a6a
Merge pull request #892 from TransformerOptimus/conflict-resolve-dev
nborthy Jul 27, 2023
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
Prev Previous commit
Next Next commit
Supercoder Improve tool addition (#755)
  • Loading branch information
Autocop-Agent authored Jul 20, 2023
commit 9f0a78df6a38e7f336ce807270218d66f9703d07
41 changes: 33 additions & 8 deletions superagi/resource_manager/file_manager.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import csv

from sqlalchemy.orm import Session

import os
from superagi.helper.resource_helper import ResourceHelper
from superagi.helper.s3_helper import S3Helper
from superagi.lib.logger import logger
from superagi.models.agent import Agent
from superagi.models.agent_execution import AgentExecution
from superagi.types.storage_types import StorageType


class FileManager:
def __init__(self, session: Session, agent_id: int = None, agent_execution_id: int = None):
self.session = session
self.agent_id = agent_id
self.agent_execution_id = agent_execution_id

def write_binary_file(self, file_name: str, data):
if self.agent_id is not None:
final_path = ResourceHelper.get_agent_write_resource_path(file_name,
Expand All @@ -35,7 +31,6 @@ def write_binary_file(self, file_name: str, data):
return f"Binary {file_name} saved successfully"
except Exception as err:
return f"Error write_binary_file: {err}"

def write_to_s3(self, file_name, final_path):
with open(final_path, 'rb') as img:
resource = ResourceHelper.make_written_file_resource(file_name=file_name,
Expand Down Expand Up @@ -68,7 +63,6 @@ def write_file(self, file_name: str, content):
return f"{file_name} - File written successfully"
except Exception as err:
return f"Error write_file: {err}"

def write_csv_file(self, file_name: str, csv_data):
if self.agent_id is not None:
final_path = ResourceHelper.get_agent_write_resource_path(file_name,
Expand All @@ -79,7 +73,6 @@ def write_csv_file(self, file_name: str, csv_data):
self.agent_execution_id))
else:
final_path = ResourceHelper.get_resource_path(file_name)

try:
with open(final_path, mode="w") as file:
writer = csv.writer(file, lineterminator="\n")
Expand All @@ -90,10 +83,42 @@ def write_csv_file(self, file_name: str, csv_data):
return f"{file_name} - File written successfully"
except Exception as err:
return f"Error write_csv_file: {err}"


def get_agent_resource_path(self, file_name: str):
return ResourceHelper.get_agent_write_resource_path(file_name, agent=Agent.get_agent_from_id(self.session,
self.agent_id),
agent_execution=AgentExecution
.get_agent_execution_from_id(self.session,
self.agent_execution_id))
def read_file(self, file_name: str):
if self.agent_id is not None:
final_path = self.get_agent_resource_path(file_name)
else:
final_path = ResourceHelper.get_resource_path(file_name)

try:
with open(final_path, mode="r") as file:
content = file.read()
logger.info(f"{file_name} - File read successfully")
return content
except Exception as err:
return f"Error while reading file {file_name}: {err}"
def get_files(self):
"""
Gets all file names generated by the CodingTool.
Returns:
A list of file names.
"""

if self.agent_id is not None:
final_path = self.get_agent_resource_path("")
else:
final_path = ResourceHelper.get_resource_path("")
try:
# List all files in the directory
files = os.listdir(final_path)
except Exception as err:
logger.error(f"Error while accessing files in {final_path}: {err}")
files = []
return files
3 changes: 2 additions & 1 deletion superagi/tools/code/coding_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from superagi.tools.code.write_code import CodingTool
from superagi.tools.code.write_spec import WriteSpecTool
from superagi.tools.code.write_test import WriteTestTool
from superagi.tools.code.improve_code import ImproveCodeTool


class CodingToolkit(BaseToolkit, ABC):
name: str = "CodingToolkit"
description: str = "Coding Tool kit contains all tools related to coding tasks"

def get_tools(self) -> List[BaseTool]:
return [CodingTool(), WriteSpecTool(), WriteTestTool()]
return [CodingTool(), WriteSpecTool(), WriteTestTool(), ImproveCodeTool()]

def get_env_keys(self) -> List[str]:
return []
99 changes: 99 additions & 0 deletions superagi/tools/code/improve_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import re
from typing import Type, Optional, List

from pydantic import BaseModel, Field

from superagi.agent.agent_prompt_builder import AgentPromptBuilder
from superagi.helper.prompt_reader import PromptReader
from superagi.helper.token_counter import TokenCounter
from superagi.lib.logger import logger
from superagi.llms.base_llm import BaseLlm
from superagi.resource_manager.file_manager import FileManager
from superagi.tools.base_tool import BaseTool
from superagi.tools.tool_response_query_manager import ToolResponseQueryManager


class ImproveCodeSchema(BaseModel):
pass


class ImproveCodeTool(BaseTool):
"""
Used to improve the already generated code by reading the code from the files

Attributes:
llm: LLM used for code generation.
name : The name of the tool.
description : The description of the tool.
resource_manager: Manages the file resources.
"""
llm: Optional[BaseLlm] = None
agent_id: int = None
name = "ImproveCodeTool"
description = (
"This tool improves the generated code."
)
args_schema: Type[ImproveCodeSchema] = ImproveCodeSchema
resource_manager: Optional[FileManager] = None
tool_response_manager: Optional[ToolResponseQueryManager] = None
goals: List[str] = []

class Config:
arbitrary_types_allowed = True

def _execute(self) -> str:
"""
Execute the improve code tool.

Returns:
Improved code or error message.
"""
# Get all file names that the CodingTool has written
file_names = self.resource_manager.get_files()
logger.info(file_names)
# Loop through each file
for file_name in file_names:
if '.txt' not in file_name and '.sh' not in file_name and '.json' not in file_name:
# Read the file content
content = self.resource_manager.read_file(file_name)

# Generate a prompt from improve_code.txt
prompt = PromptReader.read_tools_prompt(__file__, "improve_code.txt")

# Combine the hint from the file, goals, and content
prompt = prompt.replace("{goals}", AgentPromptBuilder.add_list_items_to_string(self.goals))
prompt = prompt.replace("{content}", content)

# Add the file content to the chat completion prompt
prompt = prompt + "\nOriginal Code:\n```\n" + content + "\n```"



# Use LLM to generate improved code
result = self.llm.chat_completion([{'role': 'system', 'content': prompt}])

# Extract the response first
response = result.get('response')
if not response:
logger.info("RESPONSE NOT AVAILABLE")

# Now extract the choices from response
choices = response.get('choices')
if not choices:
logger.info("CHOICES NOT AVAILABLE")

# Now you can safely extract the message content
improved_content = choices[0]["message"]["content"]
# improved_content = result["messages"][0]["content"]
parsed_content = re.findall("```(?:\w*\n)?(.*?)```", improved_content, re.DOTALL)
parsed_content_code = "\n".join(parsed_content)

# Rewrite the file with the improved content
save_result = self.resource_manager.write_file(file_name, parsed_content_code)

if save_result.startswith("Error"):
return save_result
else:
continue

return f"All codes improved and saved successfully in: " + " ".join(file_names)
26 changes: 26 additions & 0 deletions superagi/tools/code/prompts/improve_code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
You are a super smart developer. You have been tasked with fixing and filling the function and classes where only the description of code is written without the actual code . There might be placeholders in the code you have to fill in.
You provide fully functioning, well formatted code with few comments, that works and has no bugs.
If the code is already correct and doesn't need change, just return the same code
However, make sure that you only return the improved code, without any additional content.


Please structure the improved code as follows:

```
CODE
```

Please return the full new code in same format as the original code
Don't write any explanation or description in your response other than the actual code

Your high-level goal is:
{goals}

The content of the file you need to improve is:
{content}

Only return the code and not any other line

To start, first analyze the existing code. Check for any function with missing logic inside it and fill the function.
Make sure, that not a single function is empty or contains just comments, there should be function logic inside it
Return fully completed functions by filling the placeholders
2 changes: 1 addition & 1 deletion superagi/tools/code/prompts/write_code.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
You are a super smart developer who practices good Development for writing code according to a specification.
Please note that the code should be fully functional. There should be no placeholder in functions or classes in any file.

Your high-level goal is:
{goals}
Expand All @@ -23,7 +24,6 @@ Each file must strictly follow a markdown code block format, where the following
```

You will start with the "entrypoint" file, then go to the ones that are imported by that file, and so on.
Please note that the code should be fully functional. No placeholders.

Follow a language and framework appropriate best practice file naming convention.
Make sure that files contain all imports, types etc. Make sure that code in different files are compatible with each other.
Expand Down
4 changes: 3 additions & 1 deletion superagi/tools/code/write_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CodingTool(BaseTool):
"Make sure that every detail of the architecture is, in the end, implemented as code. "
"Think step by step and reason yourself to the right decisions to make sure we get it right. "
"You will first lay out the names of the core classes, functions, methods that will be necessary, "
"as well as a quick comment on their purpose. Then you will output the content of each file including ALL code."
"as well as a quick comment on their purpose. Then you will output the content of each file including each function and class and ALL code."
)
args_schema: Type[CodingSchema] = CodingSchema
goals: List[str] = []
Expand Down Expand Up @@ -84,6 +84,8 @@ def _execute(self, code_description: str) -> str:
for match in matches:
# Get the filename
file_name = re.sub(r'[<>"|?*]', "", match.group(1))
if not file_name[0].isalnum():
file_name = file_name[1:-1]

# Get the code
code = match.group(2)
Expand Down
52 changes: 52 additions & 0 deletions tests/unit_tests/tools/code/test_improve_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest
from unittest.mock import Mock, MagicMock
from superagi.tools.code.improve_code import ImproveCodeTool

@pytest.fixture
def mock_improve_code_tool():
improve_code_tool = ImproveCodeTool()
improve_code_tool.resource_manager = Mock()
improve_code_tool.llm = Mock()
return improve_code_tool

def test_execute(mock_improve_code_tool):
mock_improve_code_tool.resource_manager.get_files.return_value = ['test1', 'test2']
mock_improve_code_tool.resource_manager.read_file.return_value = "test file content"
mock_improve_code_tool.llm.chat_completion.return_value = {
"response":
{
"choices":
[
{
"message":
{
"content": "```\nimproved code\n```"
}
}
]
}
}
mock_improve_code_tool.resource_manager.write_file.return_value = "file saved successfully"

assert mock_improve_code_tool._execute() == "All codes improved and saved successfully in: test1 test2"

def test_execute_with_error(mock_improve_code_tool):
mock_improve_code_tool.resource_manager.get_files.return_value = ['test1']
mock_improve_code_tool.resource_manager.read_file.return_value = "test file content"
mock_improve_code_tool.llm.chat_completion.return_value = {
"response":
{
"choices":
[
{
"message":
{
"content": "```\nimproved code\n```"
}
}
]
}
}
mock_improve_code_tool.resource_manager.write_file.return_value = "Error: Could not save file"

assert mock_improve_code_tool._execute() == "Error: Could not save file"