This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
hyko_toolkit/functions/utils/web_search/duckduckgo_search/Dockerfile
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM hyko-sdk:latest | ||
WORKDIR /app | ||
|
||
COPY . . | ||
RUN poetry run pip install duckduckgo_search | ||
|
||
CMD ["poetry", "run", "uvicorn", "--host", "0.0.0.0", "--port", "3000", "main:func"] |
25 changes: 25 additions & 0 deletions
25
hyko_toolkit/functions/utils/web_search/duckduckgo_search/main.py
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from duckduckgo_search import DDGS | ||
from metadata import Inputs, Outputs, Params, func | ||
|
||
|
||
@func.on_execute | ||
async def main(inputs: Inputs, params: Params) -> Outputs: | ||
""" | ||
Search the web using DuckDuckGo and return all results as a single string. | ||
Args: | ||
query (str): The search query. | ||
max_results (int): Maximum number of search results to return (default is 5). | ||
Returns: | ||
str: A single string containing all search results. | ||
""" | ||
# Initialize DuckDuckGo search session | ||
with DDGS() as ddgs: | ||
# Perform the search and retrieve results | ||
results = list(ddgs.text(inputs.query, max_results=params.max_results)) # type: ignore | ||
# Concatenate titles and URLs into a single strings | ||
result_str = "" | ||
for result in results: | ||
result_str += f"Title: {result['title']}\nURL: {result['href']}\nBody: {result['body']}\n\n" | ||
return Outputs(result=result_str) |
27 changes: 27 additions & 0 deletions
27
hyko_toolkit/functions/utils/web_search/duckduckgo_search/metadata.py
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from pydantic import Field | ||
|
||
from hyko_sdk.function import SDKFunction | ||
from hyko_sdk.metadata import CoreModel | ||
|
||
func = SDKFunction(description="Search the web using DuckDuckGo .") | ||
|
||
|
||
@func.set_input | ||
class Inputs(CoreModel): | ||
query: str = Field( | ||
..., | ||
description="The search query .", | ||
) | ||
|
||
|
||
@func.set_param | ||
class Params(CoreModel): | ||
max_results: int = Field( | ||
..., | ||
description="Maximum number of search .", | ||
) | ||
|
||
|
||
@func.set_output | ||
class Outputs(CoreModel): | ||
result: str = Field(..., description="The concatenated titles and summaries .") |