Skip to content

Commit

Permalink
schemq
Browse files Browse the repository at this point in the history
  • Loading branch information
Kye committed Apr 8, 2024
1 parent 19b59e8 commit 92f9d08
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
Empty file added errors.txt
Empty file.
63 changes: 63 additions & 0 deletions neo_sapiens/hass_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from pydantic import BaseModel, Field
from typing import List
from swarms.utils.json_utils import base_model_to_json

class AgentSchema(BaseModel):
name: str = Field(
...,
title="Name of the agent",
)
system_prompt: str = Field(
...,
title = "System prompt for the agent",
)


class HassSchema(BaseModel):
plan: List[str] = Field(
...,
title="Plan to solve the input problem",
)
number_of_agents: int = Field(
...,
title="Number of agents to use for the problem",
)

agents: List[AgentSchema] = Field(
...,
title="List of agents to use for the problem",
)



json = HassSchema.model_json_schema()
json = base_model_to_json(HassSchema)
# print(json)



def parse_hass_schema(data: str) -> tuple:
parsed_data = eval(data)
hass_schema = HassSchema(**parsed_data)
return hass_schema.plan, hass_schema.number_of_agents, hass_schema.agents

# Example usage
data = '''
{
"plan": ["Step 1", "Step 2", "Step 3"],
"number_of_agents": 5,
"agents": [
{
"name": "Agent 1",
"system_prompt": "Prompt 1"
},
{
"name": "Agent 2",
"system_prompt": "Prompt 2"
}
]
}
'''

parsed_schema = parse_hass_schema(data)
print(parsed_schema)
100 changes: 100 additions & 0 deletions neo_sapiens/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,101 @@
from swarms import Agent, Anthropic, tool, OpenAIChat
import subprocess

# Model
llm = OpenAIChat()

# Tools
@tool
def terminal(
code: str,
):
"""
Run code in the terminal.
Args:
code (str): The code to run in the terminal.
Returns:
str: The output of the code.
"""
out = subprocess.run(
code, shell=True, capture_output=True, text=True
).stdout
return str(out)


@tool
def browser(query: str):
"""
Search the query in the browser with the `browser` tool.
Args:
query (str): The query to search in the browser.
Returns:
str: The search results.
"""
import webbrowser

url = f"https://www.google.com/search?q={query}"
webbrowser.open(url)
return f"Searching for {query} in the browser."

@tool
def create_file(file_path: str, content: str):
"""
Create a file using the file editor tool.
Args:
file_path (str): The path to the file.
content (str): The content to write to the file.
Returns:
str: The result of the file creation operation.
"""
with open(file_path, "w") as file:
file.write(content)
return f"File {file_path} created successfully."

@tool
def file_editor(file_path: str, mode: str, content: str):
"""
Edit a file using the file editor tool.
Args:
file_path (str): The path to the file.
mode (str): The mode to open the file in.
content (str): The content to write to the file.
Returns:
str: The result of the file editing operation.
"""
with open(file_path, mode) as file:
file.write(content)
return f"File {file_path} edited successfully."


# Agent
agent = Agent(
agent_name="Neo Sapien orchestrator",
system_prompt=(
"Autonomous agent that can interact with humans and other"
" agents. Be Helpful and Kind. Use the tools provided to"
" assist the user. Return all code in markdown format."
),
llm=llm,
max_loops="auto",
autosave=True,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
interactive=True,
tools=[terminal, browser, file_editor, create_file],
code_interpreter=True,
# streaming=True,
)

# Run the agent
out = agent("Create a new file for a plan to take over the world.")
print(out)

0 comments on commit 92f9d08

Please sign in to comment.