Skip to content

Commit

Permalink
dockerfile running
Browse files Browse the repository at this point in the history
  • Loading branch information
kyegomez committed Nov 9, 2023
1 parent 371da79 commit 991979d
Show file tree
Hide file tree
Showing 103 changed files with 2,452 additions and 2,241 deletions.
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set environment variables to make Python output unbuffered and disable the PIP cache
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_NO_CACHE_DIR off
ENV PIP_DISABLE_PIP_VERSION_CHECK on
ENV PIP_DEFAULT_TIMEOUT 100

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy the current directory contents into the container at /usr/src/app
COPY . .

# Install Poetry
RUN pip install poetry

# Disable virtualenv creation by poetry and install dependencies
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-ansi

# Install the 'swarms' package if it's not included in the poetry.lock
RUN pip install swarms

# Assuming tests require pytest to run
RUN pip install pytest

# Run pytest on all tests in the tests directory
CMD find ./tests -name '*.py' -exec pytest {} +
2 changes: 1 addition & 1 deletion demos/ui_software_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Autonomous swarm that optimizes UI autonomously
GPT4Vision ->> GPT4 ->> UI
"""
"""
2 changes: 1 addition & 1 deletion swarms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
from swarms.agents import *
from swarms.swarms import *
from swarms.structs import *
from swarms.models import *
from swarms.models import *
from swarms.chunkers import *
from swarms.workers import *
1 change: 1 addition & 0 deletions swarms/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# from swarms.agents.idea_to_image_agent import Idea2Image
from swarms.agents.simple_agent import SimpleAgent

"""Agent Infrastructure, models, memory, utils, tools"""

__all__ = [
Expand Down
120 changes: 64 additions & 56 deletions swarms/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from langchain.chat_models.base import BaseChatModel
from langchain.memory import ChatMessageHistory
from langchain.prompts.chat import (
BaseChatPromptTemplate,)
BaseChatPromptTemplate,
)
from langchain.schema import (
BaseChatMessageHistory,
Document,
Expand Down Expand Up @@ -70,12 +71,14 @@ class AutoGPTPrompt(BaseChatPromptTemplate, BaseModel): # type: ignore[misc]
send_token_limit: int = 4196

def construct_full_prompt(self, goals: List[str]) -> str:
prompt_start = ("Your decisions must always be made independently "
"without seeking user assistance.\n"
"Play to your strengths as an LLM and pursue simple "
"strategies with no legal complications.\n"
"If you have completed all your tasks, make sure to "
'use the "finish" command.')
prompt_start = (
"Your decisions must always be made independently "
"without seeking user assistance.\n"
"Play to your strengths as an LLM and pursue simple "
"strategies with no legal complications.\n"
"If you have completed all your tasks, make sure to "
'use the "finish" command.'
)
# Construct full prompt
full_prompt = (
f"You are {self.ai_name}, {self.ai_role}\n{prompt_start}\n\nGOALS:\n\n"
Expand All @@ -87,23 +90,25 @@ def construct_full_prompt(self, goals: List[str]) -> str:
return full_prompt

def format_messages(self, **kwargs: Any) -> List[BaseMessage]:
base_prompt = SystemMessage(
content=self.construct_full_prompt(kwargs["goals"]))
base_prompt = SystemMessage(content=self.construct_full_prompt(kwargs["goals"]))
time_prompt = SystemMessage(
content=f"The current time and date is {time.strftime('%c')}")
used_tokens = self.token_counter(
base_prompt.content) + self.token_counter(time_prompt.content)
content=f"The current time and date is {time.strftime('%c')}"
)
used_tokens = self.token_counter(base_prompt.content) + self.token_counter(
time_prompt.content
)
memory: VectorStoreRetriever = kwargs["memory"]
previous_messages = kwargs["messages"]
relevant_docs = memory.get_relevant_documents(
str(previous_messages[-10:]))
relevant_docs = memory.get_relevant_documents(str(previous_messages[-10:]))
relevant_memory = [d.page_content for d in relevant_docs]
relevant_memory_tokens = sum(
[self.token_counter(doc) for doc in relevant_memory])
[self.token_counter(doc) for doc in relevant_memory]
)
while used_tokens + relevant_memory_tokens > 2500:
relevant_memory = relevant_memory[:-1]
relevant_memory_tokens = sum(
[self.token_counter(doc) for doc in relevant_memory])
[self.token_counter(doc) for doc in relevant_memory]
)
content_format = (
f"This reminds you of these events from your past:\n{relevant_memory}\n\n"
)
Expand Down Expand Up @@ -141,23 +146,13 @@ def __init__(self) -> None:
self.performance_evaluation: List[str] = []
self.response_format = {
"thoughts": {
"text":
"thought",
"reasoning":
"reasoning",
"plan":
"- short bulleted\n- list that conveys\n- long-term plan",
"criticism":
"constructive self-criticism",
"speak":
"thoughts summary to say to user",
},
"command": {
"name": "command name",
"args": {
"arg name": "value"
}
"text": "thought",
"reasoning": "reasoning",
"plan": "- short bulleted\n- list that conveys\n- long-term plan",
"criticism": "constructive self-criticism",
"speak": "thoughts summary to say to user",
},
"command": {"name": "command name", "args": {"arg name": "value"}},
}

def add_constraint(self, constraint: str) -> None:
Expand Down Expand Up @@ -195,9 +190,7 @@ def add_performance_evaluation(self, evaluation: str) -> None:
"""
self.performance_evaluation.append(evaluation)

def _generate_numbered_list(self,
items: list,
item_type: str = "list") -> str:
def _generate_numbered_list(self, items: list, item_type: str = "list") -> str:
"""
Generate a numbered list from given items based on the item_type.
Expand All @@ -215,11 +208,16 @@ def _generate_numbered_list(self,
for i, item in enumerate(items)
]
finish_description = (
"use this to signal that you have finished all your objectives")
finish_args = ('"response": "final response to let '
'people know you have finished your objectives"')
finish_string = (f"{len(items) + 1}. {FINISH_NAME}: "
f"{finish_description}, args: {finish_args}")
"use this to signal that you have finished all your objectives"
)
finish_args = (
'"response": "final response to let '
'people know you have finished your objectives"'
)
finish_string = (
f"{len(items) + 1}. {FINISH_NAME}: "
f"{finish_description}, args: {finish_args}"
)
return "\n".join(command_strings + [finish_string])
else:
return "\n".join(f"{i+1}. {item}" for i, item in enumerate(items))
Expand All @@ -240,7 +238,8 @@ def generate_prompt_string(self) -> str:
f"{self._generate_numbered_list(self.performance_evaluation)}\n\n"
"You should only respond in JSON format as described below "
f"\nResponse Format: \n{formatted_response_format} "
"\nEnsure the response can be parsed by Python json.loads")
"\nEnsure the response can be parsed by Python json.loads"
)

return prompt_string

Expand All @@ -261,11 +260,13 @@ def get_prompt(tools: List[BaseTool]) -> str:
prompt_generator.add_constraint(
"~16000 word limit for short term memory. "
"Your short term memory is short, "
"so immediately save important information to files.")
"so immediately save important information to files."
)
prompt_generator.add_constraint(
"If you are unsure how you previously did something "
"or want to recall past events, "
"thinking about similar events will help you remember.")
"thinking about similar events will help you remember."
)
prompt_generator.add_constraint("No user assistance")
prompt_generator.add_constraint(
'Exclusively use the commands listed in double quotes e.g. "command name"'
Expand All @@ -277,23 +278,29 @@ def get_prompt(tools: List[BaseTool]) -> str:

# Add resources to the PromptGenerator object
prompt_generator.add_resource(
"Internet access for searches and information gathering.")
"Internet access for searches and information gathering."
)
prompt_generator.add_resource("Long Term memory management.")
prompt_generator.add_resource(
"GPT-3.5 powered Agents for delegation of simple tasks.")
"GPT-3.5 powered Agents for delegation of simple tasks."
)
prompt_generator.add_resource("File output.")

# Add performance evaluations to the PromptGenerator object
prompt_generator.add_performance_evaluation(
"Continuously review and analyze your actions "
"to ensure you are performing to the best of your abilities.")
"to ensure you are performing to the best of your abilities."
)
prompt_generator.add_performance_evaluation(
"Constructively self-criticize your big-picture behavior constantly.")
"Constructively self-criticize your big-picture behavior constantly."
)
prompt_generator.add_performance_evaluation(
"Reflect on past decisions and strategies to refine your approach.")
"Reflect on past decisions and strategies to refine your approach."
)
prompt_generator.add_performance_evaluation(
"Every command has a cost, so be smart and efficient. "
"Aim to complete tasks in the least number of steps.")
"Aim to complete tasks in the least number of steps."
)

# Generate the prompt string
prompt_string = prompt_generator.generate_prompt_string()
Expand Down Expand Up @@ -364,8 +371,10 @@ def from_llm_and_tools(
)

def run(self, goals: List[str]) -> str:
user_input = ("Determine which next command to use, "
"and respond using the format specified above:")
user_input = (
"Determine which next command to use, "
"and respond using the format specified above:"
)
# Interaction Loop
loop_count = 0
while True:
Expand All @@ -382,10 +391,8 @@ def run(self, goals: List[str]) -> str:

# Print Assistant thoughts
print(assistant_reply)
self.chat_history_memory.add_message(
HumanMessage(content=user_input))
self.chat_history_memory.add_message(
AIMessage(content=assistant_reply))
self.chat_history_memory.add_message(HumanMessage(content=user_input))
self.chat_history_memory.add_message(AIMessage(content=assistant_reply))

# Get command name and arguments
action = self.output_parser.parse(assistant_reply)
Expand All @@ -411,7 +418,8 @@ def run(self, goals: List[str]) -> str:
result = (
f"Unknown command '{action.name}'. "
"Please refer to the 'COMMANDS' list for available "
"commands and only respond in the specified JSON format.")
"commands and only respond in the specified JSON format."
)

memory_to_add = f"Assistant Reply: {assistant_reply} \nResult: {result} "
if self.feedback_tool is not None:
Expand Down

0 comments on commit 991979d

Please sign in to comment.