A FastAPI utility for exposing CrewAI functionalities
Project description
Graphtomation Documentation
⚠️ Disclaimer: This package is still under development. Use it at your own risk.
Installation
Install the required dependencies for Graphtomation using the following command:
pip install graphtomation
Implementation
import requests
from typing import Type
from fastapi import FastAPI
from crewai.tools import BaseTool
from crewai import Agent, Task, Crew
from graphtomation import CrewAIRouter
from pydantic import BaseModel, Field
# Define the input schema for the tool
class DuckDuckGoSearchInput(BaseModel):
"""Input schema for DuckDuckGoSearchTool."""
query: str = Field(..., description="Search query to look up on DuckDuckGo.")
# Create the custom tool by subclassing BaseTool
class DuckDuckGoSearchTool(BaseTool):
name: str = "DuckDuckGoSearch"
description: str = (
"This tool performs web searches using DuckDuckGo and retrieves the top results. "
"Provide a query string to get relevant information."
)
args_schema: Type[BaseModel] = DuckDuckGoSearchInput
def _run(self, query: str) -> str:
"""
Perform a search using the DuckDuckGo API and return the top results.
"""
url = "https://api.duckduckgo.com/"
params = {
"q": query,
"format": "json",
"no_redirect": "1",
"no_html": "1",
}
try:
response = requests.get(url, params=params)
response.raise_for_status()
data = response.json()
# Extract the top result or fallback to AbstractText
if "RelatedTopics" in data and data["RelatedTopics"]:
results = [
topic.get("Text", "No description available")
for topic in data["RelatedTopics"]
if "Text" in topic
]
return "\n".join(results[:3]) # Return the top 3 results
else:
return "No results found for the given query."
except requests.RequestException as e:
return f"An error occurred while performing the search: {e}"
ddg_search_tool = DuckDuckGoSearchTool()
researcher = Agent(
role="Web Researcher",
goal="Perform searches to gather relevant information for tasks.",
backstory="An experienced researcher with expertise in online information gathering.",
tools=[ddg_search_tool],
verbose=True,
)
research_task = Task(
description="Search for the latest advancements in AI technology.",
expected_output="A summary of the top 3 advancements in AI technology from recent searches.",
agent=researcher,
)
example_crew = Crew(
agents=[researcher],
tasks=[research_task],
verbose=True,
planning=True,
)
app = FastAPI()
crew_router = CrewAIRouter(
crews=[
{
"name": "example-crew",
"crew": example_crew,
"metadata": {
"description": "An example crew ai implementation",
"version": "1.0.0",
},
}
]
)
app.include_router(crew_router.router, prefix="/crew")
Running the Application
fastapi dev main.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
graphtomation-0.0.3.tar.gz
(14.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphtomation-0.0.3.tar.gz.
File metadata
- Download URL: graphtomation-0.0.3.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
341722650a050b24040e1d2aefd67dab8e505d1817b3a45654eea29b467f3b8e
|
|
| MD5 |
2f518932c935537a16219b2a197e0b16
|
|
| BLAKE2b-256 |
6a06c24b83f5aa8e2657b15acc4b6502e7bf8b28ff2cf8d99b883db6acde99f7
|
File details
Details for the file graphtomation-0.0.3-py3-none-any.whl.
File metadata
- Download URL: graphtomation-0.0.3-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42cc9d3bbeb539c0d1bdc5dcea2a19b9288ba326800d9845abf3897ca577bf86
|
|
| MD5 |
6fd98fe5e986ca80e79e0afb20b24bf8
|
|
| BLAKE2b-256 |
315847418912a630f1ad3fcebf2608298945e0ef87d35f5d68e6e81d3678a0dd
|