Skip to content

Conversation

The Conversation class manages a single conversation thread with multi-turn and streaming support. Create instances via client.create_conversation().

perplexity_webui_scraper.core.conversation.Conversation

Conversation(http: HTTPClient, config: ConversationConfig)

Manage a Perplexity conversation thread with multi-turn and streaming support.

Create instances via client.create_conversation() — do not instantiate directly.

Example
for response in conversation.ask("Tell me a story", stream=True):
    print(response.last_chunk, end="", flush=True)
ATTRIBUTE DESCRIPTION
answer

The most recent final answer text.

TYPE: str | None

search_results

Web sources cited in the last response.

TYPE: list[SearchResultItem]

uuid

Conversation UUID returned by Perplexity.

TYPE: str | None

Source code in src/perplexity_webui_scraper/core/conversation.py
def __init__(self, http: HTTPClient, config: ConversationConfig) -> None:
    self._http = http
    self._config = config
    self._citation_mode: CitationMode = config.citation_mode
    self._backend_uuid: str | None = None
    self._read_write_token: str | None = None
    self._answer: str | None = None
    self._chunks: list[str] = []
    self._search_results: list[SearchResultItem] = []
    self._raw_data: dict[str, Any] = {}
    self._stream_generator: Generator[Response, None, None] | None = None

Attributes

answer property

answer: str | None

Most recent final answer text. None until a response completes.

search_results property

search_results: list[SearchResultItem]

Web sources cited in the most recent response.

uuid property

uuid: str | None

Backend conversation UUID. None before the first query completes.

Functions

ask

ask(query: str, model: str | None = None, files: list[FileInput] | None = None, citation_mode: CitationMode | None = None, stream: bool = False) -> Conversation

Send a query and return self for chaining or streaming iteration.

In non-streaming mode, blocks until the response completes. In streaming mode, iterate over self to receive chunks.

PARAMETER DESCRIPTION
query

The prompt text.

TYPE: str

model

Model ID override. Falls back to config or "perplexity/best".

TYPE: str | None DEFAULT: None

files

Optional list of attachments.

TYPE: list[FileInput] | None DEFAULT: None

citation_mode

Per-query citation override.

TYPE: CitationMode | None DEFAULT: None

stream

If True, sets up an internal generator for streaming.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Conversation

self to support method chaining or iteration.

Source code in src/perplexity_webui_scraper/core/conversation.py
def ask(
    self,
    query: str,
    model: str | None = None,
    files: list[FileInput] | None = None,
    citation_mode: CitationMode | None = None,
    stream: bool = False,
) -> Conversation:
    """Send a query and return ``self`` for chaining or streaming iteration.

    In non-streaming mode, blocks until the response completes.
    In streaming mode, iterate over ``self`` to receive chunks.

    Args:
        query: The prompt text.
        model: Model ID override. Falls back to config or ``"perplexity/best"``.
        files: Optional list of attachments.
        citation_mode: Per-query citation override.
        stream: If ``True``, sets up an internal generator for streaming.

    Returns:
        ``self`` to support method chaining or iteration.
    """
    model_id = model or self._config.model or _DEFAULT_MODEL
    resolved_model = MODELS.resolve(model_id)
    self._citation_mode = citation_mode if citation_mode is not None else self._config.citation_mode

    self._execute(query, resolved_model, files, stream=stream)

    return self