-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linkup for agents #178
Open
juliette0704
wants to merge
14
commits into
crewAIInc:main
Choose a base branch
from
juliette0704:feat/add_linkup_tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
linkup for agents #178
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
060dd9e
linkup for agents
juliette0704 4720f55
Merge branch 'main' into feat/add_linkup_tool
juliette0704 67b5443
add linkup with agents
juliette0704 e0a3c41
rename variable
juliette0704 724d573
no default parameters
juliette0704 424ad1f
refacto return
juliette0704 35b98f6
add linkup tool
juliette0704 3957905
add linkup tool
juliette0704 850e4bc
indentation
juliette0704 4622800
Merge branch 'main' into feat/add_linkup_tool
juliette0704 9bec253
spaces
juliette0704 65a83d1
add linkup tool
juliette0704 4ae8363
features readme
juliette0704 c4c3ceb
Merge branch 'main' into feat/add_linkup_tool
juliette0704 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file not shown.
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 |
---|---|---|
@@ -1,73 +1,60 @@ | ||
from typing import Any | ||
|
||
from typing import Any, Type | ||
from pydantic import BaseModel, Field | ||
from crewai.tools import BaseTool | ||
|
||
try: | ||
from linkup import LinkupClient | ||
|
||
LINKUP_AVAILABLE = True | ||
except ImportError: | ||
LINKUP_AVAILABLE = False | ||
LinkupClient = Any # type placeholder when package is not available | ||
LinkupClient = Any | ||
|
||
from pydantic import PrivateAttr | ||
|
||
class LinkupSearchToolSchema(BaseModel): | ||
"""Input for LinkupBaseTool.""" | ||
|
||
query: str = Field( | ||
..., description="The query to search for." | ||
) | ||
|
||
|
||
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 | ||
description: str = "A tool to search and retrieve trends or insights using the Linkup API." | ||
args_schema: Type[BaseModel] = LinkupSearchToolSchema | ||
|
||
def __init__(self, api_key: str): | ||
""" | ||
Initialize the tool with an API key. | ||
""" | ||
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?" | ||
): | ||
import subprocess | ||
def __init__(self, api_key: str, depth: str, output_type: str, structured_output_schema:str = None, **kwargs): | ||
from linkup import LinkupClient | ||
|
||
subprocess.run(["uv", "add", "linkup-sdk"], check=True) | ||
from linkup import LinkupClient | ||
super().__init__(**kwargs) | ||
if not LINKUP_AVAILABLE: | ||
raise ImportError( | ||
"The 'linkup' package is required to use the LinkupSearchTool. " | ||
"Please install it with: pip install linkup" | ||
) | ||
|
||
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) | ||
self._default_depth = depth | ||
self._default_output_type = output_type | ||
self._default_structured_schema = structured_output_schema | ||
|
||
def _run(self, query: str ) : | ||
|
||
def _run( | ||
self, query: str, depth: str = "standard", output_type: str = "searchResults" | ||
) -> dict: | ||
""" | ||
Executes a search using the Linkup API. | ||
|
||
:param query: The query to search for. | ||
:param depth: Search depth (default is "standard"). | ||
:param output_type: Desired result type (default is "searchResults"). | ||
:return: A dictionary containing the results or an error message. | ||
:return: The results or an error message. | ||
""" | ||
try: | ||
response = self._client.search( | ||
query=query, depth=depth, output_type=output_type | ||
) | ||
results = [ | ||
{"name": result.name, "url": result.url, "content": result.content} | ||
for result in response.results | ||
] | ||
return {"success": True, "results": results} | ||
except Exception as e: | ||
return {"success": False, "error": str(e)} | ||
|
||
api_params = { | ||
"query": query, | ||
"depth": self._default_depth, | ||
"output_type": self._default_output_type, | ||
} | ||
|
||
if self._default_output_type == "structured": | ||
if not self.structured_output_schema: | ||
raise ValueError("structured_output_schema must be provided when output_type is 'structured'.") | ||
api_params["structured_output_schema"] = self._default_structured_schema | ||
return self._client.search(**api_params) |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juliette0704 can you update to 0.2.2 please