Skip to content

Commit 0a8620e

Browse files
add gateway call
1 parent 4810e54 commit 0a8620e

3 files changed

Lines changed: 80 additions & 1 deletion

File tree

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ from pgl_utils.genai import llm, rag
7878
# Your code here
7979
```
8080

81+
### Using the PGL Search Gateway
82+
83+
```python
84+
from pgl_utils.genai.search_gateway import PGLSearchGateway
85+
86+
gateway = PGLSearchGateway()
87+
results = gateway.search(
88+
"inteligência artificial generativa",
89+
search_depth="advanced",
90+
include_raw_content=True,
91+
)
92+
```
93+
8194
### Institution-Specific Tools
8295

8396
#### For PUC Students
@@ -116,7 +129,8 @@ pgl_utils/
116129
│ ├── genai/ # Generative AI module
117130
│ │ ├── __init__.py
118131
│ │ ├── llm.py
119-
│ │ └── rag.py
132+
│ │ ├── rag.py
133+
│ │ └── search_gateway.py
120134
│ ├── puc/ # PUC-specific extensions
121135
│ │ ├── __init__.py
122136
│ │ └── config.py

pgl_utils/genai/search_gateway.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
PGL Gateway search utilities
3+
"""
4+
5+
6+
# Standard library
7+
from typing import Any, Dict
8+
9+
# Third-party
10+
import requests
11+
12+
13+
_DEFAULT_BASE_URL = "https://pgl-gateway.vercel.app"
14+
_DEFAULT_TIMEOUT = 30
15+
16+
17+
class PGLSearchGateway:
18+
"""
19+
Thin client for the PGL Gateway search API.
20+
21+
Example:
22+
from pgl_utils.genai.search_gateway import PGLSearchGateway
23+
24+
gateway = PGLSearchGateway()
25+
results = gateway.search("inteligência artificial generativa")
26+
"""
27+
28+
def __init__(self, base_url: str = _DEFAULT_BASE_URL, timeout: int = _DEFAULT_TIMEOUT):
29+
self.base_url = base_url.rstrip("/")
30+
self.timeout = timeout
31+
32+
def search(
33+
self,
34+
q: str,
35+
search_depth: str = "advanced",
36+
include_raw_content: bool = True,
37+
**params: Any,
38+
) -> Dict[str, Any]:
39+
"""
40+
Calls the GET /search endpoint of the PGL Gateway.
41+
42+
Args:
43+
q: Search query text.
44+
search_depth: "basic" or "advanced".
45+
include_raw_content: Whether to include each result's raw page content.
46+
**params: Extra query parameters forwarded to the gateway as-is.
47+
48+
Returns:
49+
The parsed JSON response from the gateway.
50+
"""
51+
query = {
52+
"q": q,
53+
"search_depth": search_depth,
54+
"include_raw_content": include_raw_content,
55+
**params,
56+
}
57+
response = requests.get(
58+
f"{self.base_url}/search",
59+
params=query,
60+
headers={"accept": "application/json"},
61+
timeout=self.timeout,
62+
)
63+
response.raise_for_status()
64+
return response.json()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ langchain-groq
2222
langchain-core
2323
langchain-community
2424
pydantic
25+
requests
2526

2627
# Optional: Generative AI
2728
# openai>=0.27.0

0 commit comments

Comments
 (0)