Update PerplexityLLMService docstrings
This commit is contained in:
@@ -4,6 +4,13 @@
|
|||||||
# SPDX-License-Identifier: BSD 2-Clause License
|
# SPDX-License-Identifier: BSD 2-Clause License
|
||||||
#
|
#
|
||||||
|
|
||||||
|
"""Perplexity LLM service implementation.
|
||||||
|
|
||||||
|
This module provides a service for interacting with Perplexity's API using
|
||||||
|
an OpenAI-compatible interface. It handles Perplexity's unique token usage
|
||||||
|
reporting patterns while maintaining compatibility with the Pipecat framework.
|
||||||
|
"""
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from openai import NOT_GIVEN, AsyncStream
|
from openai import NOT_GIVEN, AsyncStream
|
||||||
@@ -22,10 +29,10 @@ class PerplexityLLMService(OpenAILLMService):
|
|||||||
in token usage reporting between Perplexity (incremental) and OpenAI (final summary).
|
in token usage reporting between Perplexity (incremental) and OpenAI (final summary).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
api_key (str): The API key for accessing Perplexity's API
|
api_key: The API key for accessing Perplexity's API.
|
||||||
base_url (str, optional): The base URL for Perplexity's API. Defaults to "https://api.perplexity.ai"
|
base_url: The base URL for Perplexity's API. Defaults to "https://api.perplexity.ai".
|
||||||
model (str, optional): The model identifier to use. Defaults to "sonar"
|
model: The model identifier to use. Defaults to "sonar".
|
||||||
**kwargs: Additional keyword arguments passed to OpenAILLMService
|
**kwargs: Additional keyword arguments passed to OpenAILLMService.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -50,11 +57,11 @@ class PerplexityLLMService(OpenAILLMService):
|
|||||||
"""Get chat completions from Perplexity API using OpenAI-compatible parameters.
|
"""Get chat completions from Perplexity API using OpenAI-compatible parameters.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
context: The context containing conversation history and settings
|
context: The context containing conversation history and settings.
|
||||||
messages: The messages to send to the API
|
messages: The messages to send to the API.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A stream of chat completion chunks
|
A stream of chat completion chunks from the Perplexity API.
|
||||||
"""
|
"""
|
||||||
params = {
|
params = {
|
||||||
"model": self.model_name,
|
"model": self.model_name,
|
||||||
@@ -85,8 +92,8 @@ class PerplexityLLMService(OpenAILLMService):
|
|||||||
and reporting them once at the end of processing.
|
and reporting them once at the end of processing.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
context (OpenAILLMContext): The context to process, containing messages
|
context: The context to process, containing messages and other
|
||||||
and other information needed for the LLM interaction.
|
information needed for the LLM interaction.
|
||||||
"""
|
"""
|
||||||
# Reset all counters and flags at the start of processing
|
# Reset all counters and flags at the start of processing
|
||||||
self._prompt_tokens = 0
|
self._prompt_tokens = 0
|
||||||
@@ -115,6 +122,9 @@ class PerplexityLLMService(OpenAILLMService):
|
|||||||
Perplexity reports token usage incrementally during streaming,
|
Perplexity reports token usage incrementally during streaming,
|
||||||
unlike OpenAI which provides a final summary. We accumulate the
|
unlike OpenAI which provides a final summary. We accumulate the
|
||||||
counts and report the total at the end of processing.
|
counts and report the total at the end of processing.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
tokens: Token usage information to accumulate.
|
||||||
"""
|
"""
|
||||||
if not self._is_processing:
|
if not self._is_processing:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user