[CLEANUP][EXAMPLE]

pull/239/head
Kye 1 year ago
parent 60d777080d
commit 74f996b352

@ -33,7 +33,6 @@ Run example in Collab: <a target="_blank" href="https://colab.research.google.co
- Enterprise Grade + Production Grade: `Agent` is designed and optimized for automating real-world tasks at scale! - Enterprise Grade + Production Grade: `Agent` is designed and optimized for automating real-world tasks at scale!
```python ```python
import os import os
from dotenv import load_dotenv from dotenv import load_dotenv
@ -55,12 +54,12 @@ llm = OpenAIChat(
) )
## Initialize the Agent ## Initialize the workflow
agent = Agent(llm=llm, max_loops=1, dashboard=True) agent = Agent(llm=llm, max_loops=1, autosave=True, dashboard=True)
# Run the Agent on a task # Run the workflow on a task
out = agent.run("Generate a 10,000 word blog on health and wellness.") out = agent.run("Generate a 10,000 word blog on health and wellness.")
print(out)
``` ```

@ -20,7 +20,12 @@ llm = OpenAIChat(
## Initialize the workflow ## Initialize the workflow
agent = Agent(llm=llm, max_loops=1, dashboard=True, autosave=True) agent = Agent(
llm=llm,
max_loops=1,
autosave=True,
dashboard=True,
)
# Run the workflow on a task # Run the workflow on a task
out = agent.run("Generate a 10,000 word blog on health and wellness.") out = agent.run("Generate a 10,000 word blog on health and wellness.")

@ -3,6 +3,7 @@ from swarms.tools.tool_func_doc_scraper import scrape_tool_func_docs
# Define a tool by decorating a function with the tool decorator and providing a docstring # Define a tool by decorating a function with the tool decorator and providing a docstring
@tool(return_direct=True) @tool(return_direct=True)
def search_api(query: str): def search_api(query: str):
"""Search the web for the query """Search the web for the query

@ -216,6 +216,7 @@ class Agent:
self.system_prompt = system_prompt self.system_prompt = system_prompt
self.agent_name = agent_name self.agent_name = agent_name
self.agent_description = agent_description self.agent_description = agent_description
self.saved_state_path = saved_state_path
self.saved_state_path = f"{self.agent_name}_state.json" self.saved_state_path = f"{self.agent_name}_state.json"
self.autosave = autosave self.autosave = autosave
self.response_filters = [] self.response_filters = []

@ -1,3 +1,3 @@
from swarms.tools.tool_func_doc_scraper import scrape_tool_func_docs from swarms.tools.tool_func_doc_scraper import scrape_tool_func_docs
__all__ = ["scrape_tool_func_docs"] __all__ = ["scrape_tool_func_docs"]

@ -2,6 +2,7 @@ import inspect
from typing import Callable from typing import Callable
from termcolor import colored from termcolor import colored
def scrape_tool_func_docs(fn: Callable) -> str: def scrape_tool_func_docs(fn: Callable) -> str:
""" """
Scrape the docstrings and parameters of a function decorated with `tool` and return a formatted string. Scrape the docstrings and parameters of a function decorated with `tool` and return a formatted string.
@ -13,7 +14,6 @@ def scrape_tool_func_docs(fn: Callable) -> str:
str: A string containing the function's name, documentation string, and a list of its parameters. Each parameter is represented as a line containing the parameter's name, default value, and annotation. str: A string containing the function's name, documentation string, and a list of its parameters. Each parameter is represented as a line containing the parameter's name, default value, and annotation.
""" """
try: try:
# If the function is a tool, get the original function # If the function is a tool, get the original function
if hasattr(fn, "func"): if hasattr(fn, "func"):
fn = fn.func fn = fn.func
@ -33,4 +33,13 @@ def scrape_tool_func_docs(fn: Callable) -> str:
f" {inspect.getdoc(fn)}\nParameters:\n{parameters_str}" f" {inspect.getdoc(fn)}\nParameters:\n{parameters_str}"
) )
except Exception as error: except Exception as error:
print(colored(f"Error scraping tool function docs {error} try optimizing your inputs with different variables and attempt once more.", "red")) print(
colored(
(
f"Error scraping tool function docs {error} try"
" optimizing your inputs with different"
" variables and attempt once more."
),
"red",
)
)

Loading…
Cancel
Save