| from typing import Literal |
|
|
| from smolagents import Tool |
| from linkup import LinkupClient |
|
|
| class LinkupSearchTool(Tool): |
| name = "linkup_web_search" |
| description = "Performs a search for your text query using Linkup sdk then returns a string of the top search results." |
| inputs = { |
| "query": {"type": "string", "description": "The search query to perform."}, |
| } |
| output_type = "string" |
|
|
| def __init__(self, answer_output_type: str = "sourcedAnswer", |
| **kwargs): |
| super().__init__(self) |
| import os |
|
|
| self.api_key = os.getenv("LINKUP_API_KEY") |
| if self.api_key is None: |
| raise ValueError("Missing Linkup API key. Make sure you have 'LINKUP_API_KEY' in your env variables.") |
|
|
| self.client = LinkupClient(api_key=self.api_key) |
| self.answer_output_type = answer_output_type |
|
|
| def forward(self, query: str) -> str: |
| response = self.client.search( |
| query=query, |
| depth="deep", |
| output_type=self.answer_output_type |
| ) |
|
|
| answer_text = getattr(response, "answer", "No answer provided.") |
|
|
| return f'## Search Results\n:{answer_text}' |