mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-03 08:12:39 +00:00
optional deps for most
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from typing import Any
|
||||
|
||||
from crewai.tools import BaseTool
|
||||
|
||||
try:
|
||||
from linkup import LinkupClient
|
||||
|
||||
LINKUP_AVAILABLE = True
|
||||
except ImportError:
|
||||
LINKUP_AVAILABLE = False
|
||||
@@ -9,23 +12,42 @@ except ImportError:
|
||||
|
||||
from pydantic import PrivateAttr
|
||||
|
||||
class LinkupSearchTool:
|
||||
|
||||
class LinkupSearchTool(BaseTool):
|
||||
name: str = "Linkup Search Tool"
|
||||
description: str = "Performs an API call to Linkup to retrieve contextual information."
|
||||
_client: LinkupClient = PrivateAttr() # type: ignore
|
||||
description: str = (
|
||||
"Performs an API call to Linkup to retrieve contextual information."
|
||||
)
|
||||
_client: LinkupClient = PrivateAttr() # type: ignore
|
||||
|
||||
def __init__(self, api_key: str):
|
||||
"""
|
||||
Initialize the tool with an API key.
|
||||
"""
|
||||
if not LINKUP_AVAILABLE:
|
||||
raise ImportError(
|
||||
"The 'linkup' package is required to use the LinkupSearchTool. "
|
||||
"Please install it with: uv add linkup"
|
||||
)
|
||||
super().__init__()
|
||||
try:
|
||||
from linkup import LinkupClient
|
||||
except ImportError:
|
||||
import click
|
||||
|
||||
if click.confirm(
|
||||
"You are missing the 'linkup-sdk' package. Would you like to install it? (y/N)"
|
||||
):
|
||||
import subprocess
|
||||
|
||||
subprocess.run(["uv", "add", "linkup-sdk"], check=True)
|
||||
from linkup import LinkupClient
|
||||
|
||||
else:
|
||||
raise ImportError(
|
||||
"The 'linkup-sdk' package is required to use the LinkupSearchTool. "
|
||||
"Please install it with: uv add linkup-sdk"
|
||||
)
|
||||
self._client = LinkupClient(api_key=api_key)
|
||||
|
||||
def _run(self, query: str, depth: str = "standard", output_type: str = "searchResults") -> dict:
|
||||
def _run(
|
||||
self, query: str, depth: str = "standard", output_type: str = "searchResults"
|
||||
) -> dict:
|
||||
"""
|
||||
Executes a search using the Linkup API.
|
||||
|
||||
@@ -36,9 +58,7 @@ class LinkupSearchTool:
|
||||
"""
|
||||
try:
|
||||
response = self._client.search(
|
||||
query=query,
|
||||
depth=depth,
|
||||
output_type=output_type
|
||||
query=query, depth=depth, output_type=output_type
|
||||
)
|
||||
results = [
|
||||
{"name": result.name, "url": result.url, "content": result.content}
|
||||
|
||||
Reference in New Issue
Block a user