-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kye
committed
Nov 30, 2023
1 parent
4e47528
commit ec51149
Showing
8 changed files
with
182 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
tool decorated func [search_api] -> agent which parses the docs of the tool func | ||
-> injected into prompt -> agent will output json containing tool usage -> agent output will be parsed -> tool executed | ||
-> terminal response can be returned to agent for self-healing | ||
""" | ||
|
||
import os | ||
|
||
from dotenv import load_dotenv | ||
|
||
# Import the OpenAIChat model and the Agent struct | ||
from swarms.models import OpenAIChat | ||
from swarms.structs import Agent | ||
from swarms.tools.tool import tool | ||
|
||
# Load the environment variables | ||
load_dotenv() | ||
|
||
# Define a tool | ||
@tool | ||
def search_api(query: str): | ||
"""Search the web for the query | ||
Args: | ||
query (str): _description_ | ||
Returns: | ||
_type_: _description_ | ||
""" | ||
return f"Search results for {query}" | ||
|
||
|
||
# Get the API key from the environment | ||
api_key = os.environ.get("OPENAI_API_KEY") | ||
|
||
# Initialize the language model | ||
llm = OpenAIChat( | ||
temperature=0.5, | ||
openai_api_key=api_key, | ||
) | ||
|
||
|
||
## Initialize the workflow | ||
agent = Agent( | ||
llm=llm, max_loops=1, dashboard=True, tools=[search_api] | ||
) | ||
|
||
# Run the workflow on a task | ||
out = agent.run("Generate a 10,000 word blog on health and wellness.") | ||
print(out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "swarms" | ||
version = "2.4.6" | ||
version = "2.4.7" | ||
description = "Swarms - Pytorch" | ||
license = "MIT" | ||
authors = ["Kye Gomez <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters