Module livekit.plugins.perplexity
Perplexity plugin for LiveKit Agents
Wraps Perplexity's OpenAI-compatible chat completions endpoint at
https://api.perplexity.ai so it can be used as a drop-in LLM for LiveKit
voice agents.
Sub-modules
livekit.plugins.perplexity.responses
Classes
class LLM (*,
model: str | PerplexityChatModels = 'sonar-pro',
api_key: NotGivenOr[str] = NOT_GIVEN,
base_url: NotGivenOr[str] = 'https://api.perplexity.ai',
client: openai.AsyncClient | None = None,
user: NotGivenOr[str] = NOT_GIVEN,
temperature: NotGivenOr[float] = NOT_GIVEN,
parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN,
tool_choice: NotGivenOr[ToolChoice] = NOT_GIVEN,
top_p: NotGivenOr[float] = NOT_GIVEN,
timeout: httpx.Timeout | None = None)-
Expand source code
class LLM(OpenAILLM): def __init__( self, *, model: str | PerplexityChatModels = "sonar-pro", api_key: NotGivenOr[str] = NOT_GIVEN, base_url: NotGivenOr[str] = PERPLEXITY_BASE_URL, client: openai.AsyncClient | None = None, user: NotGivenOr[str] = NOT_GIVEN, temperature: NotGivenOr[float] = NOT_GIVEN, parallel_tool_calls: NotGivenOr[bool] = NOT_GIVEN, tool_choice: NotGivenOr[ToolChoice] = NOT_GIVEN, top_p: NotGivenOr[float] = NOT_GIVEN, timeout: httpx.Timeout | None = None, ): """ Create a new instance of Perplexity LLM. ``api_key`` must be set to your Perplexity API key, either using the argument or by setting the ``PERPLEXITY_API_KEY`` environmental variable. """ api_key = api_key if is_given(api_key) else os.environ.get("PERPLEXITY_API_KEY", "") if not api_key: raise ValueError( "PERPLEXITY_API_KEY is required, either as argument or set " "PERPLEXITY_API_KEY environmental variable" ) super().__init__( model=model, api_key=api_key, base_url=base_url, client=client, user=user, temperature=temperature, parallel_tool_calls=parallel_tool_calls, tool_choice=tool_choice, top_p=top_p, timeout=timeout, extra_headers=_ATTRIBUTION_HEADER, _strict_tool_schema=False, ) @property def model(self) -> str: return self._opts.model @property def provider(self) -> str: return "Perplexity"Helper class that provides a standard way to create an ABC using inheritance.
Create a new instance of Perplexity LLM.
api_keymust be set to your Perplexity API key, either using the argument or by setting thePERPLEXITY_API_KEYenvironmental variable.Ancestors
- livekit.plugins.openai.llm.LLM
- livekit.agents.llm.llm.LLM
- abc.ABC
- EventEmitter
- typing.Generic
Instance variables
prop model : str-
Expand source code
@property def model(self) -> str: return self._opts.modelGet the model name/identifier for this LLM instance.
Returns
The model name if available, "unknown" otherwise.
Note
Plugins should override this property to provide their model information.
prop provider : str-
Expand source code
@property def provider(self) -> str: return "Perplexity"Get the provider name/identifier for this LLM instance.
Returns
The provider name if available, "unknown" otherwise.
Note
Plugins should override this property to provide their provider information.
Inherited members