Spaces:
Running on Zero
Running on Zero
Update API reference with news/images backends and extraction support
Browse files- API_REFERENCE.md +83 -18
API_REFERENCE.md
CHANGED
|
@@ -95,14 +95,17 @@ Lists all callable capabilities.
|
|
| 95 |
},
|
| 96 |
"web_search": {
|
| 97 |
"name": "Web search",
|
| 98 |
-
"description": "Search the web via DuckDuckGo. No API key required.",
|
| 99 |
"endpoint": "/respite/search",
|
| 100 |
"method": "GET",
|
| 101 |
"input": {
|
| 102 |
"q": "string (search query)",
|
| 103 |
-
"
|
|
|
|
|
|
|
|
|
|
| 104 |
},
|
| 105 |
-
"output": "JSON with title, url, content per result"
|
| 106 |
}
|
| 107 |
}
|
| 108 |
}
|
|
@@ -112,39 +115,90 @@ Lists all callable capabilities.
|
|
| 112 |
|
| 113 |
### `GET /respite/search`
|
| 114 |
|
| 115 |
-
Search the web via DuckDuckGo. No API key required.
|
| 116 |
|
| 117 |
**Query Parameters:**
|
| 118 |
|
| 119 |
| Parameter | Type | Required | Default | Description |
|
| 120 |
|---|---|---|---|---|
|
| 121 |
| `q` | string | Yes | β | Search query |
|
|
|
|
| 122 |
| `max_results` | integer | No | 10 | Number of results (1-50) |
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
**Request:**
|
| 125 |
|
| 126 |
```
|
| 127 |
-
GET /respite/search?q=what+is+python&max_results=3
|
| 128 |
```
|
| 129 |
|
| 130 |
-
**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
```json
|
| 133 |
{
|
| 134 |
"query": "what is python",
|
|
|
|
| 135 |
"results": [
|
| 136 |
{
|
| 137 |
"title": "Python (programming language) - Wikipedia",
|
| 138 |
"url": "https://en.wikipedia.org/wiki/Python_(programming_language)",
|
| 139 |
"content": "Python is a high-level, general-purpose programming language that emphasizes code readability..."
|
| 140 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
{
|
| 142 |
-
"title": "
|
| 143 |
-
"url": "https://
|
| 144 |
-
"content": "
|
|
|
|
|
|
|
|
|
|
| 145 |
}
|
| 146 |
],
|
| 147 |
-
"total_results":
|
| 148 |
}
|
| 149 |
```
|
| 150 |
|
|
@@ -153,6 +207,7 @@ GET /respite/search?q=what+is+python&max_results=3
|
|
| 153 |
| Status | Body | Cause |
|
| 154 |
|---|---|---|
|
| 155 |
| 400 | `{"error": "Missing query parameter 'q'"}` | No query provided |
|
|
|
|
| 156 |
| 502 | `{"error": "..."}` | Search backend unreachable |
|
| 157 |
|
| 158 |
---
|
|
@@ -235,14 +290,24 @@ Check the HTTP status code:
|
|
| 235 |
|
| 236 |
1. **Discover capabilities at runtime** β Call `GET /respite/resources` to enumerate what the API can do. Do not hardcode resource names.
|
| 237 |
|
| 238 |
-
2. **Search
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
-
|
| 241 |
|
| 242 |
-
|
| 243 |
|
| 244 |
-
|
| 245 |
|
| 246 |
-
|
| 247 |
|
| 248 |
-
|
|
|
|
| 95 |
},
|
| 96 |
"web_search": {
|
| 97 |
"name": "Web search",
|
| 98 |
+
"description": "Search the web via DuckDuckGo. Supports general, news, and image search. No API key required.",
|
| 99 |
"endpoint": "/respite/search",
|
| 100 |
"method": "GET",
|
| 101 |
"input": {
|
| 102 |
"q": "string (search query)",
|
| 103 |
+
"backend": "string: 'text' (default), 'news', or 'images'",
|
| 104 |
+
"max_results": "integer (1-50, default 10)",
|
| 105 |
+
"extract_top": "integer (0-5, default 0) - fetch full page content for top N results",
|
| 106 |
+
"region": "string (default 'wt-wt') - e.g. 'us-en', 'gb-en', 'de-de'"
|
| 107 |
},
|
| 108 |
+
"output": "JSON with title, url, content per result. News results include date and source."
|
| 109 |
}
|
| 110 |
}
|
| 111 |
}
|
|
|
|
| 115 |
|
| 116 |
### `GET /respite/search`
|
| 117 |
|
| 118 |
+
Search the web via DuckDuckGo. Supports general text, news, and image search. No API key required.
|
| 119 |
|
| 120 |
**Query Parameters:**
|
| 121 |
|
| 122 |
| Parameter | Type | Required | Default | Description |
|
| 123 |
|---|---|---|---|---|
|
| 124 |
| `q` | string | Yes | β | Search query |
|
| 125 |
+
| `backend` | string | No | `"text"` | `"text"` (general), `"news"` (news articles), or `"images"` |
|
| 126 |
| `max_results` | integer | No | 10 | Number of results (1-50) |
|
| 127 |
+
| `extract_top` | integer | No | 0 | Fetch full page content for top N results (0-5). Adds latency but gives richer content. |
|
| 128 |
+
| `region` | string | No | `"wt-wt"` | Region code: `"us-en"`, `"gb-en"`, `"de-de"`, `"wt-wt"` (worldwide) |
|
| 129 |
|
| 130 |
+
**Request (text search):**
|
| 131 |
|
| 132 |
```
|
| 133 |
+
GET /respite/search?q=what+is+python&backend=text&max_results=3
|
| 134 |
```
|
| 135 |
|
| 136 |
+
**Request (news search):**
|
| 137 |
+
|
| 138 |
+
```
|
| 139 |
+
GET /respite/search?q=latest+AI+news&backend=news&max_results=5
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
**Request (news + extraction):**
|
| 143 |
+
|
| 144 |
+
```
|
| 145 |
+
GET /respite/search?q=nvidia+earnings&backend=news&max_results=3&extract_top=2
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
**Response (text):**
|
| 149 |
|
| 150 |
```json
|
| 151 |
{
|
| 152 |
"query": "what is python",
|
| 153 |
+
"backend": "text",
|
| 154 |
"results": [
|
| 155 |
{
|
| 156 |
"title": "Python (programming language) - Wikipedia",
|
| 157 |
"url": "https://en.wikipedia.org/wiki/Python_(programming_language)",
|
| 158 |
"content": "Python is a high-level, general-purpose programming language that emphasizes code readability..."
|
| 159 |
+
}
|
| 160 |
+
],
|
| 161 |
+
"total_results": 1
|
| 162 |
+
}
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
**Response (news):**
|
| 166 |
+
|
| 167 |
+
```json
|
| 168 |
+
{
|
| 169 |
+
"query": "latest AI news",
|
| 170 |
+
"backend": "news",
|
| 171 |
+
"results": [
|
| 172 |
+
{
|
| 173 |
+
"title": "Strong AI chip demand fuels Nvidia's Q2 results",
|
| 174 |
+
"url": "https://apnews.com/article/...",
|
| 175 |
+
"content": "Nvidia's latest quarterly results once again blew past Wall Street's expectations...",
|
| 176 |
+
"source": "Associated Press News",
|
| 177 |
+
"date": "2026-08-27T00:00:00+00:00",
|
| 178 |
+
"image": "https://..."
|
| 179 |
+
}
|
| 180 |
+
],
|
| 181 |
+
"total_results": 1
|
| 182 |
+
}
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
**Response (with extraction):**
|
| 186 |
+
|
| 187 |
+
```json
|
| 188 |
+
{
|
| 189 |
+
"query": "nvidia earnings",
|
| 190 |
+
"backend": "news",
|
| 191 |
+
"results": [
|
| 192 |
{
|
| 193 |
+
"title": "Nvidia earnings report",
|
| 194 |
+
"url": "https://...",
|
| 195 |
+
"content": "Short snippet...",
|
| 196 |
+
"source": "Reuters",
|
| 197 |
+
"date": "2026-08-27T00:00:00+00:00",
|
| 198 |
+
"extracted_content": "Full article text, up to 8000 characters..."
|
| 199 |
}
|
| 200 |
],
|
| 201 |
+
"total_results": 1
|
| 202 |
}
|
| 203 |
```
|
| 204 |
|
|
|
|
| 207 |
| Status | Body | Cause |
|
| 208 |
|---|---|---|
|
| 209 |
| 400 | `{"error": "Missing query parameter 'q'"}` | No query provided |
|
| 210 |
+
| 400 | `{"error": "Invalid backend 'x'. Use 'text', 'news', or 'images'."}` | Bad backend value |
|
| 211 |
| 502 | `{"error": "..."}` | Search backend unreachable |
|
| 212 |
|
| 213 |
---
|
|
|
|
| 290 |
|
| 291 |
1. **Discover capabilities at runtime** β Call `GET /respite/resources` to enumerate what the API can do. Do not hardcode resource names.
|
| 292 |
|
| 293 |
+
2. **Search strategies by query type:**
|
| 294 |
+
|
| 295 |
+
| Query type | Backend | extract_top | Region |
|
| 296 |
+
|---|---|---|---|
|
| 297 |
+
| Current events, news | `news` | 2-3 | user's region |
|
| 298 |
+
| Factual questions | `text` | 1 | `wt-wt` |
|
| 299 |
+
| How-to, tutorials | `text` | 0 | `wt-wt` |
|
| 300 |
+
| Recent developments | `news` | 0 | `wt-wt` |
|
| 301 |
+
| Images, visuals | `images` | 0 | user's region |
|
| 302 |
+
|
| 303 |
+
3. **Use extraction for depth** β When a user wants detailed information (e.g., "summarize this article"), set `extract_top=1` to get the full page content. Don't overuse it β it adds latency.
|
| 304 |
|
| 305 |
+
4. **Audio generation is queued** β Only 1 generation runs at a time. If the queue is full (503), retry with exponential backoff. Do not retry rapidly.
|
| 306 |
|
| 307 |
+
5. **Model selection** β Use `"small-music"` for music, melodies, ambient sound. Use `"small-sfx"` for sound effects, foley, short percussive sounds.
|
| 308 |
|
| 309 |
+
6. **Response handling** β `/respite/audio/generate` returns binary WAV, not JSON. Save to a `.wav` file and play/serve it. Do not try to JSON-parse the response body.
|
| 310 |
|
| 311 |
+
7. **Specs for capability planning** β `GET /respite/specs` tells you GPU type, VRAM, and queue limits. Use this to decide what to offer users (e.g., don't promise 4-minute tracks β max is 120s).
|
| 312 |
|
| 313 |
+
8. **Graceful degradation** β If the API is down (503, 502), tell the user the service is temporarily unavailable rather than hanging. ZeroGPU Spaces can go cold when idle.
|