perplexityai 0.3.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of perplexityai might be problematic. Click here for more details.
- perplexityai-0.5.0/.release-please-manifest.json +3 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/CHANGELOG.md +21 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/PKG-INFO +19 -19
- {perplexityai-0.3.0 → perplexityai-0.5.0}/README.md +18 -18
- perplexityai-0.5.0/api.md +11 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/pyproject.toml +1 -1
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_client.py +24 -24
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_version.py +1 -1
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/resources/search.py +18 -18
- perplexityai-0.5.0/src/perplexity/types/__init__.py +6 -0
- perplexityai-0.3.0/src/perplexity/types/search_perform_params.py → perplexityai-0.5.0/src/perplexity/types/search_create_params.py +2 -2
- perplexityai-0.3.0/src/perplexity/types/search_perform_response.py → perplexityai-0.5.0/src/perplexity/types/search_create_response.py +2 -2
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/api_resources/test_search.py +25 -25
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/conftest.py +3 -3
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_client.py +73 -111
- perplexityai-0.3.0/.release-please-manifest.json +0 -3
- perplexityai-0.3.0/api.md +0 -11
- perplexityai-0.3.0/src/perplexity/types/__init__.py +0 -6
- {perplexityai-0.3.0 → perplexityai-0.5.0}/.gitignore +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/CONTRIBUTING.md +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/LICENSE +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/SECURITY.md +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/bin/check-release-environment +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/bin/publish-pypi +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/examples/.keep +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/noxfile.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/release-please-config.json +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/requirements-dev.lock +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/requirements.lock +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/__init__.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_base_client.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_compat.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_constants.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_exceptions.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_files.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_models.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_qs.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_resource.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_response.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_streaming.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_types.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/__init__.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_compat.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_datetime_parse.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_logs.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_proxy.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_reflection.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_resources_proxy.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_streams.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_sync.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_transform.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_typing.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/_utils/_utils.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/lib/.keep +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/py.typed +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/src/perplexity/resources/__init__.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/__init__.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/api_resources/__init__.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/sample_file.txt +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_deepcopy.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_extract_files.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_files.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_models.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_qs.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_required_args.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_response.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_streaming.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_transform.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_utils/test_datetime_parse.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_utils/test_proxy.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/test_utils/test_typing.py +0 -0
- {perplexityai-0.3.0 → perplexityai-0.5.0}/tests/utils.py +0 -0
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0 (2025-09-08)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [v0.4.0...v0.5.0](https://github.com/ppl-ai/perplexity-py/compare/v0.4.0...v0.5.0)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* **api:** change bearer_token to api_key ([875bba1](https://github.com/ppl-ai/perplexity-py/commit/875bba126072093d572f00818746b0637a1a56a6))
|
|
10
|
+
|
|
11
|
+
## 0.4.0 (2025-09-07)
|
|
12
|
+
|
|
13
|
+
Full Changelog: [v0.3.0...v0.4.0](https://github.com/ppl-ai/perplexity-py/compare/v0.3.0...v0.4.0)
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **api:** update from perform -> create ([35d2c42](https://github.com/ppl-ai/perplexity-py/commit/35d2c42567e59d53b37be7d4699f80755c09ca30))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Chores
|
|
21
|
+
|
|
22
|
+
* update SDK settings ([a5a9d00](https://github.com/ppl-ai/perplexity-py/commit/a5a9d0009d07b48cf9b5f4521705acdb6878c904))
|
|
23
|
+
|
|
3
24
|
## 0.3.0 (2025-09-07)
|
|
4
25
|
|
|
5
26
|
Full Changelog: [v0.2.1...v0.3.0](https://github.com/ppl-ai/perplexity-py/compare/v0.2.1...v0.3.0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: perplexityai
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: The official Python library for the perplexity API
|
|
5
5
|
Project-URL: Homepage, https://github.com/ppl-ai/perplexity-py
|
|
6
6
|
Project-URL: Repository, https://github.com/ppl-ai/perplexity-py
|
|
@@ -64,19 +64,19 @@ import os
|
|
|
64
64
|
from perplexity import Perplexity
|
|
65
65
|
|
|
66
66
|
client = Perplexity(
|
|
67
|
-
|
|
67
|
+
api_key=os.environ.get("PERPLEXITY_API_KEY"), # This is the default and can be omitted
|
|
68
68
|
)
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
search = client.search.create(
|
|
71
71
|
query="string",
|
|
72
72
|
)
|
|
73
|
-
print(
|
|
73
|
+
print(search.id)
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
While you can provide
|
|
76
|
+
While you can provide an `api_key` keyword argument,
|
|
77
77
|
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
|
|
78
|
-
to add `PERPLEXITY_API_KEY="My
|
|
79
|
-
so that your
|
|
78
|
+
to add `PERPLEXITY_API_KEY="My API Key"` to your `.env` file
|
|
79
|
+
so that your API Key is not stored in source control.
|
|
80
80
|
|
|
81
81
|
## Async usage
|
|
82
82
|
|
|
@@ -88,15 +88,15 @@ import asyncio
|
|
|
88
88
|
from perplexity import AsyncPerplexity
|
|
89
89
|
|
|
90
90
|
client = AsyncPerplexity(
|
|
91
|
-
|
|
91
|
+
api_key=os.environ.get("PERPLEXITY_API_KEY"), # This is the default and can be omitted
|
|
92
92
|
)
|
|
93
93
|
|
|
94
94
|
|
|
95
95
|
async def main() -> None:
|
|
96
|
-
|
|
96
|
+
search = await client.search.create(
|
|
97
97
|
query="string",
|
|
98
98
|
)
|
|
99
|
-
print(
|
|
99
|
+
print(search.id)
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
asyncio.run(main())
|
|
@@ -125,13 +125,13 @@ from perplexity import AsyncPerplexity
|
|
|
125
125
|
|
|
126
126
|
async def main() -> None:
|
|
127
127
|
async with AsyncPerplexity(
|
|
128
|
-
|
|
128
|
+
api_key="My API Key",
|
|
129
129
|
http_client=DefaultAioHttpClient(),
|
|
130
130
|
) as client:
|
|
131
|
-
|
|
131
|
+
search = await client.search.create(
|
|
132
132
|
query="string",
|
|
133
133
|
)
|
|
134
|
-
print(
|
|
134
|
+
print(search.id)
|
|
135
135
|
|
|
136
136
|
|
|
137
137
|
asyncio.run(main())
|
|
@@ -162,7 +162,7 @@ from perplexity import Perplexity
|
|
|
162
162
|
client = Perplexity()
|
|
163
163
|
|
|
164
164
|
try:
|
|
165
|
-
client.search.
|
|
165
|
+
client.search.create(
|
|
166
166
|
query="string",
|
|
167
167
|
)
|
|
168
168
|
except perplexity.APIConnectionError as e:
|
|
@@ -207,7 +207,7 @@ client = Perplexity(
|
|
|
207
207
|
)
|
|
208
208
|
|
|
209
209
|
# Or, configure per-request:
|
|
210
|
-
client.with_options(max_retries=5).search.
|
|
210
|
+
client.with_options(max_retries=5).search.create(
|
|
211
211
|
query="string",
|
|
212
212
|
)
|
|
213
213
|
```
|
|
@@ -232,7 +232,7 @@ client = Perplexity(
|
|
|
232
232
|
)
|
|
233
233
|
|
|
234
234
|
# Override per-request:
|
|
235
|
-
client.with_options(timeout=5.0).search.
|
|
235
|
+
client.with_options(timeout=5.0).search.create(
|
|
236
236
|
query="string",
|
|
237
237
|
)
|
|
238
238
|
```
|
|
@@ -275,12 +275,12 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
|
|
|
275
275
|
from perplexity import Perplexity
|
|
276
276
|
|
|
277
277
|
client = Perplexity()
|
|
278
|
-
response = client.search.with_raw_response.
|
|
278
|
+
response = client.search.with_raw_response.create(
|
|
279
279
|
query="string",
|
|
280
280
|
)
|
|
281
281
|
print(response.headers.get('X-My-Header'))
|
|
282
282
|
|
|
283
|
-
search = response.parse() # get the object that `search.
|
|
283
|
+
search = response.parse() # get the object that `search.create()` would have returned
|
|
284
284
|
print(search.id)
|
|
285
285
|
```
|
|
286
286
|
|
|
@@ -295,7 +295,7 @@ The above interface eagerly reads the full response body when you make the reque
|
|
|
295
295
|
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
|
|
296
296
|
|
|
297
297
|
```python
|
|
298
|
-
with client.search.with_streaming_response.
|
|
298
|
+
with client.search.with_streaming_response.create(
|
|
299
299
|
query="string",
|
|
300
300
|
) as response:
|
|
301
301
|
print(response.headers.get("X-My-Header"))
|
|
@@ -29,19 +29,19 @@ import os
|
|
|
29
29
|
from perplexity import Perplexity
|
|
30
30
|
|
|
31
31
|
client = Perplexity(
|
|
32
|
-
|
|
32
|
+
api_key=os.environ.get("PERPLEXITY_API_KEY"), # This is the default and can be omitted
|
|
33
33
|
)
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
search = client.search.create(
|
|
36
36
|
query="string",
|
|
37
37
|
)
|
|
38
|
-
print(
|
|
38
|
+
print(search.id)
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
While you can provide
|
|
41
|
+
While you can provide an `api_key` keyword argument,
|
|
42
42
|
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
|
|
43
|
-
to add `PERPLEXITY_API_KEY="My
|
|
44
|
-
so that your
|
|
43
|
+
to add `PERPLEXITY_API_KEY="My API Key"` to your `.env` file
|
|
44
|
+
so that your API Key is not stored in source control.
|
|
45
45
|
|
|
46
46
|
## Async usage
|
|
47
47
|
|
|
@@ -53,15 +53,15 @@ import asyncio
|
|
|
53
53
|
from perplexity import AsyncPerplexity
|
|
54
54
|
|
|
55
55
|
client = AsyncPerplexity(
|
|
56
|
-
|
|
56
|
+
api_key=os.environ.get("PERPLEXITY_API_KEY"), # This is the default and can be omitted
|
|
57
57
|
)
|
|
58
58
|
|
|
59
59
|
|
|
60
60
|
async def main() -> None:
|
|
61
|
-
|
|
61
|
+
search = await client.search.create(
|
|
62
62
|
query="string",
|
|
63
63
|
)
|
|
64
|
-
print(
|
|
64
|
+
print(search.id)
|
|
65
65
|
|
|
66
66
|
|
|
67
67
|
asyncio.run(main())
|
|
@@ -90,13 +90,13 @@ from perplexity import AsyncPerplexity
|
|
|
90
90
|
|
|
91
91
|
async def main() -> None:
|
|
92
92
|
async with AsyncPerplexity(
|
|
93
|
-
|
|
93
|
+
api_key="My API Key",
|
|
94
94
|
http_client=DefaultAioHttpClient(),
|
|
95
95
|
) as client:
|
|
96
|
-
|
|
96
|
+
search = await client.search.create(
|
|
97
97
|
query="string",
|
|
98
98
|
)
|
|
99
|
-
print(
|
|
99
|
+
print(search.id)
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
asyncio.run(main())
|
|
@@ -127,7 +127,7 @@ from perplexity import Perplexity
|
|
|
127
127
|
client = Perplexity()
|
|
128
128
|
|
|
129
129
|
try:
|
|
130
|
-
client.search.
|
|
130
|
+
client.search.create(
|
|
131
131
|
query="string",
|
|
132
132
|
)
|
|
133
133
|
except perplexity.APIConnectionError as e:
|
|
@@ -172,7 +172,7 @@ client = Perplexity(
|
|
|
172
172
|
)
|
|
173
173
|
|
|
174
174
|
# Or, configure per-request:
|
|
175
|
-
client.with_options(max_retries=5).search.
|
|
175
|
+
client.with_options(max_retries=5).search.create(
|
|
176
176
|
query="string",
|
|
177
177
|
)
|
|
178
178
|
```
|
|
@@ -197,7 +197,7 @@ client = Perplexity(
|
|
|
197
197
|
)
|
|
198
198
|
|
|
199
199
|
# Override per-request:
|
|
200
|
-
client.with_options(timeout=5.0).search.
|
|
200
|
+
client.with_options(timeout=5.0).search.create(
|
|
201
201
|
query="string",
|
|
202
202
|
)
|
|
203
203
|
```
|
|
@@ -240,12 +240,12 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
|
|
|
240
240
|
from perplexity import Perplexity
|
|
241
241
|
|
|
242
242
|
client = Perplexity()
|
|
243
|
-
response = client.search.with_raw_response.
|
|
243
|
+
response = client.search.with_raw_response.create(
|
|
244
244
|
query="string",
|
|
245
245
|
)
|
|
246
246
|
print(response.headers.get('X-My-Header'))
|
|
247
247
|
|
|
248
|
-
search = response.parse() # get the object that `search.
|
|
248
|
+
search = response.parse() # get the object that `search.create()` would have returned
|
|
249
249
|
print(search.id)
|
|
250
250
|
```
|
|
251
251
|
|
|
@@ -260,7 +260,7 @@ The above interface eagerly reads the full response body when you make the reque
|
|
|
260
260
|
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
|
|
261
261
|
|
|
262
262
|
```python
|
|
263
|
-
with client.search.with_streaming_response.
|
|
263
|
+
with client.search.with_streaming_response.create(
|
|
264
264
|
query="string",
|
|
265
265
|
) as response:
|
|
266
266
|
print(response.headers.get("X-My-Header"))
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Search
|
|
2
|
+
|
|
3
|
+
Types:
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from perplexity.types import SearchCreateResponse
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Methods:
|
|
10
|
+
|
|
11
|
+
- <code title="post /search">client.search.<a href="./src/perplexity/resources/search.py">create</a>(\*\*<a href="src/perplexity/types/search_create_params.py">params</a>) -> <a href="./src/perplexity/types/search_create_response.py">SearchCreateResponse</a></code>
|
|
@@ -48,12 +48,12 @@ class Perplexity(SyncAPIClient):
|
|
|
48
48
|
with_streaming_response: PerplexityWithStreamedResponse
|
|
49
49
|
|
|
50
50
|
# client options
|
|
51
|
-
|
|
51
|
+
api_key: str
|
|
52
52
|
|
|
53
53
|
def __init__(
|
|
54
54
|
self,
|
|
55
55
|
*,
|
|
56
|
-
|
|
56
|
+
api_key: str | None = None,
|
|
57
57
|
base_url: str | httpx.URL | None = None,
|
|
58
58
|
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
|
|
59
59
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
@@ -75,15 +75,15 @@ class Perplexity(SyncAPIClient):
|
|
|
75
75
|
) -> None:
|
|
76
76
|
"""Construct a new synchronous Perplexity client instance.
|
|
77
77
|
|
|
78
|
-
This automatically infers the `
|
|
78
|
+
This automatically infers the `api_key` argument from the `PERPLEXITY_API_KEY` environment variable if it is not provided.
|
|
79
79
|
"""
|
|
80
|
-
if
|
|
81
|
-
|
|
82
|
-
if
|
|
80
|
+
if api_key is None:
|
|
81
|
+
api_key = os.environ.get("PERPLEXITY_API_KEY")
|
|
82
|
+
if api_key is None:
|
|
83
83
|
raise PerplexityError(
|
|
84
|
-
"The
|
|
84
|
+
"The api_key client option must be set either by passing api_key to the client or by setting the PERPLEXITY_API_KEY environment variable"
|
|
85
85
|
)
|
|
86
|
-
self.
|
|
86
|
+
self.api_key = api_key
|
|
87
87
|
|
|
88
88
|
if base_url is None:
|
|
89
89
|
base_url = os.environ.get("PERPLEXITY_BASE_URL")
|
|
@@ -113,8 +113,8 @@ class Perplexity(SyncAPIClient):
|
|
|
113
113
|
@property
|
|
114
114
|
@override
|
|
115
115
|
def auth_headers(self) -> dict[str, str]:
|
|
116
|
-
|
|
117
|
-
return {"Authorization": f"Bearer {
|
|
116
|
+
api_key = self.api_key
|
|
117
|
+
return {"Authorization": f"Bearer {api_key}"}
|
|
118
118
|
|
|
119
119
|
@property
|
|
120
120
|
@override
|
|
@@ -128,7 +128,7 @@ class Perplexity(SyncAPIClient):
|
|
|
128
128
|
def copy(
|
|
129
129
|
self,
|
|
130
130
|
*,
|
|
131
|
-
|
|
131
|
+
api_key: str | None = None,
|
|
132
132
|
base_url: str | httpx.URL | None = None,
|
|
133
133
|
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
|
134
134
|
http_client: httpx.Client | None = None,
|
|
@@ -162,7 +162,7 @@ class Perplexity(SyncAPIClient):
|
|
|
162
162
|
|
|
163
163
|
http_client = http_client or self._client
|
|
164
164
|
return self.__class__(
|
|
165
|
-
|
|
165
|
+
api_key=api_key or self.api_key,
|
|
166
166
|
base_url=base_url or self.base_url,
|
|
167
167
|
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
|
168
168
|
http_client=http_client,
|
|
@@ -216,12 +216,12 @@ class AsyncPerplexity(AsyncAPIClient):
|
|
|
216
216
|
with_streaming_response: AsyncPerplexityWithStreamedResponse
|
|
217
217
|
|
|
218
218
|
# client options
|
|
219
|
-
|
|
219
|
+
api_key: str
|
|
220
220
|
|
|
221
221
|
def __init__(
|
|
222
222
|
self,
|
|
223
223
|
*,
|
|
224
|
-
|
|
224
|
+
api_key: str | None = None,
|
|
225
225
|
base_url: str | httpx.URL | None = None,
|
|
226
226
|
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
|
|
227
227
|
max_retries: int = DEFAULT_MAX_RETRIES,
|
|
@@ -243,15 +243,15 @@ class AsyncPerplexity(AsyncAPIClient):
|
|
|
243
243
|
) -> None:
|
|
244
244
|
"""Construct a new async AsyncPerplexity client instance.
|
|
245
245
|
|
|
246
|
-
This automatically infers the `
|
|
246
|
+
This automatically infers the `api_key` argument from the `PERPLEXITY_API_KEY` environment variable if it is not provided.
|
|
247
247
|
"""
|
|
248
|
-
if
|
|
249
|
-
|
|
250
|
-
if
|
|
248
|
+
if api_key is None:
|
|
249
|
+
api_key = os.environ.get("PERPLEXITY_API_KEY")
|
|
250
|
+
if api_key is None:
|
|
251
251
|
raise PerplexityError(
|
|
252
|
-
"The
|
|
252
|
+
"The api_key client option must be set either by passing api_key to the client or by setting the PERPLEXITY_API_KEY environment variable"
|
|
253
253
|
)
|
|
254
|
-
self.
|
|
254
|
+
self.api_key = api_key
|
|
255
255
|
|
|
256
256
|
if base_url is None:
|
|
257
257
|
base_url = os.environ.get("PERPLEXITY_BASE_URL")
|
|
@@ -281,8 +281,8 @@ class AsyncPerplexity(AsyncAPIClient):
|
|
|
281
281
|
@property
|
|
282
282
|
@override
|
|
283
283
|
def auth_headers(self) -> dict[str, str]:
|
|
284
|
-
|
|
285
|
-
return {"Authorization": f"Bearer {
|
|
284
|
+
api_key = self.api_key
|
|
285
|
+
return {"Authorization": f"Bearer {api_key}"}
|
|
286
286
|
|
|
287
287
|
@property
|
|
288
288
|
@override
|
|
@@ -296,7 +296,7 @@ class AsyncPerplexity(AsyncAPIClient):
|
|
|
296
296
|
def copy(
|
|
297
297
|
self,
|
|
298
298
|
*,
|
|
299
|
-
|
|
299
|
+
api_key: str | None = None,
|
|
300
300
|
base_url: str | httpx.URL | None = None,
|
|
301
301
|
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
|
302
302
|
http_client: httpx.AsyncClient | None = None,
|
|
@@ -330,7 +330,7 @@ class AsyncPerplexity(AsyncAPIClient):
|
|
|
330
330
|
|
|
331
331
|
http_client = http_client or self._client
|
|
332
332
|
return self.__class__(
|
|
333
|
-
|
|
333
|
+
api_key=api_key or self.api_key,
|
|
334
334
|
base_url=base_url or self.base_url,
|
|
335
335
|
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
|
336
336
|
http_client=http_client,
|
|
@@ -7,7 +7,7 @@ from typing_extensions import Literal
|
|
|
7
7
|
|
|
8
8
|
import httpx
|
|
9
9
|
|
|
10
|
-
from ..types import
|
|
10
|
+
from ..types import search_create_params
|
|
11
11
|
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
|
|
12
12
|
from .._utils import maybe_transform, async_maybe_transform
|
|
13
13
|
from .._compat import cached_property
|
|
@@ -19,7 +19,7 @@ from .._response import (
|
|
|
19
19
|
async_to_streamed_response_wrapper,
|
|
20
20
|
)
|
|
21
21
|
from .._base_client import make_request_options
|
|
22
|
-
from ..types.
|
|
22
|
+
from ..types.search_create_response import SearchCreateResponse
|
|
23
23
|
|
|
24
24
|
__all__ = ["SearchResource", "AsyncSearchResource"]
|
|
25
25
|
|
|
@@ -44,7 +44,7 @@ class SearchResource(SyncAPIResource):
|
|
|
44
44
|
"""
|
|
45
45
|
return SearchResourceWithStreamingResponse(self)
|
|
46
46
|
|
|
47
|
-
def
|
|
47
|
+
def create(
|
|
48
48
|
self,
|
|
49
49
|
*,
|
|
50
50
|
query: Union[str, SequenceNotStr[str]],
|
|
@@ -65,7 +65,7 @@ class SearchResource(SyncAPIResource):
|
|
|
65
65
|
extra_query: Query | None = None,
|
|
66
66
|
extra_body: Body | None = None,
|
|
67
67
|
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
68
|
-
) ->
|
|
68
|
+
) -> SearchCreateResponse:
|
|
69
69
|
"""
|
|
70
70
|
Search
|
|
71
71
|
|
|
@@ -95,12 +95,12 @@ class SearchResource(SyncAPIResource):
|
|
|
95
95
|
"search_mode": search_mode,
|
|
96
96
|
"search_recency_filter": search_recency_filter,
|
|
97
97
|
},
|
|
98
|
-
|
|
98
|
+
search_create_params.SearchCreateParams,
|
|
99
99
|
),
|
|
100
100
|
options=make_request_options(
|
|
101
101
|
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
102
102
|
),
|
|
103
|
-
cast_to=
|
|
103
|
+
cast_to=SearchCreateResponse,
|
|
104
104
|
)
|
|
105
105
|
|
|
106
106
|
|
|
@@ -124,7 +124,7 @@ class AsyncSearchResource(AsyncAPIResource):
|
|
|
124
124
|
"""
|
|
125
125
|
return AsyncSearchResourceWithStreamingResponse(self)
|
|
126
126
|
|
|
127
|
-
async def
|
|
127
|
+
async def create(
|
|
128
128
|
self,
|
|
129
129
|
*,
|
|
130
130
|
query: Union[str, SequenceNotStr[str]],
|
|
@@ -145,7 +145,7 @@ class AsyncSearchResource(AsyncAPIResource):
|
|
|
145
145
|
extra_query: Query | None = None,
|
|
146
146
|
extra_body: Body | None = None,
|
|
147
147
|
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
148
|
-
) ->
|
|
148
|
+
) -> SearchCreateResponse:
|
|
149
149
|
"""
|
|
150
150
|
Search
|
|
151
151
|
|
|
@@ -175,12 +175,12 @@ class AsyncSearchResource(AsyncAPIResource):
|
|
|
175
175
|
"search_mode": search_mode,
|
|
176
176
|
"search_recency_filter": search_recency_filter,
|
|
177
177
|
},
|
|
178
|
-
|
|
178
|
+
search_create_params.SearchCreateParams,
|
|
179
179
|
),
|
|
180
180
|
options=make_request_options(
|
|
181
181
|
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
182
182
|
),
|
|
183
|
-
cast_to=
|
|
183
|
+
cast_to=SearchCreateResponse,
|
|
184
184
|
)
|
|
185
185
|
|
|
186
186
|
|
|
@@ -188,8 +188,8 @@ class SearchResourceWithRawResponse:
|
|
|
188
188
|
def __init__(self, search: SearchResource) -> None:
|
|
189
189
|
self._search = search
|
|
190
190
|
|
|
191
|
-
self.
|
|
192
|
-
search.
|
|
191
|
+
self.create = to_raw_response_wrapper(
|
|
192
|
+
search.create,
|
|
193
193
|
)
|
|
194
194
|
|
|
195
195
|
|
|
@@ -197,8 +197,8 @@ class AsyncSearchResourceWithRawResponse:
|
|
|
197
197
|
def __init__(self, search: AsyncSearchResource) -> None:
|
|
198
198
|
self._search = search
|
|
199
199
|
|
|
200
|
-
self.
|
|
201
|
-
search.
|
|
200
|
+
self.create = async_to_raw_response_wrapper(
|
|
201
|
+
search.create,
|
|
202
202
|
)
|
|
203
203
|
|
|
204
204
|
|
|
@@ -206,8 +206,8 @@ class SearchResourceWithStreamingResponse:
|
|
|
206
206
|
def __init__(self, search: SearchResource) -> None:
|
|
207
207
|
self._search = search
|
|
208
208
|
|
|
209
|
-
self.
|
|
210
|
-
search.
|
|
209
|
+
self.create = to_streamed_response_wrapper(
|
|
210
|
+
search.create,
|
|
211
211
|
)
|
|
212
212
|
|
|
213
213
|
|
|
@@ -215,6 +215,6 @@ class AsyncSearchResourceWithStreamingResponse:
|
|
|
215
215
|
def __init__(self, search: AsyncSearchResource) -> None:
|
|
216
216
|
self._search = search
|
|
217
217
|
|
|
218
|
-
self.
|
|
219
|
-
search.
|
|
218
|
+
self.create = async_to_streamed_response_wrapper(
|
|
219
|
+
search.create,
|
|
220
220
|
)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .search_create_params import SearchCreateParams as SearchCreateParams
|
|
6
|
+
from .search_create_response import SearchCreateResponse as SearchCreateResponse
|
|
@@ -7,10 +7,10 @@ from typing_extensions import Literal, Required, TypedDict
|
|
|
7
7
|
|
|
8
8
|
from .._types import SequenceNotStr
|
|
9
9
|
|
|
10
|
-
__all__ = ["
|
|
10
|
+
__all__ = ["SearchCreateParams"]
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
class
|
|
13
|
+
class SearchCreateParams(TypedDict, total=False):
|
|
14
14
|
query: Required[Union[str, SequenceNotStr[str]]]
|
|
15
15
|
|
|
16
16
|
country: Optional[str]
|
|
@@ -4,7 +4,7 @@ from typing import List, Optional
|
|
|
4
4
|
|
|
5
5
|
from .._models import BaseModel
|
|
6
6
|
|
|
7
|
-
__all__ = ["
|
|
7
|
+
__all__ = ["SearchCreateResponse", "Result"]
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class Result(BaseModel):
|
|
@@ -19,7 +19,7 @@ class Result(BaseModel):
|
|
|
19
19
|
last_updated: Optional[str] = None
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
class
|
|
22
|
+
class SearchCreateResponse(BaseModel):
|
|
23
23
|
id: str
|
|
24
24
|
|
|
25
25
|
results: List[Result]
|