perplexityai 0.6.0__py3-none-any.whl → 0.7.0__py3-none-any.whl
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.
- perplexity/_client.py +18 -0
- perplexity/_version.py +1 -1
- perplexity/resources/__init__.py +28 -0
- perplexity/resources/async_/__init__.py +33 -0
- perplexity/resources/async_/async_.py +102 -0
- perplexity/resources/async_/chat/__init__.py +33 -0
- perplexity/resources/async_/chat/chat.py +102 -0
- perplexity/resources/async_/chat/completions.py +347 -0
- perplexity/resources/chat/__init__.py +33 -0
- perplexity/resources/chat/chat.py +102 -0
- perplexity/resources/chat/completions.py +295 -0
- perplexity/resources/content.py +6 -2
- perplexity/resources/search.py +60 -2
- perplexity/types/__init__.py +6 -0
- perplexity/types/async_/__init__.py +3 -0
- perplexity/types/async_/chat/__init__.py +9 -0
- perplexity/types/async_/chat/completion_create_params.py +94 -0
- perplexity/types/async_/chat/completion_create_response.py +54 -0
- perplexity/types/async_/chat/completion_get_response.py +54 -0
- perplexity/types/async_/chat/completion_list_params.py +15 -0
- perplexity/types/async_/chat/completion_list_response.py +31 -0
- perplexity/types/chat/__init__.py +6 -0
- perplexity/types/chat/completion_create_params.py +90 -0
- perplexity/types/chat/completion_create_response.py +30 -0
- perplexity/types/content_create_params.py +1 -0
- perplexity/types/content_create_response.py +6 -0
- perplexity/types/search_create_params.py +24 -0
- perplexity/types/search_create_response.py +7 -0
- perplexity/types/shared/__init__.py +6 -0
- perplexity/types/shared/chat_choice.py +17 -0
- perplexity/types/shared/chat_message.py +31 -0
- perplexity/types/shared/search_result.py +15 -0
- perplexity/types/shared/usage_info.py +23 -0
- perplexity/types/shared_params/__init__.py +3 -0
- perplexity/types/shared_params/chat_message.py +31 -0
- {perplexityai-0.6.0.dist-info → perplexityai-0.7.0.dist-info}/METADATA +90 -22
- perplexityai-0.7.0.dist-info/RECORD +65 -0
- perplexityai-0.6.0.dist-info/RECORD +0 -40
- {perplexityai-0.6.0.dist-info → perplexityai-0.7.0.dist-info}/WHEEL +0 -0
- {perplexityai-0.6.0.dist-info → perplexityai-0.7.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -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 .completion_create_params import CompletionCreateParams as CompletionCreateParams
|
|
6
|
+
from .completion_create_response import CompletionCreateResponse as CompletionCreateResponse
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Iterable, Optional
|
|
6
|
+
from typing_extensions import Literal, Required, TypedDict
|
|
7
|
+
|
|
8
|
+
from ..._types import SequenceNotStr
|
|
9
|
+
from ..shared_params.chat_message import ChatMessage
|
|
10
|
+
|
|
11
|
+
__all__ = ["CompletionCreateParams", "WebSearchOptions", "WebSearchOptionsUserLocation"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CompletionCreateParams(TypedDict, total=False):
|
|
15
|
+
messages: Required[Iterable[ChatMessage]]
|
|
16
|
+
"""A list of messages comprising the conversation so far"""
|
|
17
|
+
|
|
18
|
+
model: Required[Literal["sonar", "sonar-pro", "sonar-deep-research", "sonar-reasoning", "sonar-reasoning-pro"]]
|
|
19
|
+
"""The name of the model that will complete your prompt"""
|
|
20
|
+
|
|
21
|
+
disable_search: bool
|
|
22
|
+
"""Disables web search completely - model uses only training data"""
|
|
23
|
+
|
|
24
|
+
enable_search_classifier: bool
|
|
25
|
+
"""Enables classifier that decides if web search is needed"""
|
|
26
|
+
|
|
27
|
+
last_updated_after_filter: Optional[str]
|
|
28
|
+
"""Only include content last updated after this date (YYYY-MM-DD)"""
|
|
29
|
+
|
|
30
|
+
last_updated_before_filter: Optional[str]
|
|
31
|
+
"""Only include content last updated before this date (YYYY-MM-DD)"""
|
|
32
|
+
|
|
33
|
+
reasoning_effort: Optional[Literal["low", "medium", "high"]]
|
|
34
|
+
"""Controls computational effort for sonar-deep-research model.
|
|
35
|
+
|
|
36
|
+
Higher effort = more thorough but more tokens
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
return_images: bool
|
|
40
|
+
"""Whether to include images in search results"""
|
|
41
|
+
|
|
42
|
+
return_related_questions: bool
|
|
43
|
+
"""Whether to return related questions"""
|
|
44
|
+
|
|
45
|
+
search_after_date_filter: Optional[str]
|
|
46
|
+
"""Only include content published after this date (YYYY-MM-DD)"""
|
|
47
|
+
|
|
48
|
+
search_before_date_filter: Optional[str]
|
|
49
|
+
"""Only include content published before this date (YYYY-MM-DD)"""
|
|
50
|
+
|
|
51
|
+
search_domain_filter: Optional[SequenceNotStr[str]]
|
|
52
|
+
"""List of domains to limit search results to. Use '-' prefix to exclude domains"""
|
|
53
|
+
|
|
54
|
+
search_mode: Optional[Literal["web", "academic", "sec"]]
|
|
55
|
+
"""
|
|
56
|
+
Type of search: 'web' for general, 'academic' for scholarly, 'sec' for SEC
|
|
57
|
+
filings
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
search_recency_filter: Optional[Literal["hour", "day", "week", "month", "year"]]
|
|
61
|
+
"""Filter results by how recently they were published"""
|
|
62
|
+
|
|
63
|
+
web_search_options: WebSearchOptions
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class WebSearchOptionsUserLocation(TypedDict, total=False):
|
|
67
|
+
city: Optional[str]
|
|
68
|
+
|
|
69
|
+
country: Optional[str]
|
|
70
|
+
"""Two-letter ISO country code"""
|
|
71
|
+
|
|
72
|
+
latitude: Optional[float]
|
|
73
|
+
|
|
74
|
+
longitude: Optional[float]
|
|
75
|
+
|
|
76
|
+
region: Optional[str]
|
|
77
|
+
"""State/province name"""
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class WebSearchOptions(TypedDict, total=False):
|
|
81
|
+
image_search_relevance_enhanced: bool
|
|
82
|
+
"""Improves relevance of image search results"""
|
|
83
|
+
|
|
84
|
+
search_context_size: Literal["low", "medium", "high"]
|
|
85
|
+
"""
|
|
86
|
+
Amount of search context retrieved: low (cost-saving), medium (balanced), high
|
|
87
|
+
(comprehensive)
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
user_location: WebSearchOptionsUserLocation
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
from ..._models import BaseModel
|
|
6
|
+
from ..shared.usage_info import UsageInfo
|
|
7
|
+
from ..shared.chat_choice import ChatChoice
|
|
8
|
+
from ..shared.search_result import SearchResult
|
|
9
|
+
|
|
10
|
+
__all__ = ["CompletionCreateResponse"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CompletionCreateResponse(BaseModel):
|
|
14
|
+
id: str
|
|
15
|
+
"""Unique identifier for the chat completion"""
|
|
16
|
+
|
|
17
|
+
choices: List[ChatChoice]
|
|
18
|
+
|
|
19
|
+
created: int
|
|
20
|
+
"""Unix timestamp of creation"""
|
|
21
|
+
|
|
22
|
+
model: str
|
|
23
|
+
"""The model used"""
|
|
24
|
+
|
|
25
|
+
object: str
|
|
26
|
+
|
|
27
|
+
usage: UsageInfo
|
|
28
|
+
|
|
29
|
+
search_results: Optional[List[SearchResult]] = None
|
|
30
|
+
"""Search results used in generating the response"""
|
|
@@ -9,15 +9,21 @@ __all__ = ["ContentCreateResponse", "Result"]
|
|
|
9
9
|
|
|
10
10
|
class Result(BaseModel):
|
|
11
11
|
content: str
|
|
12
|
+
"""The full text content of the web page or document"""
|
|
12
13
|
|
|
13
14
|
title: str
|
|
15
|
+
"""The title of the web page or document"""
|
|
14
16
|
|
|
15
17
|
url: str
|
|
18
|
+
"""The URL of the web page or document"""
|
|
16
19
|
|
|
17
20
|
date: Optional[str] = None
|
|
21
|
+
"""The publication date of the content (if available)"""
|
|
18
22
|
|
|
19
23
|
|
|
20
24
|
class ContentCreateResponse(BaseModel):
|
|
21
25
|
id: str
|
|
26
|
+
"""Unique identifier for this content retrieval request"""
|
|
22
27
|
|
|
23
28
|
results: List[Result]
|
|
29
|
+
"""Array of content objects retrieved from the requested URLs"""
|
|
@@ -12,27 +12,51 @@ __all__ = ["SearchCreateParams"]
|
|
|
12
12
|
|
|
13
13
|
class SearchCreateParams(TypedDict, total=False):
|
|
14
14
|
query: Required[Union[str, SequenceNotStr[str]]]
|
|
15
|
+
"""Search query string or array of query strings to search for"""
|
|
15
16
|
|
|
16
17
|
country: Optional[str]
|
|
18
|
+
"""Country code to bias search results towards (e.g., 'US', 'GB', 'CA')"""
|
|
17
19
|
|
|
18
20
|
last_updated_after_filter: Optional[str]
|
|
21
|
+
"""Only include results last updated after this date (ISO 8601 format: YYYY-MM-DD)"""
|
|
19
22
|
|
|
20
23
|
last_updated_before_filter: Optional[str]
|
|
24
|
+
"""
|
|
25
|
+
Only include results last updated before this date (ISO 8601 format: YYYY-MM-DD)
|
|
26
|
+
"""
|
|
21
27
|
|
|
22
28
|
max_results: int
|
|
29
|
+
"""Maximum number of search results to return"""
|
|
23
30
|
|
|
24
31
|
max_tokens: int
|
|
32
|
+
"""Maximum number of tokens to return across all results"""
|
|
25
33
|
|
|
26
34
|
max_tokens_per_page: int
|
|
35
|
+
"""Maximum number of tokens to return per individual search result"""
|
|
27
36
|
|
|
28
37
|
safe_search: Optional[bool]
|
|
38
|
+
"""Enable safe search filtering to exclude adult content"""
|
|
29
39
|
|
|
30
40
|
search_after_date_filter: Optional[str]
|
|
41
|
+
"""Only include results published after this date (ISO 8601 format: YYYY-MM-DD)"""
|
|
31
42
|
|
|
32
43
|
search_before_date_filter: Optional[str]
|
|
44
|
+
"""Only include results published before this date (ISO 8601 format: YYYY-MM-DD)"""
|
|
33
45
|
|
|
34
46
|
search_domain_filter: Optional[SequenceNotStr[str]]
|
|
47
|
+
"""
|
|
48
|
+
List of domains to restrict search results to (e.g., ['example.com',
|
|
49
|
+
'another.com'])
|
|
50
|
+
"""
|
|
35
51
|
|
|
36
52
|
search_mode: Optional[Literal["web", "academic", "sec"]]
|
|
53
|
+
"""
|
|
54
|
+
Type of search to perform: 'web' for general web search, 'academic' for
|
|
55
|
+
scholarly articles, 'sec' for SEC filings
|
|
56
|
+
"""
|
|
37
57
|
|
|
38
58
|
search_recency_filter: Optional[Literal["hour", "day", "week", "month", "year"]]
|
|
59
|
+
"""
|
|
60
|
+
Filter results by how recently they were published (hour, day, week, month, or
|
|
61
|
+
year)
|
|
62
|
+
"""
|
|
@@ -9,17 +9,24 @@ __all__ = ["SearchCreateResponse", "Result"]
|
|
|
9
9
|
|
|
10
10
|
class Result(BaseModel):
|
|
11
11
|
snippet: str
|
|
12
|
+
"""A brief excerpt or summary of the page content"""
|
|
12
13
|
|
|
13
14
|
title: str
|
|
15
|
+
"""The title of the search result page"""
|
|
14
16
|
|
|
15
17
|
url: str
|
|
18
|
+
"""The URL of the search result page"""
|
|
16
19
|
|
|
17
20
|
date: Optional[str] = None
|
|
21
|
+
"""The publication date of the content (if available)"""
|
|
18
22
|
|
|
19
23
|
last_updated: Optional[str] = None
|
|
24
|
+
"""When the content was last updated (if available)"""
|
|
20
25
|
|
|
21
26
|
|
|
22
27
|
class SearchCreateResponse(BaseModel):
|
|
23
28
|
id: str
|
|
29
|
+
"""Unique identifier for this search request"""
|
|
24
30
|
|
|
25
31
|
results: List[Result]
|
|
32
|
+
"""Array of search result pages matching the query"""
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from .usage_info import UsageInfo as UsageInfo
|
|
4
|
+
from .chat_choice import ChatChoice as ChatChoice
|
|
5
|
+
from .chat_message import ChatMessage as ChatMessage
|
|
6
|
+
from .search_result import SearchResult as SearchResult
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from typing_extensions import Literal
|
|
5
|
+
|
|
6
|
+
from ..._models import BaseModel
|
|
7
|
+
from .chat_message import ChatMessage
|
|
8
|
+
|
|
9
|
+
__all__ = ["ChatChoice"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ChatChoice(BaseModel):
|
|
13
|
+
index: int
|
|
14
|
+
|
|
15
|
+
message: ChatMessage
|
|
16
|
+
|
|
17
|
+
finish_reason: Optional[Literal["stop", "length"]] = None
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from typing import List, Union, Optional
|
|
4
|
+
from typing_extensions import Literal
|
|
5
|
+
|
|
6
|
+
from ..._models import BaseModel
|
|
7
|
+
|
|
8
|
+
__all__ = ["ChatMessage", "ContentMultipartContent", "ContentMultipartContentImageURL"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ContentMultipartContentImageURL(BaseModel):
|
|
12
|
+
url: str
|
|
13
|
+
"""URL of the image (base64 or HTTPS)"""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ContentMultipartContent(BaseModel):
|
|
17
|
+
type: Literal["text", "image_url"]
|
|
18
|
+
"""The type of content"""
|
|
19
|
+
|
|
20
|
+
image_url: Optional[ContentMultipartContentImageURL] = None
|
|
21
|
+
|
|
22
|
+
text: Optional[str] = None
|
|
23
|
+
"""Text content"""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ChatMessage(BaseModel):
|
|
27
|
+
content: Union[str, List[ContentMultipartContent]]
|
|
28
|
+
"""The content of the message"""
|
|
29
|
+
|
|
30
|
+
role: Literal["system", "user", "assistant"]
|
|
31
|
+
"""The role of the message author"""
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from ..._models import BaseModel
|
|
6
|
+
|
|
7
|
+
__all__ = ["SearchResult"]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SearchResult(BaseModel):
|
|
11
|
+
title: str
|
|
12
|
+
|
|
13
|
+
url: str
|
|
14
|
+
|
|
15
|
+
date: Optional[str] = None
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from ..._models import BaseModel
|
|
6
|
+
|
|
7
|
+
__all__ = ["UsageInfo"]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class UsageInfo(BaseModel):
|
|
11
|
+
completion_tokens: int
|
|
12
|
+
|
|
13
|
+
prompt_tokens: int
|
|
14
|
+
|
|
15
|
+
total_tokens: int
|
|
16
|
+
|
|
17
|
+
citation_tokens: Optional[int] = None
|
|
18
|
+
|
|
19
|
+
num_search_queries: Optional[int] = None
|
|
20
|
+
|
|
21
|
+
reasoning_tokens: Optional[int] = None
|
|
22
|
+
|
|
23
|
+
search_context_size: Optional[str] = None
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Union, Iterable, Optional
|
|
6
|
+
from typing_extensions import Literal, Required, TypedDict
|
|
7
|
+
|
|
8
|
+
__all__ = ["ChatMessage", "ContentMultipartContent", "ContentMultipartContentImageURL"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ContentMultipartContentImageURL(TypedDict, total=False):
|
|
12
|
+
url: Required[str]
|
|
13
|
+
"""URL of the image (base64 or HTTPS)"""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ContentMultipartContent(TypedDict, total=False):
|
|
17
|
+
type: Required[Literal["text", "image_url"]]
|
|
18
|
+
"""The type of content"""
|
|
19
|
+
|
|
20
|
+
image_url: Optional[ContentMultipartContentImageURL]
|
|
21
|
+
|
|
22
|
+
text: Optional[str]
|
|
23
|
+
"""Text content"""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ChatMessage(TypedDict, total=False):
|
|
27
|
+
content: Required[Union[str, Iterable[ContentMultipartContent]]]
|
|
28
|
+
"""The content of the message"""
|
|
29
|
+
|
|
30
|
+
role: Required[Literal["system", "user", "assistant"]]
|
|
31
|
+
"""The role of the message author"""
|
|
@@ -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
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
perplexity/__init__.py,sha256=5epbvK3UiJEgvsBW9Ds6RFB6zObkUxYkA9fIQlgUaXA,2655
|
|
2
|
+
perplexity/_base_client.py,sha256=DSeMteXutziRGJA9HqJaoLpG7ktzpU2GPcaIgQT1oZQ,67051
|
|
3
|
+
perplexity/_client.py,sha256=Uy5nrz9S9FTCy3-s1EGLOr-b8LJ2M2GTuQAB1GclZHE,16611
|
|
4
|
+
perplexity/_compat.py,sha256=DQBVORjFb33zch24jzkhM14msvnzY7mmSmgDLaVFUM8,6562
|
|
5
|
+
perplexity/_constants.py,sha256=S14PFzyN9-I31wiV7SmIlL5Ga0MLHxdvegInGdXH7tM,462
|
|
6
|
+
perplexity/_exceptions.py,sha256=v-hOXWSDTEtXcn_By7pPml3HjEmG5HXpbE-RK_A6_0Q,3228
|
|
7
|
+
perplexity/_files.py,sha256=KnEzGi_O756MvKyJ4fOCW_u3JhOeWPQ4RsmDvqihDQU,3545
|
|
8
|
+
perplexity/_models.py,sha256=c29x_mRccdxlGwdUPfSR5eJxGXe74Ea5Dje5igZTrKQ,30024
|
|
9
|
+
perplexity/_qs.py,sha256=AOkSz4rHtK4YI3ZU_kzea-zpwBUgEY8WniGmTPyEimc,4846
|
|
10
|
+
perplexity/_resource.py,sha256=Pgc8KNBsIc1ltJn94uhDcDl0-3n5RLbe3iC2AiiNRnE,1124
|
|
11
|
+
perplexity/_response.py,sha256=bpqzmVGq6jnivoMkUgt3OI0Rh6xHd6BMcp5PHgSFPb0,28842
|
|
12
|
+
perplexity/_streaming.py,sha256=SQ61v42gFmNiO57uMFUZMAuDlGE0n_EulkZcPgJXt4U,10116
|
|
13
|
+
perplexity/_types.py,sha256=XZYv2_G7oQGhQkjI28-TFIMP_yZZV590TRuKAoLJ3wM,7300
|
|
14
|
+
perplexity/_version.py,sha256=uCysX84wOk6jVxbeJH9qOeK6dKiSul86f3NkeqwTEBk,162
|
|
15
|
+
perplexity/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
perplexity/_utils/__init__.py,sha256=7fch0GT9zpNnErbciSpUNa-SjTxxjY6kxHxKMOM4AGs,2305
|
|
17
|
+
perplexity/_utils/_compat.py,sha256=D8gtAvjJQrDWt9upS0XaG9Rr5l1QhiAx_I_1utT_tt0,1195
|
|
18
|
+
perplexity/_utils/_datetime_parse.py,sha256=bABTs0Bc6rabdFvnIwXjEhWL15TcRgWZ_6XGTqN8xUk,4204
|
|
19
|
+
perplexity/_utils/_logs.py,sha256=CsE-zYnAQTOCueNGVjEn6bozMyE86gdjMhJDNWDLpaQ,786
|
|
20
|
+
perplexity/_utils/_proxy.py,sha256=aglnj2yBTDyGX9Akk2crZHrl10oqRmceUy2Zp008XEs,1975
|
|
21
|
+
perplexity/_utils/_reflection.py,sha256=ZmGkIgT_PuwedyNBrrKGbxoWtkpytJNU1uU4QHnmEMU,1364
|
|
22
|
+
perplexity/_utils/_resources_proxy.py,sha256=iMCHPeYmXwSunawEq3fcKGszOF3kL9w1ob-48Xnl04I,609
|
|
23
|
+
perplexity/_utils/_streams.py,sha256=SMC90diFFecpEg_zgDRVbdR3hSEIgVVij4taD-noMLM,289
|
|
24
|
+
perplexity/_utils/_sync.py,sha256=TpGLrrhRNWTJtODNE6Fup3_k7zrWm1j2RlirzBwre-0,2862
|
|
25
|
+
perplexity/_utils/_transform.py,sha256=i_U4R82RtQJtKKCriwFqmfcWjtwmmsiiF1AEXKQ_OPo,15957
|
|
26
|
+
perplexity/_utils/_typing.py,sha256=N_5PPuFNsaygbtA_npZd98SVN1LQQvFTKL6bkWPBZGU,4786
|
|
27
|
+
perplexity/_utils/_utils.py,sha256=D2QE7mVPNEJzaB50u8rvDQAUDS5jx7JoeFD7zdj-TeI,12231
|
|
28
|
+
perplexity/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
|
|
29
|
+
perplexity/resources/__init__.py,sha256=gQcgmiNY3uzaN5eAh9eclKJZRSaklhYcCF4ZTnFqemc,1877
|
|
30
|
+
perplexity/resources/content.py,sha256=6nv6_mtcvEnREDHbtia8EGghlttquY77fzw-akZB28U,6073
|
|
31
|
+
perplexity/resources/search.py,sha256=V67w1ql-6qsHjxj5WZ6CBHb0-NvMDi7U8Wg_flqfk74,12140
|
|
32
|
+
perplexity/resources/async_/__init__.py,sha256=hvcoEKx4nCYPDoBSO_sk-uNVQ7y-fmNhzvAlvX19TIo,964
|
|
33
|
+
perplexity/resources/async_/async_.py,sha256=p1-C_8m2cdS0NR3oa7FfdM8gxHH13LQWX6c9lh1gnFo,3510
|
|
34
|
+
perplexity/resources/async_/chat/__init__.py,sha256=BVAfz9TM3DT5W9f_mt0P9YRxL_MsUxKCWAH6u1iogmA,1041
|
|
35
|
+
perplexity/resources/async_/chat/chat.py,sha256=wOHHfLclvjAVv-btASi6EcdY5gJZQdwAdbR9Q9H4BKw,3658
|
|
36
|
+
perplexity/resources/async_/chat/completions.py,sha256=aQEd_z5FRl3N5YIqj3hC2LFFDLK70aVu9AubzodNNNk,13324
|
|
37
|
+
perplexity/resources/chat/__init__.py,sha256=BVAfz9TM3DT5W9f_mt0P9YRxL_MsUxKCWAH6u1iogmA,1041
|
|
38
|
+
perplexity/resources/chat/chat.py,sha256=P143HQo1m9MknnYtSq4JzmDofDtGHlXHzTaLEyr1a7k,3656
|
|
39
|
+
perplexity/resources/chat/completions.py,sha256=H0UwLYxERV2LXNj9ZBZlqLNPcB1U3dv9rqsq3BHKgn8,13315
|
|
40
|
+
perplexity/types/__init__.py,sha256=ho1vOafTpRoPrIpgk1taoebxSZ9QbkyBPWJCMHlbyKU,589
|
|
41
|
+
perplexity/types/content_create_params.py,sha256=qP3YBo-7wzh_1SNakoBO9ssUE8VmkLmin5pY6ebfdME,386
|
|
42
|
+
perplexity/types/content_create_response.py,sha256=_iwdGBc28BC4aYNIQ4p-yrc7ltVsUUbK7cb8J-5Ayk0,735
|
|
43
|
+
perplexity/types/search_create_params.py,sha256=zpsqdiQ78bDjPUE-dCIWZHQf5U_HyUrI55MnUHlW_Rg,2042
|
|
44
|
+
perplexity/types/search_create_response.py,sha256=SSOaX0FBdDeYL2dVlzYJraYKedjoPObzrG_RPw1SmDw,803
|
|
45
|
+
perplexity/types/async_/__init__.py,sha256=OKfJYcKb4NObdiRObqJV_dOyDQ8feXekDUge2o_4pXQ,122
|
|
46
|
+
perplexity/types/async_/chat/__init__.py,sha256=1ULArAJormThTsN1-TBsDQ-gKB6HIIJNtVaoR8PPJRg,555
|
|
47
|
+
perplexity/types/async_/chat/completion_create_params.py,sha256=CO76R15VQ_Bnt6pQ-huUXPJdeDFK2OzoXo5uSjHtIec,3048
|
|
48
|
+
perplexity/types/async_/chat/completion_create_response.py,sha256=fdwHTGwQi01ysHJMX-nEQ5JJUDy0naZhSJ30Rhb5nNU,1259
|
|
49
|
+
perplexity/types/async_/chat/completion_get_response.py,sha256=6vOpEH8X-V2kLnN3GSzYa6VadZ4J-e9YHX6ApJvdpzw,1253
|
|
50
|
+
perplexity/types/async_/chat/completion_list_params.py,sha256=rRPgrSIOl5PZ8HeDAOPbKTQ8_u0sGubtYnYdsomuy7Y,390
|
|
51
|
+
perplexity/types/async_/chat/completion_list_response.py,sha256=tI_XxSUmo7JnBwtpBl7Vb8R1rsOTHlYnScG5_LL8k0s,645
|
|
52
|
+
perplexity/types/chat/__init__.py,sha256=A5VCUPqJZydjjOqEXC01GXmcDkKM3bq6zuCu9lmi5Es,303
|
|
53
|
+
perplexity/types/chat/completion_create_params.py,sha256=GEF0xGk3krsQbUaFMJYKcph573Py571Rm2q8Qwiesww,2921
|
|
54
|
+
perplexity/types/chat/completion_create_response.py,sha256=5UjMQEQC8wUcM7H9FllzLpwoSM9x9gSd0dtXFXVrqcU,718
|
|
55
|
+
perplexity/types/shared/__init__.py,sha256=I_5WnFCvU4sKlUMTpqkuQCmyUpU4MHrslicgzGNop80,293
|
|
56
|
+
perplexity/types/shared/chat_choice.py,sha256=gez_WTykZW7I54rGr0WJAvdPVExdvc1BgR4E8e57dsY,386
|
|
57
|
+
perplexity/types/shared/chat_message.py,sha256=_KkDHtLJylc9NuJHQEjdBpMy2qEIxV2lz1Uana8hzNk,847
|
|
58
|
+
perplexity/types/shared/search_result.py,sha256=pm4L1gWI9_8NtpI1kjdfXzoOpD0CDE4IhrG6yED98go,271
|
|
59
|
+
perplexity/types/shared/usage_info.py,sha256=TGAReiJmZBjfXVxGsrKNaT7E0f5pi_D3GqB2qqjXOCc,458
|
|
60
|
+
perplexity/types/shared_params/__init__.py,sha256=vOrN5p21OFWPGWV_y68OkZnQltAXa53y308Tg2Lmct4,140
|
|
61
|
+
perplexity/types/shared_params/chat_message.py,sha256=haPdpCCjcOfLzcP25VeiVsSBuipz43co8HF_oFfWCf8,943
|
|
62
|
+
perplexityai-0.7.0.dist-info/METADATA,sha256=LBcuSfZ1GtdG5krefpUPQ7Gy2xkxXNRrJOfOgUCB1MI,15261
|
|
63
|
+
perplexityai-0.7.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
64
|
+
perplexityai-0.7.0.dist-info/licenses/LICENSE,sha256=hkCriG3MT4vBhhc0roAOsrCE7IEDr1ywVEMonVHGmAQ,11340
|
|
65
|
+
perplexityai-0.7.0.dist-info/RECORD,,
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
perplexity/__init__.py,sha256=5epbvK3UiJEgvsBW9Ds6RFB6zObkUxYkA9fIQlgUaXA,2655
|
|
2
|
-
perplexity/_base_client.py,sha256=DSeMteXutziRGJA9HqJaoLpG7ktzpU2GPcaIgQT1oZQ,67051
|
|
3
|
-
perplexity/_client.py,sha256=dMkVFaHlpMtICqxeJOxwhIj1PKBgn7DPdoMmOKfvQ0s,15613
|
|
4
|
-
perplexity/_compat.py,sha256=DQBVORjFb33zch24jzkhM14msvnzY7mmSmgDLaVFUM8,6562
|
|
5
|
-
perplexity/_constants.py,sha256=S14PFzyN9-I31wiV7SmIlL5Ga0MLHxdvegInGdXH7tM,462
|
|
6
|
-
perplexity/_exceptions.py,sha256=v-hOXWSDTEtXcn_By7pPml3HjEmG5HXpbE-RK_A6_0Q,3228
|
|
7
|
-
perplexity/_files.py,sha256=KnEzGi_O756MvKyJ4fOCW_u3JhOeWPQ4RsmDvqihDQU,3545
|
|
8
|
-
perplexity/_models.py,sha256=c29x_mRccdxlGwdUPfSR5eJxGXe74Ea5Dje5igZTrKQ,30024
|
|
9
|
-
perplexity/_qs.py,sha256=AOkSz4rHtK4YI3ZU_kzea-zpwBUgEY8WniGmTPyEimc,4846
|
|
10
|
-
perplexity/_resource.py,sha256=Pgc8KNBsIc1ltJn94uhDcDl0-3n5RLbe3iC2AiiNRnE,1124
|
|
11
|
-
perplexity/_response.py,sha256=bpqzmVGq6jnivoMkUgt3OI0Rh6xHd6BMcp5PHgSFPb0,28842
|
|
12
|
-
perplexity/_streaming.py,sha256=SQ61v42gFmNiO57uMFUZMAuDlGE0n_EulkZcPgJXt4U,10116
|
|
13
|
-
perplexity/_types.py,sha256=XZYv2_G7oQGhQkjI28-TFIMP_yZZV590TRuKAoLJ3wM,7300
|
|
14
|
-
perplexity/_version.py,sha256=jJUPrkIRgFBl89WVXU3mGpPT6gT2nbhE_hrTKXiRDtk,162
|
|
15
|
-
perplexity/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
-
perplexity/_utils/__init__.py,sha256=7fch0GT9zpNnErbciSpUNa-SjTxxjY6kxHxKMOM4AGs,2305
|
|
17
|
-
perplexity/_utils/_compat.py,sha256=D8gtAvjJQrDWt9upS0XaG9Rr5l1QhiAx_I_1utT_tt0,1195
|
|
18
|
-
perplexity/_utils/_datetime_parse.py,sha256=bABTs0Bc6rabdFvnIwXjEhWL15TcRgWZ_6XGTqN8xUk,4204
|
|
19
|
-
perplexity/_utils/_logs.py,sha256=CsE-zYnAQTOCueNGVjEn6bozMyE86gdjMhJDNWDLpaQ,786
|
|
20
|
-
perplexity/_utils/_proxy.py,sha256=aglnj2yBTDyGX9Akk2crZHrl10oqRmceUy2Zp008XEs,1975
|
|
21
|
-
perplexity/_utils/_reflection.py,sha256=ZmGkIgT_PuwedyNBrrKGbxoWtkpytJNU1uU4QHnmEMU,1364
|
|
22
|
-
perplexity/_utils/_resources_proxy.py,sha256=iMCHPeYmXwSunawEq3fcKGszOF3kL9w1ob-48Xnl04I,609
|
|
23
|
-
perplexity/_utils/_streams.py,sha256=SMC90diFFecpEg_zgDRVbdR3hSEIgVVij4taD-noMLM,289
|
|
24
|
-
perplexity/_utils/_sync.py,sha256=TpGLrrhRNWTJtODNE6Fup3_k7zrWm1j2RlirzBwre-0,2862
|
|
25
|
-
perplexity/_utils/_transform.py,sha256=i_U4R82RtQJtKKCriwFqmfcWjtwmmsiiF1AEXKQ_OPo,15957
|
|
26
|
-
perplexity/_utils/_typing.py,sha256=N_5PPuFNsaygbtA_npZd98SVN1LQQvFTKL6bkWPBZGU,4786
|
|
27
|
-
perplexity/_utils/_utils.py,sha256=D2QE7mVPNEJzaB50u8rvDQAUDS5jx7JoeFD7zdj-TeI,12231
|
|
28
|
-
perplexity/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
|
|
29
|
-
perplexity/resources/__init__.py,sha256=4gcgh_cZ4sqi0z898C_SeFbHx_RpXtkd3coApMVPiPs,1015
|
|
30
|
-
perplexity/resources/content.py,sha256=4BbRmRPY3qeYtP-b8toraEbRnBMAPYRZkyuri17SH-0,5905
|
|
31
|
-
perplexity/resources/search.py,sha256=3EqjYtS5EK457YAO0QXY5QutoqscbSqKKxkwM65sRqU,9270
|
|
32
|
-
perplexity/types/__init__.py,sha256=gD41Ien1RrCYCdig8ygalnShM5uT8k_l0-dx1u38I8I,441
|
|
33
|
-
perplexity/types/content_create_params.py,sha256=NHj29NXYWhvY9CpcE2RuqHQ-H2_dP7yRRa3fFUbB2AM,338
|
|
34
|
-
perplexity/types/content_create_response.py,sha256=Wr2TbU5lbEb5tHhw68erei5AGtX6hfQHmc-y8DcatLc,388
|
|
35
|
-
perplexity/types/search_create_params.py,sha256=RHKT4toTErSF4T5g0DYD9DTDFDOvjKF0BIa0t5Pv7bk,916
|
|
36
|
-
perplexity/types/search_create_response.py,sha256=lOteaJs4qpULkx5GLtEs6HhetqIBhM0I1AC1moWTeI8,426
|
|
37
|
-
perplexityai-0.6.0.dist-info/METADATA,sha256=_RTfMkrLjrfNgCxgD2YASfbevut51kA7ePgRI9E_17Q,13621
|
|
38
|
-
perplexityai-0.6.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
39
|
-
perplexityai-0.6.0.dist-info/licenses/LICENSE,sha256=hkCriG3MT4vBhhc0roAOsrCE7IEDr1ywVEMonVHGmAQ,11340
|
|
40
|
-
perplexityai-0.6.0.dist-info/RECORD,,
|
|
File without changes
|