flow dashboard with settings + simple agent example

pull/77/head
Kye 1 year ago
parent ac991872e4
commit ddf5356490

@ -1,21 +1,11 @@
message='Request to OpenAI API' method=post path=https://api.openai.com/v1/chat/completions
api_version=None data='{"messages": [{"role": "user", "content": "What were the winning boston marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times."}], "model": "gpt-3.5-turbo", "temperature": 0.5}' message='Post details'
api_version=None data='{"messages": [{"role": "user", "content": "Generate a 10,000 word blog on health and wellness."}], "model": "gpt-3.5-turbo", "temperature": 0.5}' message='Post details'
Converted retries value: 2 -> Retry(total=2, connect=None, read=None, redirect=None, status=None)
Starting new HTTPS connection (1): api.openai.com:443
https://api.openai.com:443 "POST /v1/chat/completions HTTP/1.1" 200 None
message='OpenAI API response' path=https://api.openai.com/v1/chat/completions processing_ms=4814 request_id=0efbc1770444395852146ea38fbb074f response_code=200
message='OpenAI API response' path=https://api.openai.com/v1/chat/completions processing_ms=15325 request_id=0f0244a70fe0d6dc3008761f9f2f8f82 response_code=200
message='Request to OpenAI API' method=post path=https://api.openai.com/v1/chat/completions
api_version=None data='{"messages": [{"role": "user", "content": "What were the winning boston marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times."}], "model": "gpt-3.5-turbo", "temperature": 0.5}' message='Post details'
https://api.openai.com:443 "POST /v1/chat/completions HTTP/1.1" 200 None
message='OpenAI API response' path=https://api.openai.com/v1/chat/completions processing_ms=3094 request_id=f791336dd4b081e0b13bdf54bf00471a response_code=200
message='Request to OpenAI API' method=post path=https://api.openai.com/v1/chat/completions
api_version=None data='{"messages": [{"role": "user", "content": "What were the winning boston marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times."}], "model": "gpt-3.5-turbo", "temperature": 0.5}' message='Post details'
https://api.openai.com:443 "POST /v1/chat/completions HTTP/1.1" 200 None
message='OpenAI API response' path=https://api.openai.com/v1/chat/completions processing_ms=3317 request_id=5aa8194828ba49ae72ab024d29180b1a response_code=200
message='Request to OpenAI API' method=post path=https://api.openai.com/v1/chat/completions
api_version=None data='{"messages": [{"role": "user", "content": "What were the winning boston marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times."}], "model": "gpt-3.5-turbo", "temperature": 0.5}' message='Post details'
https://api.openai.com:443 "POST /v1/chat/completions HTTP/1.1" 200 None
message='OpenAI API response' path=https://api.openai.com/v1/chat/completions processing_ms=4528 request_id=85b6182749870200b317958cd97c7206 response_code=200
api_version=None data='{"messages": [{"role": "user", "content": "Title: \\"Achieving Optimal Health and Wellness: A Comprehensive Guide to Transform Your Life\\"\\n\\nIntroduction (Word Count: 500)\\n\\nWelcome to our extensive guide on health and wellness, where we delve into the various aspects that contribute to a balanced and fulfilling life. In today\'s fast-paced world, it has become increasingly important to prioritize our well-being, both physically and mentally. This blog aims to provide you with valuable insights, practical tips, and evidence-based information to help you embark on a journey towards optimal health and wellness.\\n\\nTable of Contents:\\n\\n1. The Importance of Health and Wellness (Word Count: 800)\\n 1.1 Defining Health and Wellness\\n 1.2 Understanding the Mind-Body Connection\\n 1.3 The Benefits of Prioritizing Health and Wellness\\n\\n2. Nutrition and Diet (Word Count: 1,500)\\n 2.1 The Fundamentals of a Balanced Diet\\n 2.2 Exploring Macro and Micronutrients\\n 2.3 Superfoods: Unleashing the Power of Nutrient-Dense Foods\\n 2.4 Debunking Diet Myths\\n 2.5 The Role of Hydration in Overall Health\\n\\n3. Physical Fitness and Exercise (Word Count: 1,500)\\n 3.1 The Importance of Regular Physical Activity\\n 3.2 Different Types of Exercise and Their Benefits\\n 3.3 Creating an Effective Workout Routine\\n 3.4 Overcoming Barriers to Exercise\\n 3.5 The Role of Rest and Recovery in Fitness\\n\\n4. Mental Health and Well-being (Word Count: 1,500)\\n 4.1 Understanding Mental Health\\n 4.2 Strategies for Stress Management\\n 4.3 Promoting Emotional Well-being\\n 4.4 The Power of Mindfulness and Meditation\\n 4.5 Seeking Professional Help: Therapy and Counseling\\n\\n5. Sleep and its Impact on Health (Word Count: 1,200)\\n 5.1 The Science of Sleep\\n 5.2 Establishing Healthy Sleep Habits\\n 5.3 Tips for Better Sleep Quality\\n 5.4 Addressing Common Sleep Disorders\\n 5.5 The Link Between Sleep and Mental Health\\n\\n6. Building Healthy Relationships (Word Count: 1,200)\\n 6.1 The Importance of Social Connections\\n 6.2 Nurturing Meaningful Relationships\\n 6.3 Effective Communication Skills\\n 6.4 Setting Boundaries for Healthy Relationships\\n 6.5 Cultivating a Supportive Network\\n\\n7. Holistic Approaches to Health and Wellness (Word Count: 1,200)\\n 7.1 Exploring Alternative Therapies\\n 7.2 Integrating Traditional Medicine with Complementary Practices\\n 7.3 The Benefits of Yoga and Tai Chi\\n 7.4 Harnessing the Power of Aromatherapy and Essential Oils\\n 7.5 Embracing Nature: Ecotherapy and Outdoor Activities\\n\\n8. Preventive Health Measures (Word Count: 1,000)\\n 8.1 Regular Health Check-ups and Screenings\\n 8.2 Vaccinations and Immunizations\\n 8.3 Preventing Chronic Diseases through Lifestyle Changes\\n 8.4 Understanding the Importance of Hygiene\\n 8.5 Promoting Workplace Health and Safety\\n\\nConclusion (Word Count: 300)\\n\\nIn conclusion, achieving optimal health and wellness is a lifelong journey that requires commitment, self-awareness, and continuous learning. By incorporating the principles discussed in this comprehensive guide into your daily life, you can take significant strides towards enhancing your well-being, finding balance, and living a more fulfilled life. Remember, small steps can lead to significant transformations, and prioritizing your health is an investment that yields lifelong rewards."}], "model": "gpt-3.5-turbo", "temperature": 0.5}' message='Post details'
Error in sys.excepthook:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/humbug/report.py", line 505, in _hook
@ -26,7 +16,95 @@ TypeError: format_exception() got an unexpected keyword argument 'etype'
Original exception was:
Traceback (most recent call last):
File "/Users/defalt/Desktop/Athena/research/swarms/multi_agent_debate.py", line 27, in <module>
print(f"Agent {result['agent']} responded: {result['response']}")
~~~~~~^^^^^^^^^
KeyError: 'agent'
File "/Users/defalt/Desktop/Athena/research/swarms/simple_agent.py", line 24, in <module>
out = agent.run("Generate a 10,000 word blog on health and wellness.")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/defalt/Desktop/Athena/research/swarms/swarms/agents/simple_agent.py", line 18, in run
response = self.flow.run(task)
^^^^^^^^^^^^^^^^^^^
File "/Users/defalt/Desktop/Athena/research/swarms/swarms/structs/flow.py", line 158, in run
response = self.llm(response)
^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/llms/base.py", line 802, in __call__
self.generate(
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/llms/base.py", line 598, in generate
output = self._generate_helper(
^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/llms/base.py", line 504, in _generate_helper
raise e
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/langchain/llms/base.py", line 491, in _generate_helper
self._generate(
File "/Users/defalt/Desktop/Athena/research/swarms/swarms/models/openai_models.py", line 882, in _generate
full_response = completion_with_retry(
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/defalt/Desktop/Athena/research/swarms/swarms/models/openai_models.py", line 114, in completion_with_retry
return _completion_with_retry(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tenacity/__init__.py", line 289, in wrapped_f
return self(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tenacity/__init__.py", line 379, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tenacity/__init__.py", line 314, in iter
return fut.result()
^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/tenacity/__init__.py", line 382, in __call__
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/Users/defalt/Desktop/Athena/research/swarms/swarms/models/openai_models.py", line 112, in _completion_with_retry
return llm.client.create(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/chat_completion.py", line 25, in create
return super().create(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_requestor.py", line 288, in request
result = self.request_raw(
^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_requestor.py", line 596, in request_raw
result = _thread_context.session.request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
resp = conn.urlopen(
^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/urllib3/connectionpool.py", line 449, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/urllib3/connectionpool.py", line 444, in _make_request
httplib_response = conn.getresponse()
^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1374, in getresponse
response.begin()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 318, in begin
version, status, reason = self._read_status()
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 279, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/socket.py", line 705, in readinto
return self._sock.recv_into(b)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1278, in recv_into
return self.read(nbytes, buffer)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1134, in read
return self._sslobj.read(len, buffer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

@ -0,0 +1,25 @@
from swarms.agents.simple_agent import SimpleAgent
from swarms.structs import Flow
from swarms.models import OpenAIChat
api_key = ""
llm = OpenAIChat(
openai_api_key=api_key,
temperature=0.5,
)
# Initialize the flow
flow = Flow(
llm=llm,
max_loops=5,
)
agent = SimpleAgent(
name="Optimus Prime",
flow=flow,
)
out = agent.run("Generate a 10,000 word blog on health and wellness.")
print(out)

@ -5,10 +5,10 @@ from swarms.agents.stream_response import stream
from swarms.agents.base import AbstractAgent
from swarms.agents.registry import Registry
from swarms.agents.idea_to_image_agent import Idea2Image
from swarms.agents.simple_agent import SimpleAgent
"""Agent Infrastructure, models, memory, utils, tools"""
"""Agent Infrastructure, models, memory, utils, tools"""
"""Agent Infrastructure, models, memory, utils, tools"""
__all__ = [
"OmniModalAgent",
@ -18,4 +18,5 @@ __all__ = [
"AbstractAgent",
"Registry",
"Idea2Image",
"SimpleAgent",
]

@ -1,14 +1,36 @@
from termcolor import colored
class SimpleAgent:
"""
Simple Agent is a simple agent that runs a flow.
Args:
name (str): Name of the agent
flow (Flow): Flow to run
Example:
>>> from swarms.agents.simple_agent import SimpleAgent
>>> from swarms.structs import Flow
>>> from swarms.models import OpenAIChat
>>> api_key = "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"
>>> llm = OpenAIChat()
"""
def __init__(
self,
name: str,
llm,
flow,
):
self.name = name
self.llm = llm
self.flow = flow
self.message_history = []
def run(self, task: str) -> str:
response = self.model(task)
"""Run method"""
metrics = print(colored(f"Agent {self.name} is running task: {task}", "red"))
print(metrics)
response = self.flow.run(task)
self.message_history.append((self.name, response))
return response

@ -91,3 +91,5 @@ class AbstractModel(ABC):
TOKENS: {_num_tokens}
Tokens/SEC: {_time_for_generation}
"""

@ -23,7 +23,7 @@ from langchain.callbacks.manager import (
AsyncCallbackManagerForLLMRun,
CallbackManagerForLLMRun,
)
from swarms.models.base import BaseLLM, create_base_retry_decorator
from langchain.llms.base import BaseLLM, create_base_retry_decorator
from langchain.pydantic_v1 import Field, root_validator
from langchain.schema import Generation, LLMResult
from langchain.schema.output import GenerationChunk

@ -120,6 +120,33 @@ class Flow:
"""
response = task
history = [task]
dashboard = print(colored(f"""
Flow Dashboard
--------------------------------------------
Flow loop is initializing for {self.max_loops} with the following configuration:
Model Configuration:
Model Temperature:
Model Max Tokens:
----------------------------------------
Flow Configuration:
Task: {task}
Max Loops: {self.max_loops}
Stopping Condition: {self.stopping_condition}
Loop Interval: {self.loop_interval}
Retry Attempts: {self.retry_attempts}
Retry Interval: {self.retry_interval}
Interactive: {self.interactive}
----------------------------------------""", "green"))
print(dashboard)
for i in range(self.max_loops):
print(colored(f"\nLoop {i+1} of {self.max_loops}", "blue"))
print("\n")

Loading…
Cancel
Save