Skip to content
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

Feat/add linkup #11854

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions api/core/tools/provider/builtin/linkup/linkup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import requests
from core.tools.errors import ToolProviderCredentialValidationError
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
from linkup import LinkupClient

class LinkupProvider(BuiltinToolProviderController):
def _validate_credentials(self, credentials: dict) -> None:
try:
if "api_key" not in credentials or not credentials.get("api_key"):
raise ToolProviderCredentialValidationError("Linkup API key is required.")

api_key = credentials.get("api_key")
client = LinkupClient(api_key=api_key)
try:
response = client.search(query="test")
if not response or response.get("error"):
raise ToolProviderCredentialValidationError("Invalid Linkup API key.")
except Exception as e:
raise ToolProviderCredentialValidationError(f"Linkup API key validation failed: {str(e)}")

except Exception as e:
raise ToolProviderCredentialValidationError(str(e))
53 changes: 53 additions & 0 deletions api/core/tools/provider/builtin/linkup/linkup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
identity:
author: Juliette Sivan
name: linkup
label:
en_US: Linkup Search Tool
zh_Hans: Linkup 搜索工具
description:
en_US: Search engine optimized for agents to seamlessly and fairly retrieve data from the web and beyond.
zh_Hans: 针对代理进行了优化的搜索引擎,可以无缝、公平地从网络及其他地方检索数据
icon: icon.png
tags:
- search
- api

dependencies:
- linkup_sdk

commands:
- name: search
label:
en_US: Search
zh_Hans: 搜索
description:
en_US: Perform a search using the Linkup API.
zh_Hans: 使用 Linkup API 进行搜索。
parameters:
- name: query
type: string
required: true
label:
en_US: Query
zh_Hans: 查询
description:
en_US: The search query string.
zh_Hans: 查询字符串。
- name: depth
type: string
required: false
label:
en_US: Search Depth
zh_Hans: 搜索深度
description:
en_US: The search depth (e.g., basic, standard).
zh_Hans: 搜索深度(例如:基础、标准)。
- name: output_type
type: string
required: false
label:
en_US: Output Type
zh_Hans: 输出类型
description:
en_US: The desired type of output (e.g., searchResults).
zh_Hans: 所需的输出类型(例如:searchResults)。
36 changes: 36 additions & 0 deletions api/core/tools/provider/builtin/linkup/tools/linkup_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from linkup import LinkupClient
from pydantic import PrivateAttr

class LinkupSearchTool:
name: str = "Linkup Search Tool"
description: str = "Performs an API call to Linkup to retrieve contextual information."
_client: LinkupClient = PrivateAttr()

def __init__(self, api_key: str):
"""
Initialize the tool with an API key.
"""
self._client = LinkupClient(api_key=api_key)

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.
"""
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)}