File size: 1,396 Bytes
fbf3c28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
id: deep_research
title: Deep Research Orchestrator
author: admin
description: Search → fetch → scrape → summarize across top results; stores pages to /data/adaptai/web/pages and returns structured findings.
version: 0.1.0
license: Proprietary
"""

from typing import List, Dict, Any


class Tools:
    def run(self, query: str, max_results: int = 5, fetch_chars: int = 2000) -> dict:
        from open_webui.utils.plugin import load_tool_module_by_id

        web, _ = load_tool_module_by_id("web_search")
        http, _ = load_tool_module_by_id("http")
        scraper, _ = load_tool_module_by_id("scraper")
        res = web.search(query=query, max_results=max_results)
        hits: List[Dict[str, Any]] = []
        for item in res.get("results", [])[:max_results]:
            url = item.get("url")
            try:
                page = http.get(url=url)
                ext = scraper.extract(html_text=page.get("stdout", ""), url=url)
                hits.append(
                    {
                        "title": ext.get("title") or item.get("title"),
                        "url": url,
                        "summary": (ext.get("text") or "")[:fetch_chars],
                    }
                )
            except Exception as e:
                hits.append({"title": item.get("title"), "url": url, "error": str(e)})
        return {"query": query, "hits": hits}