Skip to content

Commit d51115b

Browse files
authored
Instant search function (#8)
* Instant search endpoint introduced * Bump version
1 parent 195ff93 commit d51115b

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "oxylabs-ai-studio"
3-
version = "0.2.17"
3+
version = "0.2.18"
44
description = "Oxylabs studio python sdk"
55
readme = "README.md"
66
keywords = ["oxylabs", "ai", "studio"]

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ print(result.data)
132132
- `return_content` (bool): Whether to return markdown contents in results (default: True)
133133
- `geo_location` (str): search proxy location in ISO2 format.
134134

135+
> **Note:** When `limit <= 10` and `return_content=False`, the search automatically uses the instant endpoint (`/search/instant`) which returns results immediately without polling, providing faster response times.
136+
135137
### Map (`AiMap.map`)
136138
```python
137139
from oxylabs_ai_studio.apps.ai_map import AiMap

src/oxylabs_ai_studio/apps/ai_search.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ def search(
5050
"return_content": return_content,
5151
"geo_location": geo_location,
5252
}
53+
# Use instant endpoint if limit <= 10 and return_content is False
54+
if limit <= 10 and not return_content:
55+
client = self.get_client()
56+
response = self.call_api(
57+
client=client, url="/search/instant", method="POST", body=body
58+
)
59+
status_code = response.status_code
60+
if status_code != 200:
61+
raise Exception(f"Failed to perform instant search: `{response.text}`")
62+
63+
resp_body = response.json()
64+
return AiSearchJob(
65+
run_id=resp_body["run_id"],
66+
message=resp_body.get("message", None),
67+
data=resp_body.get("data", None),
68+
)
69+
70+
# Use regular polling endpoint
5371
client = self.get_client()
5472
create_response = self.call_api(
5573
client=client, url="/search/run", method="POST", body=body
@@ -118,6 +136,25 @@ async def search_async(
118136
"geo_location": geo_location,
119137
}
120138
async with self.async_client() as client:
139+
# Use instant endpoint if limit <= 10 and return_content is False
140+
if limit <= 10 and not return_content:
141+
response = await self.call_api_async(
142+
client=client, url="/search/instant", method="POST", body=body
143+
)
144+
status_code = response.status_code
145+
if status_code != 200:
146+
raise Exception(
147+
f"Failed to perform instant search: `{response.text}`"
148+
)
149+
150+
resp_body = response.json()
151+
return AiSearchJob(
152+
run_id=resp_body["run_id"],
153+
message=resp_body.get("message", None),
154+
data=resp_body.get("data", None),
155+
)
156+
157+
# Use regular polling endpoint
121158
create_response = await self.call_api_async(
122159
client=client, url="/search/run", method="POST", body=body
123160
)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)