You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
945 B
48 lines
945 B
1 year ago
|
from swarms.structs import Task, Agent
|
||
|
from swarms.models import OpenAIChat
|
||
|
from dotenv import load_dotenv
|
||
|
import os
|
||
|
|
||
|
|
||
|
# Load the environment variables
|
||
|
load_dotenv()
|
||
|
|
||
|
|
||
|
# Define a function to be used as the action
|
||
|
def my_action():
|
||
|
print("Action executed")
|
||
|
|
||
|
|
||
|
# Define a function to be used as the condition
|
||
|
def my_condition():
|
||
|
print("Condition checked")
|
||
|
return True
|
||
|
|
||
|
|
||
|
# Create an agent
|
||
|
agent = Agent(
|
||
|
llm=OpenAIChat(openai_api_key=os.environ["OPENAI_API_KEY"]),
|
||
|
max_loops=1,
|
||
|
dashboard=False,
|
||
|
)
|
||
|
|
||
|
# Create a task
|
||
|
task = Task(description="What's the weather in miami", agent=agent)
|
||
|
|
||
|
# Set the action and condition
|
||
|
task.set_action(my_action)
|
||
|
task.set_condition(my_condition)
|
||
|
|
||
|
# Execute the task
|
||
|
print("Executing task...")
|
||
|
task.run()
|
||
|
|
||
|
# Check if the task is completed
|
||
|
if task.is_completed():
|
||
|
print("Task completed")
|
||
|
else:
|
||
|
print("Task not completed")
|
||
|
|
||
|
# Output the result of the task
|
||
|
print(f"Task result: {task.result}")
|