gateway/modules/methods/method_web.py
2025-08-29 15:35:14 +02:00

43 lines
1.4 KiB
Python

import logging
from typing import Any, Dict
from modules.chat.methodBase import MethodBase, action
from modules.interfaces.interfaceChatModel import ActionResult
from modules.interfaces.interface_web_objects import WebInterface
from modules.interfaces.interface_web_model import WebSearchRequest
logger = logging.getLogger(__name__)
class MethodWeb(MethodBase):
"""Web method implementation for web operations."""
def __init__(self, serviceCenter: Any):
super().__init__(serviceCenter)
@action
async def search(self, parameters: Dict[str, Any]) -> ActionResult:
"""
Perform a web search and output a .txt file with a plain list of URLs (one per line).
Parameters:
query (str): Search query to perform
maxResults (int, optional): Maximum number of results (default: 10)
"""
# TODO: Fix docstrings - do we need that format for parsing?
try:
# Prepare request data
web_search_request = WebSearchRequest(
query=parameters.get("query"),
max_results=parameters.get("maxResults", 10),
)
# Perform request
web_interface = await WebInterface.create()
web_search_result = await web_interface.search(web_search_request)
return web_search_result
except Exception as e:
return ActionResult(success=False, error=str(e))