Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
feat: Add duckduckgo_search Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoubmrx committed Feb 16, 2024
1 parent 744fd09 commit 6bc28e6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
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 hyko_toolkit/functions/utils/web_search/duckduckgo_search/main.py
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)
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 .")

0 comments on commit 6bc28e6

Please sign in to comment.