Upload 2 files
Browse files- agent.py +90 -0
- agentllm.py +34 -0
agent.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from agentllm import AgGPT
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
class Agent:
|
| 6 |
+
|
| 7 |
+
def __init__(self, mission):
|
| 8 |
+
self.mission = mission
|
| 9 |
+
self.llm = AgGPT("agent.gguf")
|
| 10 |
+
self.mission_name = self.llm.ask("Based on this mission, create a one-word name for it. the mission is " + mission + " send a single word to identify the mission. send one word only.")
|
| 11 |
+
self.folder = f"agent/{self.mission_name}"
|
| 12 |
+
print(self.folder)
|
| 13 |
+
if not os.path.exists(self.folder):
|
| 14 |
+
os.makedirs(self.folder)
|
| 15 |
+
|
| 16 |
+
def create_file(self, name, content):
|
| 17 |
+
with open(f"{self.folder}/{name}", "w") as file:
|
| 18 |
+
file.write(content)
|
| 19 |
+
|
| 20 |
+
def summarize_file(self, path):
|
| 21 |
+
with open(path, "r") as file:
|
| 22 |
+
content = file.read()
|
| 23 |
+
summary = self.llm.ask("Summarize this text: " + content + " in 5 bullet points. send only the summary. ")
|
| 24 |
+
return summary
|
| 25 |
+
|
| 26 |
+
def get_full_project_summary(self):
|
| 27 |
+
files = [f for f in os.listdir(self.folder) if os.path.isfile(os.path.join(self.folder, f))]
|
| 28 |
+
summary = ""
|
| 29 |
+
for i, file in enumerate(files):
|
| 30 |
+
with open(os.path.join(self.folder, file), "r") as f:
|
| 31 |
+
content = f.read().strip()
|
| 32 |
+
if i > 0:
|
| 33 |
+
summary += "\n"
|
| 34 |
+
summary += f"{file} - {content}"
|
| 35 |
+
return summary
|
| 36 |
+
|
| 37 |
+
def deploy_agent(self):
|
| 38 |
+
system = f'''
|
| 39 |
+
You are an AI agent that can write files to the computer.
|
| 40 |
+
The files you have created so far are:
|
| 41 |
+
{self.get_full_project_summary()}
|
| 42 |
+
|
| 43 |
+
The project is called {self.mission_name} and the folder is called {self.folder}.
|
| 44 |
+
You must work on the README.md file and all other project files, you can only respond in this format:
|
| 45 |
+
{{
|
| 46 |
+
"file_name": "line1\\nline2\\nline3"
|
| 47 |
+
}}
|
| 48 |
+
if the file already exists it will be overwritten, for example if you want to overwrite the file README.md with the content "Hello World" you will respond with:
|
| 49 |
+
{{
|
| 50 |
+
"README.md": "Hello World"
|
| 51 |
+
}}
|
| 52 |
+
You will only respond with the JSON object, nothing else.
|
| 53 |
+
to create new files you will use the same format, for example if you want to create a new file called "test.txt" with the content "Hello World" you will respond with:
|
| 54 |
+
{{
|
| 55 |
+
"test.txt": "Hello World"
|
| 56 |
+
}}
|
| 57 |
+
You will only respond with the JSON object, nothing else.
|
| 58 |
+
The mission objective is: {self.mission}
|
| 59 |
+
continue working on the project. you may send more than one file name and content per response as follows:
|
| 60 |
+
{{
|
| 61 |
+
"README.md": "This is the README\\nIt has multiple lines\\nPretty cool, right?",
|
| 62 |
+
"main.py": "print('Hello, world!')\\ndef main():\\n return 42"
|
| 63 |
+
}}
|
| 64 |
+
continue the project.
|
| 65 |
+
|
| 66 |
+
Do not assume any module or library, you must create everything with the respective programming language.
|
| 67 |
+
create in the readme all the files you will create, and then create the files that you havent created yet. make sure the project is fully functional.
|
| 68 |
+
Make sure to write fucntional code and no placeholders, keep iterating.
|
| 69 |
+
'''
|
| 70 |
+
system += "\nRespond ONLY with the JSON. No explanation, no commentary, just raw JSON."
|
| 71 |
+
|
| 72 |
+
print(system)
|
| 73 |
+
|
| 74 |
+
response = self.llm.ask(system)
|
| 75 |
+
print(response)
|
| 76 |
+
try:
|
| 77 |
+
files_to_write = json.loads(response.strip())
|
| 78 |
+
except json.JSONDecodeError:
|
| 79 |
+
print("Error decoding JSON response. Please check the format.")
|
| 80 |
+
for file_name, content in files_to_write.items():
|
| 81 |
+
file_path = os.path.join(self.folder, file_name)
|
| 82 |
+
with open(file_path, 'w', encoding='utf-8') as f:
|
| 83 |
+
f.write(content)
|
| 84 |
+
|
| 85 |
+
self.deploy_agent()
|
| 86 |
+
|
| 87 |
+
if __name__ == "__main__":
|
| 88 |
+
mission = input("Enter your mission: ")
|
| 89 |
+
agent = Agent(mission)
|
| 90 |
+
agent.deploy_agent()
|
agentllm.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llama_cpp import Llama
|
| 2 |
+
|
| 3 |
+
class AgGPT:
|
| 4 |
+
def __init__(self, model_path):
|
| 5 |
+
self.model_path = model_path
|
| 6 |
+
self.model = Llama(model_path=model_path, n_ctx=4048, n_gpu_layers=35)
|
| 7 |
+
|
| 8 |
+
def run(self):
|
| 9 |
+
while True:
|
| 10 |
+
prompt = input("\nEnter your prompt: ")
|
| 11 |
+
|
| 12 |
+
messages = [
|
| 13 |
+
{"role": "system", "content": f"You are AgGPT-10, an AGI system. The user said: '{prompt}'."},
|
| 14 |
+
{"role": "user", "content": prompt}
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
output = self.model.create_chat_completion(messages, max_tokens=2050, temperature=0.7)
|
| 18 |
+
print(output["choices"][0]["message"]["content"])
|
| 19 |
+
|
| 20 |
+
def ask(self, question):
|
| 21 |
+
''' Ask AgGPT-10 a question and return the answer. '''
|
| 22 |
+
messages = [
|
| 23 |
+
{"role": "system", "content": f"You are AgGPT-10, an AGI system. The user said: '{question}'."},
|
| 24 |
+
{"role": "user", "content": question}
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
output = self.model.create_chat_completion(messages, max_tokens=2050, temperature=0.7)
|
| 28 |
+
|
| 29 |
+
return output["choices"][0]["message"]["content"]
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
model_path = "agent.gguf"
|
| 33 |
+
aggpt = AgGPT(model_path)
|
| 34 |
+
aggpt.run()
|