refactor: remove swarm_models dependency from examples and docs

pull/824/head
ascender1729 2 months ago
parent a74adfca69
commit 0fa4674330

@ -1271,24 +1271,28 @@ The `run` method returns a dictionary containing the execution results of all no
```python ```python
import os
from dotenv import load_dotenv
from swarms import Agent, Edge, GraphWorkflow, Node, NodeType from swarms import Agent, Edge, GraphWorkflow, Node, NodeType
from swarm_models import OpenAIChat # Initialize agents with model_name parameter
agent1 = Agent(
load_dotenv() agent_name="Agent1",
model_name="openai/gpt-4o-mini", # Using provider prefix
api_key = os.environ.get("OPENAI_API_KEY") temperature=0.5,
max_tokens=4000,
max_loops=1,
autosave=True,
dashboard=True,
)
llm = OpenAIChat( agent2 = Agent(
temperature=0.5, openai_api_key=api_key, max_tokens=4000 agent_name="Agent2",
model_name="openai/gpt-4o-mini", # Using provider prefix
temperature=0.5,
max_tokens=4000,
max_loops=1,
autosave=True,
dashboard=True,
) )
agent1 = Agent(llm=llm, max_loops=1, autosave=True, dashboard=True)
agent2 = Agent(llm=llm, max_loops=1, autosave=True, dashboard=True)
def sample_task(): def sample_task():
print("Running sample task") print("Running sample task")
@ -1297,9 +1301,8 @@ def sample_task():
wf_graph = GraphWorkflow() wf_graph = GraphWorkflow()
wf_graph.add_node(Node(id="agent1", type=NodeType.AGENT, agent=agent1)) wf_graph.add_node(Node(id="agent1", type=NodeType.AGENT, agent=agent1))
wf_graph.add_node(Node(id="agent2", type=NodeType.AGENT, agent=agent2)) wf_graph.add_node(Node(id="agent2", type=NodeType.AGENT, agent=agent2))
wf_graph.add_node( wf_graph.add_node(Node(id="task1", type=NodeType.TASK, callable=sample_task))
Node(id="task1", type=NodeType.TASK, callable=sample_task)
)
wf_graph.add_edge(Edge(source="agent1", target="task1")) wf_graph.add_edge(Edge(source="agent1", target="task1"))
wf_graph.add_edge(Edge(source="agent2", target="task1")) wf_graph.add_edge(Edge(source="agent2", target="task1"))
@ -1308,10 +1311,8 @@ wf_graph.set_end_points(["task1"])
print(wf_graph.visualize()) print(wf_graph.visualize())
# Run the workflow
results = wf_graph.run() results = wf_graph.run()
print("Execution results:", results) print("Execution results:", results)
``` ```
## `MixtureOfAgents` ## `MixtureOfAgents`
@ -2216,21 +2217,20 @@ Documentation is located here at: [docs.swarms.world](https://docs.swarms.world)
----- -----
## Folder Structure ## Folder Structure
The swarms package has been meticlously crafted for extreme use-ability and understanding, the swarms package is split up into various modules such as `swarms.agents` that holds pre-built agents, `swarms.structs` that holds a vast array of structures like `Agent` and multi agent structures. The 3 most important are `structs`, `models`, and `agents`. The swarms package has been meticulously crafted for extreme usability and understanding,the swarms package is split up into various modules such as `swarms.agents` that holds pre-built agents, `swarms.structs` that holds a vast array of structures like `Agent` and multi agent structures. The package is split into various modules, with the most important being `structs`, `tools`, and `agents`.
```sh ```sh
├── __init__.py ├── __init__.py
├── agents ├── agents/
├── artifacts ├── artifacts/
├── memory ├── client/
├── schemas ├── cli/
├── models -> swarm_models ├── prompts/
├── prompts ├── schemas/
├── structs ├── structs/
├── telemetry ├── telemetry/
├── tools ├── tools/
├── utils └── utils/
└── workers
``` ```
---- ----

@ -1,17 +1,45 @@
from swarms.structs.agent import Agent from swarms import Agent, Edge, GraphWorkflow, Node, NodeType
from swarms.prompts.finance_agent_sys_prompt import ( from swarms.prompts.finance_agent_sys_prompt import (
FINANCIAL_AGENT_SYS_PROMPT, FINANCIAL_AGENT_SYS_PROMPT,
) )
# Initialize the agent # Initialize agents with model_name parameter
agent = Agent( agent1 = Agent(
agent_name="Financial-Analysis-Agent", agent_name="Agent1",
agent_description="Personal finance advisor agent", model_name="openai/gpt-4o-mini", # Using provider prefix
system_prompt=FINANCIAL_AGENT_SYS_PROMPT, temperature=0.5,
max_loops=2, max_tokens=4000,
model_name="gpt-4o-mini", max_loops=1,
dynamic_temperature_enabled=True, autosave=True,
interactive=False, dashboard=True,
) )
agent.run("Conduct an analysis of the best real undervalued ETFs") agent2 = Agent(
agent_name="Agent2",
model_name="openai/gpt-4o-mini", # Using provider prefix
temperature=0.5,
max_tokens=4000,
max_loops=1,
autosave=True,
dashboard=True,
)
def sample_task():
print("Running sample task")
return "Task completed"
wf_graph = GraphWorkflow()
wf_graph.add_node(Node(id="agent1", type=NodeType.AGENT, agent=agent1))
wf_graph.add_node(Node(id="agent2", type=NodeType.AGENT, agent=agent2))
wf_graph.add_node(Node(id="task1", type=NodeType.TASK, callable=sample_task))
wf_graph.add_edge(Edge(source="agent1", target="task1"))
wf_graph.add_edge(Edge(source="agent2", target="task1"))
wf_graph.set_entry_points(["agent1", "agent2"])
wf_graph.set_end_points(["task1"])
print(wf_graph.visualize())
results = wf_graph.run()
print("Execution results:", results)
Loading…
Cancel
Save