Skip to content

Instantly share code, notes, and snippets.

@saifsmailbox98
Created July 26, 2025 12:17
Show Gist options
  • Save saifsmailbox98/08d56d318db535cd17783b401ce91775 to your computer and use it in GitHub Desktop.
Save saifsmailbox98/08d56d318db535cd17783b401ce91775 to your computer and use it in GitHub Desktop.
pplx
from os import getenv
from dotenv import load_dotenv
from rich.console import Console
from rich.live import Live
from rich.panel import Panel
from perplexity_webui_scraper import Perplexity, CitationMode, ModelType, SearchFocus, SourceFocus, TimeRange
load_dotenv()
console = Console()
# Print all available options
print("=== CitationMode Options ===")
for attr in dir(CitationMode):
if not attr.startswith('_'):
print(f"CitationMode.{attr}: {getattr(CitationMode, attr)}")
print("\n=== ModelType Options ===")
for attr in dir(ModelType):
if not attr.startswith('_'):
value = getattr(ModelType, attr)
print(f"ModelType.{attr}: {value}")
# If it's a class/category, explore its sub-options
if hasattr(value, '__dict__'):
for sub_attr in dir(value):
if not sub_attr.startswith('_'):
print(f" ModelType.{attr}.{sub_attr}: {getattr(value, sub_attr)}")
print("\n=== SearchFocus Options ===")
for attr in dir(SearchFocus):
if not attr.startswith('_'):
print(f"SearchFocus.{attr}: {getattr(SearchFocus, attr)}")
print("\n=== SourceFocus Options ===")
for attr in dir(SourceFocus):
if not attr.startswith('_'):
print(f"SourceFocus.{attr}: {getattr(SourceFocus, attr)}")
print("\n=== TimeRange Options ===")
for attr in dir(TimeRange):
if not attr.startswith('_'):
print(f"TimeRange.{attr}: {getattr(TimeRange, attr)}")
print("\n" + "="*50)
print("Starting Perplexity query...")
print("="*50 + "\n")
client = Perplexity(session_token=getenv("PERPLEXITY_SESSION_TOKEN"))
with Live(Panel("", title="Waiting for answer", border_style="white"), refresh_per_second=30, vertical_overflow="visible") as live:
for chunk in client.ask(
query="Explain in a simplified and easy-to-understand way what a chatbot is.",
citation_mode=CitationMode.MARKDOWN,
model=ModelType.Pro.Gemini25Pro0605,
save_to_library=False,
search_focus=SearchFocus.WEB,
source_focus=SourceFocus.WEB,
time_range=TimeRange.ALL,
language="en-US",
timezone="America/New_York",
coordinates=(-0.123, -4.567),
).stream():
if chunk.last_chunk:
current_answer = chunk.answer or ""
live.update(Panel(current_answer, title="Receiving tokens", border_style="blue"))
final_answer = chunk.answer or "No answer received"
live.update(Panel(final_answer, title="Final answer", border_style="green"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment