-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdrop_in_agent.py
More file actions
52 lines (38 loc) · 1.66 KB
/
Copy pathdrop_in_agent.py
File metadata and controls
52 lines (38 loc) · 1.66 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
"""Minimal agent-tool bridge: map OpenAI-style tool calls to WebSearchFree HTTP.
Requires a running server (no C++ build in *your* project):
docker run --rm -p 8080:8080 ghcr.io/drmikecrypto/websearchfree:latest
Then from this repo (or copy integrations/http/client.py next to this file):
python examples/drop_in_agent.py "what is metasearch"
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "integrations" / "http"))
from client import WebSearchFree # noqa: E402
def dispatch(name: str, arguments: dict) -> dict:
wsf = WebSearchFree()
if name == "web_search":
return wsf.search(
query=arguments["query"],
max_results=int(arguments.get("max_results", 5)),
include_raw_content=bool(arguments.get("include_raw_content", False)),
search_depth=str(arguments.get("search_depth", "basic")),
topic=str(arguments.get("topic", "general")),
include_domains=arguments.get("include_domains"),
exclude_domains=arguments.get("exclude_domains"),
include_answer=bool(arguments.get("include_answer", True)),
)
if name == "web_extract":
return wsf.extract(arguments["urls"])
raise ValueError(f"unknown tool: {name}")
def main() -> int:
query = " ".join(sys.argv[1:]) or "open source metasearch"
# Simulate a model choosing web_search
result = dispatch("web_search", {"query": query, "max_results": 5})
print(json.dumps(result, indent=2))
return 0
if __name__ == "__main__":
raise SystemExit(main())