perplexityai 0.5.0__tar.gz → 0.7.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 → perplexityai-0.7.0}/.gitignore +2 -0
- perplexityai-0.7.0/.release-please-manifest.json +3 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/CHANGELOG.md +17 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/PKG-INFO +90 -22
- {perplexityai-0.5.0 → perplexityai-0.7.0}/README.md +89 -21
- perplexityai-0.7.0/api.md +65 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/pyproject.toml +1 -1
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_client.py +27 -1
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_version.py +1 -1
- perplexityai-0.7.0/src/perplexity/resources/__init__.py +61 -0
- perplexityai-0.7.0/src/perplexity/resources/async_/__init__.py +33 -0
- perplexityai-0.7.0/src/perplexity/resources/async_/async_.py +102 -0
- perplexityai-0.7.0/src/perplexity/resources/async_/chat/__init__.py +33 -0
- perplexityai-0.7.0/src/perplexity/resources/async_/chat/chat.py +102 -0
- perplexityai-0.7.0/src/perplexity/resources/async_/chat/completions.py +347 -0
- perplexityai-0.7.0/src/perplexity/resources/chat/__init__.py +33 -0
- perplexityai-0.7.0/src/perplexity/resources/chat/chat.py +102 -0
- perplexityai-0.7.0/src/perplexity/resources/chat/completions.py +295 -0
- perplexityai-0.7.0/src/perplexity/resources/content.py +167 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/resources/search.py +64 -2
- perplexityai-0.7.0/src/perplexity/types/__init__.py +14 -0
- perplexityai-0.7.0/src/perplexity/types/async_/__init__.py +3 -0
- perplexityai-0.7.0/src/perplexity/types/async_/chat/__init__.py +9 -0
- perplexityai-0.7.0/src/perplexity/types/async_/chat/completion_create_params.py +94 -0
- perplexityai-0.7.0/src/perplexity/types/async_/chat/completion_create_response.py +54 -0
- perplexityai-0.7.0/src/perplexity/types/async_/chat/completion_get_response.py +54 -0
- perplexityai-0.7.0/src/perplexity/types/async_/chat/completion_list_params.py +15 -0
- perplexityai-0.7.0/src/perplexity/types/async_/chat/completion_list_response.py +31 -0
- perplexityai-0.7.0/src/perplexity/types/chat/__init__.py +6 -0
- perplexityai-0.7.0/src/perplexity/types/chat/completion_create_params.py +90 -0
- perplexityai-0.7.0/src/perplexity/types/chat/completion_create_response.py +30 -0
- perplexityai-0.7.0/src/perplexity/types/content_create_params.py +14 -0
- perplexityai-0.7.0/src/perplexity/types/content_create_response.py +29 -0
- perplexityai-0.7.0/src/perplexity/types/search_create_params.py +62 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/types/search_create_response.py +7 -0
- perplexityai-0.7.0/src/perplexity/types/shared/__init__.py +6 -0
- perplexityai-0.7.0/src/perplexity/types/shared/chat_choice.py +17 -0
- perplexityai-0.7.0/src/perplexity/types/shared/chat_message.py +31 -0
- perplexityai-0.7.0/src/perplexity/types/shared/search_result.py +15 -0
- perplexityai-0.7.0/src/perplexity/types/shared/usage_info.py +23 -0
- perplexityai-0.7.0/src/perplexity/types/shared_params/__init__.py +3 -0
- perplexityai-0.7.0/src/perplexity/types/shared_params/chat_message.py +31 -0
- perplexityai-0.7.0/tests/api_resources/async_/__init__.py +1 -0
- perplexityai-0.7.0/tests/api_resources/async_/chat/__init__.py +1 -0
- perplexityai-0.7.0/tests/api_resources/async_/chat/test_completions.py +380 -0
- perplexityai-0.7.0/tests/api_resources/chat/__init__.py +1 -0
- perplexityai-0.7.0/tests/api_resources/chat/test_completions.py +202 -0
- perplexityai-0.7.0/tests/api_resources/test_content.py +92 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/api_resources/test_search.py +2 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_client.py +104 -28
- perplexityai-0.5.0/.release-please-manifest.json +0 -3
- perplexityai-0.5.0/api.md +0 -11
- perplexityai-0.5.0/src/perplexity/resources/__init__.py +0 -19
- perplexityai-0.5.0/src/perplexity/types/__init__.py +0 -6
- perplexityai-0.5.0/src/perplexity/types/search_create_params.py +0 -36
- {perplexityai-0.5.0 → perplexityai-0.7.0}/CONTRIBUTING.md +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/LICENSE +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/SECURITY.md +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/bin/check-release-environment +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/bin/publish-pypi +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/examples/.keep +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/noxfile.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/release-please-config.json +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/requirements-dev.lock +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/requirements.lock +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/__init__.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_base_client.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_compat.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_constants.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_exceptions.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_files.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_models.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_qs.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_resource.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_response.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_streaming.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_types.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/__init__.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_compat.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_datetime_parse.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_logs.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_proxy.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_reflection.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_resources_proxy.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_streams.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_sync.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_transform.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_typing.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/_utils/_utils.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/lib/.keep +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/src/perplexity/py.typed +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/__init__.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/api_resources/__init__.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/conftest.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/sample_file.txt +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_deepcopy.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_extract_files.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_files.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_models.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_qs.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_required_args.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_response.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_streaming.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_transform.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_utils/test_datetime_parse.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_utils/test_proxy.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/test_utils/test_typing.py +0 -0
- {perplexityai-0.5.0 → perplexityai-0.7.0}/tests/utils.py +0 -0
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0 (2025-09-10)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [v0.6.0...v0.7.0](https://github.com/ppl-ai/perplexity-py/compare/v0.6.0...v0.7.0)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* **api:** add /chat/completions and /async/chat/completions ([945f7c2](https://github.com/ppl-ai/perplexity-py/commit/945f7c27c80ca90f6c703590578a414351e0adb2))
|
|
10
|
+
|
|
11
|
+
## 0.6.0 (2025-09-08)
|
|
12
|
+
|
|
13
|
+
Full Changelog: [v0.5.0...v0.6.0](https://github.com/ppl-ai/perplexity-py/compare/v0.5.0...v0.6.0)
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **api:** add /content endpoint ([a83e23b](https://github.com/ppl-ai/perplexity-py/commit/a83e23bbcacc8b80748ccf512f3a287ed6011a37))
|
|
18
|
+
* **api:** include /content endpoint ([d30ca3e](https://github.com/ppl-ai/perplexity-py/commit/d30ca3e3697f8fd5e17f00762ab2a89ea4d5814f))
|
|
19
|
+
|
|
3
20
|
## 0.5.0 (2025-09-08)
|
|
4
21
|
|
|
5
22
|
Full Changelog: [v0.4.0...v0.5.0](https://github.com/ppl-ai/perplexity-py/compare/v0.4.0...v0.5.0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: perplexityai
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.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
|
|
@@ -67,10 +67,16 @@ 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
|
-
|
|
71
|
-
|
|
70
|
+
completion = client.chat.completions.create(
|
|
71
|
+
messages=[
|
|
72
|
+
{
|
|
73
|
+
"role": "user",
|
|
74
|
+
"content": "Tell me about the latest developments in AI",
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
model="sonar",
|
|
72
78
|
)
|
|
73
|
-
print(
|
|
79
|
+
print(completion.id)
|
|
74
80
|
```
|
|
75
81
|
|
|
76
82
|
While you can provide an `api_key` keyword argument,
|
|
@@ -93,10 +99,16 @@ client = AsyncPerplexity(
|
|
|
93
99
|
|
|
94
100
|
|
|
95
101
|
async def main() -> None:
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
completion = await client.chat.completions.create(
|
|
103
|
+
messages=[
|
|
104
|
+
{
|
|
105
|
+
"role": "user",
|
|
106
|
+
"content": "Tell me about the latest developments in AI",
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
model="sonar",
|
|
98
110
|
)
|
|
99
|
-
print(
|
|
111
|
+
print(completion.id)
|
|
100
112
|
|
|
101
113
|
|
|
102
114
|
asyncio.run(main())
|
|
@@ -128,10 +140,16 @@ async def main() -> None:
|
|
|
128
140
|
api_key="My API Key",
|
|
129
141
|
http_client=DefaultAioHttpClient(),
|
|
130
142
|
) as client:
|
|
131
|
-
|
|
132
|
-
|
|
143
|
+
completion = await client.chat.completions.create(
|
|
144
|
+
messages=[
|
|
145
|
+
{
|
|
146
|
+
"role": "user",
|
|
147
|
+
"content": "Tell me about the latest developments in AI",
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
model="sonar",
|
|
133
151
|
)
|
|
134
|
-
print(
|
|
152
|
+
print(completion.id)
|
|
135
153
|
|
|
136
154
|
|
|
137
155
|
asyncio.run(main())
|
|
@@ -146,6 +164,28 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
|
|
|
146
164
|
|
|
147
165
|
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
|
|
148
166
|
|
|
167
|
+
## Nested params
|
|
168
|
+
|
|
169
|
+
Nested parameters are dictionaries, typed using `TypedDict`, for example:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from perplexity import Perplexity
|
|
173
|
+
|
|
174
|
+
client = Perplexity()
|
|
175
|
+
|
|
176
|
+
completion = client.chat.completions.create(
|
|
177
|
+
messages=[
|
|
178
|
+
{
|
|
179
|
+
"content": "string",
|
|
180
|
+
"role": "system",
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
model="sonar",
|
|
184
|
+
web_search_options={},
|
|
185
|
+
)
|
|
186
|
+
print(completion.web_search_options)
|
|
187
|
+
```
|
|
188
|
+
|
|
149
189
|
## Handling errors
|
|
150
190
|
|
|
151
191
|
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `perplexity.APIConnectionError` is raised.
|
|
@@ -162,8 +202,14 @@ from perplexity import Perplexity
|
|
|
162
202
|
client = Perplexity()
|
|
163
203
|
|
|
164
204
|
try:
|
|
165
|
-
client.
|
|
166
|
-
|
|
205
|
+
client.chat.completions.create(
|
|
206
|
+
messages=[
|
|
207
|
+
{
|
|
208
|
+
"role": "user",
|
|
209
|
+
"content": "What is the capital of France?",
|
|
210
|
+
}
|
|
211
|
+
],
|
|
212
|
+
model="sonar",
|
|
167
213
|
)
|
|
168
214
|
except perplexity.APIConnectionError as e:
|
|
169
215
|
print("The server could not be reached")
|
|
@@ -207,8 +253,14 @@ client = Perplexity(
|
|
|
207
253
|
)
|
|
208
254
|
|
|
209
255
|
# Or, configure per-request:
|
|
210
|
-
client.with_options(max_retries=5).
|
|
211
|
-
|
|
256
|
+
client.with_options(max_retries=5).chat.completions.create(
|
|
257
|
+
messages=[
|
|
258
|
+
{
|
|
259
|
+
"role": "user",
|
|
260
|
+
"content": "What is the capital of France?",
|
|
261
|
+
}
|
|
262
|
+
],
|
|
263
|
+
model="sonar",
|
|
212
264
|
)
|
|
213
265
|
```
|
|
214
266
|
|
|
@@ -232,8 +284,14 @@ client = Perplexity(
|
|
|
232
284
|
)
|
|
233
285
|
|
|
234
286
|
# Override per-request:
|
|
235
|
-
client.with_options(timeout=5.0).
|
|
236
|
-
|
|
287
|
+
client.with_options(timeout=5.0).chat.completions.create(
|
|
288
|
+
messages=[
|
|
289
|
+
{
|
|
290
|
+
"role": "user",
|
|
291
|
+
"content": "What is the capital of France?",
|
|
292
|
+
}
|
|
293
|
+
],
|
|
294
|
+
model="sonar",
|
|
237
295
|
)
|
|
238
296
|
```
|
|
239
297
|
|
|
@@ -275,13 +333,17 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
|
|
|
275
333
|
from perplexity import Perplexity
|
|
276
334
|
|
|
277
335
|
client = Perplexity()
|
|
278
|
-
response = client.
|
|
279
|
-
|
|
336
|
+
response = client.chat.completions.with_raw_response.create(
|
|
337
|
+
messages=[{
|
|
338
|
+
"role": "user",
|
|
339
|
+
"content": "What is the capital of France?",
|
|
340
|
+
}],
|
|
341
|
+
model="sonar",
|
|
280
342
|
)
|
|
281
343
|
print(response.headers.get('X-My-Header'))
|
|
282
344
|
|
|
283
|
-
|
|
284
|
-
print(
|
|
345
|
+
completion = response.parse() # get the object that `chat.completions.create()` would have returned
|
|
346
|
+
print(completion.id)
|
|
285
347
|
```
|
|
286
348
|
|
|
287
349
|
These methods return an [`APIResponse`](https://github.com/ppl-ai/perplexity-py/tree/main/src/perplexity/_response.py) object.
|
|
@@ -295,8 +357,14 @@ The above interface eagerly reads the full response body when you make the reque
|
|
|
295
357
|
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
358
|
|
|
297
359
|
```python
|
|
298
|
-
with client.
|
|
299
|
-
|
|
360
|
+
with client.chat.completions.with_streaming_response.create(
|
|
361
|
+
messages=[
|
|
362
|
+
{
|
|
363
|
+
"role": "user",
|
|
364
|
+
"content": "What is the capital of France?",
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
model="sonar",
|
|
300
368
|
) as response:
|
|
301
369
|
print(response.headers.get("X-My-Header"))
|
|
302
370
|
|
|
@@ -32,10 +32,16 @@ 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
|
-
|
|
36
|
-
|
|
35
|
+
completion = client.chat.completions.create(
|
|
36
|
+
messages=[
|
|
37
|
+
{
|
|
38
|
+
"role": "user",
|
|
39
|
+
"content": "Tell me about the latest developments in AI",
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
model="sonar",
|
|
37
43
|
)
|
|
38
|
-
print(
|
|
44
|
+
print(completion.id)
|
|
39
45
|
```
|
|
40
46
|
|
|
41
47
|
While you can provide an `api_key` keyword argument,
|
|
@@ -58,10 +64,16 @@ client = AsyncPerplexity(
|
|
|
58
64
|
|
|
59
65
|
|
|
60
66
|
async def main() -> None:
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
completion = await client.chat.completions.create(
|
|
68
|
+
messages=[
|
|
69
|
+
{
|
|
70
|
+
"role": "user",
|
|
71
|
+
"content": "Tell me about the latest developments in AI",
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
model="sonar",
|
|
63
75
|
)
|
|
64
|
-
print(
|
|
76
|
+
print(completion.id)
|
|
65
77
|
|
|
66
78
|
|
|
67
79
|
asyncio.run(main())
|
|
@@ -93,10 +105,16 @@ async def main() -> None:
|
|
|
93
105
|
api_key="My API Key",
|
|
94
106
|
http_client=DefaultAioHttpClient(),
|
|
95
107
|
) as client:
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
completion = await client.chat.completions.create(
|
|
109
|
+
messages=[
|
|
110
|
+
{
|
|
111
|
+
"role": "user",
|
|
112
|
+
"content": "Tell me about the latest developments in AI",
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
model="sonar",
|
|
98
116
|
)
|
|
99
|
-
print(
|
|
117
|
+
print(completion.id)
|
|
100
118
|
|
|
101
119
|
|
|
102
120
|
asyncio.run(main())
|
|
@@ -111,6 +129,28 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
|
|
|
111
129
|
|
|
112
130
|
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
|
|
113
131
|
|
|
132
|
+
## Nested params
|
|
133
|
+
|
|
134
|
+
Nested parameters are dictionaries, typed using `TypedDict`, for example:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from perplexity import Perplexity
|
|
138
|
+
|
|
139
|
+
client = Perplexity()
|
|
140
|
+
|
|
141
|
+
completion = client.chat.completions.create(
|
|
142
|
+
messages=[
|
|
143
|
+
{
|
|
144
|
+
"content": "string",
|
|
145
|
+
"role": "system",
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
model="sonar",
|
|
149
|
+
web_search_options={},
|
|
150
|
+
)
|
|
151
|
+
print(completion.web_search_options)
|
|
152
|
+
```
|
|
153
|
+
|
|
114
154
|
## Handling errors
|
|
115
155
|
|
|
116
156
|
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `perplexity.APIConnectionError` is raised.
|
|
@@ -127,8 +167,14 @@ from perplexity import Perplexity
|
|
|
127
167
|
client = Perplexity()
|
|
128
168
|
|
|
129
169
|
try:
|
|
130
|
-
client.
|
|
131
|
-
|
|
170
|
+
client.chat.completions.create(
|
|
171
|
+
messages=[
|
|
172
|
+
{
|
|
173
|
+
"role": "user",
|
|
174
|
+
"content": "What is the capital of France?",
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
model="sonar",
|
|
132
178
|
)
|
|
133
179
|
except perplexity.APIConnectionError as e:
|
|
134
180
|
print("The server could not be reached")
|
|
@@ -172,8 +218,14 @@ client = Perplexity(
|
|
|
172
218
|
)
|
|
173
219
|
|
|
174
220
|
# Or, configure per-request:
|
|
175
|
-
client.with_options(max_retries=5).
|
|
176
|
-
|
|
221
|
+
client.with_options(max_retries=5).chat.completions.create(
|
|
222
|
+
messages=[
|
|
223
|
+
{
|
|
224
|
+
"role": "user",
|
|
225
|
+
"content": "What is the capital of France?",
|
|
226
|
+
}
|
|
227
|
+
],
|
|
228
|
+
model="sonar",
|
|
177
229
|
)
|
|
178
230
|
```
|
|
179
231
|
|
|
@@ -197,8 +249,14 @@ client = Perplexity(
|
|
|
197
249
|
)
|
|
198
250
|
|
|
199
251
|
# Override per-request:
|
|
200
|
-
client.with_options(timeout=5.0).
|
|
201
|
-
|
|
252
|
+
client.with_options(timeout=5.0).chat.completions.create(
|
|
253
|
+
messages=[
|
|
254
|
+
{
|
|
255
|
+
"role": "user",
|
|
256
|
+
"content": "What is the capital of France?",
|
|
257
|
+
}
|
|
258
|
+
],
|
|
259
|
+
model="sonar",
|
|
202
260
|
)
|
|
203
261
|
```
|
|
204
262
|
|
|
@@ -240,13 +298,17 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
|
|
|
240
298
|
from perplexity import Perplexity
|
|
241
299
|
|
|
242
300
|
client = Perplexity()
|
|
243
|
-
response = client.
|
|
244
|
-
|
|
301
|
+
response = client.chat.completions.with_raw_response.create(
|
|
302
|
+
messages=[{
|
|
303
|
+
"role": "user",
|
|
304
|
+
"content": "What is the capital of France?",
|
|
305
|
+
}],
|
|
306
|
+
model="sonar",
|
|
245
307
|
)
|
|
246
308
|
print(response.headers.get('X-My-Header'))
|
|
247
309
|
|
|
248
|
-
|
|
249
|
-
print(
|
|
310
|
+
completion = response.parse() # get the object that `chat.completions.create()` would have returned
|
|
311
|
+
print(completion.id)
|
|
250
312
|
```
|
|
251
313
|
|
|
252
314
|
These methods return an [`APIResponse`](https://github.com/ppl-ai/perplexity-py/tree/main/src/perplexity/_response.py) object.
|
|
@@ -260,8 +322,14 @@ The above interface eagerly reads the full response body when you make the reque
|
|
|
260
322
|
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
323
|
|
|
262
324
|
```python
|
|
263
|
-
with client.
|
|
264
|
-
|
|
325
|
+
with client.chat.completions.with_streaming_response.create(
|
|
326
|
+
messages=[
|
|
327
|
+
{
|
|
328
|
+
"role": "user",
|
|
329
|
+
"content": "What is the capital of France?",
|
|
330
|
+
}
|
|
331
|
+
],
|
|
332
|
+
model="sonar",
|
|
265
333
|
) as response:
|
|
266
334
|
print(response.headers.get("X-My-Header"))
|
|
267
335
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Shared Types
|
|
2
|
+
|
|
3
|
+
```python
|
|
4
|
+
from perplexity.types import ChatChoice, ChatMessage, SearchResult, UsageInfo
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
# Chat
|
|
8
|
+
|
|
9
|
+
## Completions
|
|
10
|
+
|
|
11
|
+
Types:
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from perplexity.types.chat import CompletionCreateResponse
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Methods:
|
|
18
|
+
|
|
19
|
+
- <code title="post /chat/completions">client.chat.completions.<a href="./src/perplexity/resources/chat/completions.py">create</a>(\*\*<a href="src/perplexity/types/chat/completion_create_params.py">params</a>) -> <a href="./src/perplexity/types/chat/completion_create_response.py">CompletionCreateResponse</a></code>
|
|
20
|
+
|
|
21
|
+
# Async
|
|
22
|
+
|
|
23
|
+
## Chat
|
|
24
|
+
|
|
25
|
+
### Completions
|
|
26
|
+
|
|
27
|
+
Types:
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from perplexity.types.async_.chat import (
|
|
31
|
+
CompletionCreateResponse,
|
|
32
|
+
CompletionListResponse,
|
|
33
|
+
CompletionGetResponse,
|
|
34
|
+
)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Methods:
|
|
38
|
+
|
|
39
|
+
- <code title="post /async/chat/completions">client.async*.chat.completions.<a href="./src/perplexity/resources/async*/chat/completions.py">create</a>(\*\*<a href="src/perplexity/types/async_/chat/completion_create_params.py">params</a>) -> <a href="./src/perplexity/types/async_/chat/completion_create_response.py">CompletionCreateResponse</a></code>
|
|
40
|
+
- <code title="get /async/chat/completions">client.async*.chat.completions.<a href="./src/perplexity/resources/async*/chat/completions.py">list</a>(\*\*<a href="src/perplexity/types/async_/chat/completion_list_params.py">params</a>) -> <a href="./src/perplexity/types/async_/chat/completion_list_response.py">CompletionListResponse</a></code>
|
|
41
|
+
- <code title="get /async/chat/completions/{request_id}">client.async*.chat.completions.<a href="./src/perplexity/resources/async*/chat/completions.py">get</a>(request*id) -> <a href="./src/perplexity/types/async*/chat/completion_get_response.py">CompletionGetResponse</a></code>
|
|
42
|
+
|
|
43
|
+
# Search
|
|
44
|
+
|
|
45
|
+
Types:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from perplexity.types import SearchCreateResponse
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Methods:
|
|
52
|
+
|
|
53
|
+
- <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>
|
|
54
|
+
|
|
55
|
+
# Content
|
|
56
|
+
|
|
57
|
+
Types:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from perplexity.types import ContentCreateResponse
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Methods:
|
|
64
|
+
|
|
65
|
+
- <code title="post /content">client.content.<a href="./src/perplexity/resources/content.py">create</a>(\*\*<a href="src/perplexity/types/content_create_params.py">params</a>) -> <a href="./src/perplexity/types/content_create_response.py">ContentCreateResponse</a></code>
|
|
@@ -21,7 +21,7 @@ from ._types import (
|
|
|
21
21
|
)
|
|
22
22
|
from ._utils import is_given, get_async_library
|
|
23
23
|
from ._version import __version__
|
|
24
|
-
from .resources import search
|
|
24
|
+
from .resources import search, content
|
|
25
25
|
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
|
|
26
26
|
from ._exceptions import APIStatusError, PerplexityError
|
|
27
27
|
from ._base_client import (
|
|
@@ -29,6 +29,8 @@ from ._base_client import (
|
|
|
29
29
|
SyncAPIClient,
|
|
30
30
|
AsyncAPIClient,
|
|
31
31
|
)
|
|
32
|
+
from .resources.chat import chat
|
|
33
|
+
from .resources.async_ import async_
|
|
32
34
|
|
|
33
35
|
__all__ = [
|
|
34
36
|
"Timeout",
|
|
@@ -43,7 +45,10 @@ __all__ = [
|
|
|
43
45
|
|
|
44
46
|
|
|
45
47
|
class Perplexity(SyncAPIClient):
|
|
48
|
+
chat: chat.ChatResource
|
|
49
|
+
async_: async_.AsyncResource
|
|
46
50
|
search: search.SearchResource
|
|
51
|
+
content: content.ContentResource
|
|
47
52
|
with_raw_response: PerplexityWithRawResponse
|
|
48
53
|
with_streaming_response: PerplexityWithStreamedResponse
|
|
49
54
|
|
|
@@ -101,7 +106,10 @@ class Perplexity(SyncAPIClient):
|
|
|
101
106
|
_strict_response_validation=_strict_response_validation,
|
|
102
107
|
)
|
|
103
108
|
|
|
109
|
+
self.chat = chat.ChatResource(self)
|
|
110
|
+
self.async_ = async_.AsyncResource(self)
|
|
104
111
|
self.search = search.SearchResource(self)
|
|
112
|
+
self.content = content.ContentResource(self)
|
|
105
113
|
self.with_raw_response = PerplexityWithRawResponse(self)
|
|
106
114
|
self.with_streaming_response = PerplexityWithStreamedResponse(self)
|
|
107
115
|
|
|
@@ -211,7 +219,10 @@ class Perplexity(SyncAPIClient):
|
|
|
211
219
|
|
|
212
220
|
|
|
213
221
|
class AsyncPerplexity(AsyncAPIClient):
|
|
222
|
+
chat: chat.AsyncChatResource
|
|
223
|
+
async_: async_.AsyncAsyncResource
|
|
214
224
|
search: search.AsyncSearchResource
|
|
225
|
+
content: content.AsyncContentResource
|
|
215
226
|
with_raw_response: AsyncPerplexityWithRawResponse
|
|
216
227
|
with_streaming_response: AsyncPerplexityWithStreamedResponse
|
|
217
228
|
|
|
@@ -269,7 +280,10 @@ class AsyncPerplexity(AsyncAPIClient):
|
|
|
269
280
|
_strict_response_validation=_strict_response_validation,
|
|
270
281
|
)
|
|
271
282
|
|
|
283
|
+
self.chat = chat.AsyncChatResource(self)
|
|
284
|
+
self.async_ = async_.AsyncAsyncResource(self)
|
|
272
285
|
self.search = search.AsyncSearchResource(self)
|
|
286
|
+
self.content = content.AsyncContentResource(self)
|
|
273
287
|
self.with_raw_response = AsyncPerplexityWithRawResponse(self)
|
|
274
288
|
self.with_streaming_response = AsyncPerplexityWithStreamedResponse(self)
|
|
275
289
|
|
|
@@ -380,22 +394,34 @@ class AsyncPerplexity(AsyncAPIClient):
|
|
|
380
394
|
|
|
381
395
|
class PerplexityWithRawResponse:
|
|
382
396
|
def __init__(self, client: Perplexity) -> None:
|
|
397
|
+
self.chat = chat.ChatResourceWithRawResponse(client.chat)
|
|
398
|
+
self.async_ = async_.AsyncResourceWithRawResponse(client.async_)
|
|
383
399
|
self.search = search.SearchResourceWithRawResponse(client.search)
|
|
400
|
+
self.content = content.ContentResourceWithRawResponse(client.content)
|
|
384
401
|
|
|
385
402
|
|
|
386
403
|
class AsyncPerplexityWithRawResponse:
|
|
387
404
|
def __init__(self, client: AsyncPerplexity) -> None:
|
|
405
|
+
self.chat = chat.AsyncChatResourceWithRawResponse(client.chat)
|
|
406
|
+
self.async_ = async_.AsyncAsyncResourceWithRawResponse(client.async_)
|
|
388
407
|
self.search = search.AsyncSearchResourceWithRawResponse(client.search)
|
|
408
|
+
self.content = content.AsyncContentResourceWithRawResponse(client.content)
|
|
389
409
|
|
|
390
410
|
|
|
391
411
|
class PerplexityWithStreamedResponse:
|
|
392
412
|
def __init__(self, client: Perplexity) -> None:
|
|
413
|
+
self.chat = chat.ChatResourceWithStreamingResponse(client.chat)
|
|
414
|
+
self.async_ = async_.AsyncResourceWithStreamingResponse(client.async_)
|
|
393
415
|
self.search = search.SearchResourceWithStreamingResponse(client.search)
|
|
416
|
+
self.content = content.ContentResourceWithStreamingResponse(client.content)
|
|
394
417
|
|
|
395
418
|
|
|
396
419
|
class AsyncPerplexityWithStreamedResponse:
|
|
397
420
|
def __init__(self, client: AsyncPerplexity) -> None:
|
|
421
|
+
self.chat = chat.AsyncChatResourceWithStreamingResponse(client.chat)
|
|
422
|
+
self.async_ = async_.AsyncAsyncResourceWithStreamingResponse(client.async_)
|
|
398
423
|
self.search = search.AsyncSearchResourceWithStreamingResponse(client.search)
|
|
424
|
+
self.content = content.AsyncContentResourceWithStreamingResponse(client.content)
|
|
399
425
|
|
|
400
426
|
|
|
401
427
|
Client = Perplexity
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from .chat import (
|
|
4
|
+
ChatResource,
|
|
5
|
+
AsyncChatResource,
|
|
6
|
+
ChatResourceWithRawResponse,
|
|
7
|
+
AsyncChatResourceWithRawResponse,
|
|
8
|
+
ChatResourceWithStreamingResponse,
|
|
9
|
+
AsyncChatResourceWithStreamingResponse,
|
|
10
|
+
)
|
|
11
|
+
from .async_ import (
|
|
12
|
+
AsyncResource,
|
|
13
|
+
AsyncAsyncResource,
|
|
14
|
+
AsyncResourceWithRawResponse,
|
|
15
|
+
AsyncAsyncResourceWithRawResponse,
|
|
16
|
+
AsyncResourceWithStreamingResponse,
|
|
17
|
+
AsyncAsyncResourceWithStreamingResponse,
|
|
18
|
+
)
|
|
19
|
+
from .search import (
|
|
20
|
+
SearchResource,
|
|
21
|
+
AsyncSearchResource,
|
|
22
|
+
SearchResourceWithRawResponse,
|
|
23
|
+
AsyncSearchResourceWithRawResponse,
|
|
24
|
+
SearchResourceWithStreamingResponse,
|
|
25
|
+
AsyncSearchResourceWithStreamingResponse,
|
|
26
|
+
)
|
|
27
|
+
from .content import (
|
|
28
|
+
ContentResource,
|
|
29
|
+
AsyncContentResource,
|
|
30
|
+
ContentResourceWithRawResponse,
|
|
31
|
+
AsyncContentResourceWithRawResponse,
|
|
32
|
+
ContentResourceWithStreamingResponse,
|
|
33
|
+
AsyncContentResourceWithStreamingResponse,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"ChatResource",
|
|
38
|
+
"AsyncChatResource",
|
|
39
|
+
"ChatResourceWithRawResponse",
|
|
40
|
+
"AsyncChatResourceWithRawResponse",
|
|
41
|
+
"ChatResourceWithStreamingResponse",
|
|
42
|
+
"AsyncChatResourceWithStreamingResponse",
|
|
43
|
+
"AsyncResource",
|
|
44
|
+
"AsyncAsyncResource",
|
|
45
|
+
"AsyncResourceWithRawResponse",
|
|
46
|
+
"AsyncAsyncResourceWithRawResponse",
|
|
47
|
+
"AsyncResourceWithStreamingResponse",
|
|
48
|
+
"AsyncAsyncResourceWithStreamingResponse",
|
|
49
|
+
"SearchResource",
|
|
50
|
+
"AsyncSearchResource",
|
|
51
|
+
"SearchResourceWithRawResponse",
|
|
52
|
+
"AsyncSearchResourceWithRawResponse",
|
|
53
|
+
"SearchResourceWithStreamingResponse",
|
|
54
|
+
"AsyncSearchResourceWithStreamingResponse",
|
|
55
|
+
"ContentResource",
|
|
56
|
+
"AsyncContentResource",
|
|
57
|
+
"ContentResourceWithRawResponse",
|
|
58
|
+
"AsyncContentResourceWithRawResponse",
|
|
59
|
+
"ContentResourceWithStreamingResponse",
|
|
60
|
+
"AsyncContentResourceWithStreamingResponse",
|
|
61
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from .chat import (
|
|
4
|
+
ChatResource,
|
|
5
|
+
AsyncChatResource,
|
|
6
|
+
ChatResourceWithRawResponse,
|
|
7
|
+
AsyncChatResourceWithRawResponse,
|
|
8
|
+
ChatResourceWithStreamingResponse,
|
|
9
|
+
AsyncChatResourceWithStreamingResponse,
|
|
10
|
+
)
|
|
11
|
+
from .async_ import (
|
|
12
|
+
AsyncResource,
|
|
13
|
+
AsyncAsyncResource,
|
|
14
|
+
AsyncResourceWithRawResponse,
|
|
15
|
+
AsyncAsyncResourceWithRawResponse,
|
|
16
|
+
AsyncResourceWithStreamingResponse,
|
|
17
|
+
AsyncAsyncResourceWithStreamingResponse,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"ChatResource",
|
|
22
|
+
"AsyncChatResource",
|
|
23
|
+
"ChatResourceWithRawResponse",
|
|
24
|
+
"AsyncChatResourceWithRawResponse",
|
|
25
|
+
"ChatResourceWithStreamingResponse",
|
|
26
|
+
"AsyncChatResourceWithStreamingResponse",
|
|
27
|
+
"AsyncResource",
|
|
28
|
+
"AsyncAsyncResource",
|
|
29
|
+
"AsyncResourceWithRawResponse",
|
|
30
|
+
"AsyncAsyncResourceWithRawResponse",
|
|
31
|
+
"AsyncResourceWithStreamingResponse",
|
|
32
|
+
"AsyncAsyncResourceWithStreamingResponse",
|
|
33
|
+
]
|