Closed marcelocecin closed 1 month ago
I reached out asking for openapi docs
Install Openperplex using pip:
pip install --upgrade openperplex
Initialization
First, import the Openperplex class and create an instance:
from openperplex import Openperplex
api_key = "your_openperplex_api_key_here"
client = Openperplex(api_key)
Performing a Search
Here's how to perform a full search with sources, citations, and relevant questions:
result = client.search(
query="What are the latest developments in AI?",
date_context="2024-08-25", # if empty, the current date of the api server is used
location="us", # default is "us"
pro_mode=False, # default is False
response_language="en" # default is "auto"
)
print(result["llm_response"])
print(result["images"])
print("Sources:", result["sources"])
print("Relevant Questions:", result["relevant_questions"])
Simple Search
For a quick answer without additional context:
answer = client.search_simple(
query="Who won the FIFA World Cup in 2022?",
location="fr",
date_context="2024-08-25 7:00 AM",
pro_mode=False,
response_language="fr",
answer_type="text"
)
print(answer["llm_response"])
Website Content Retrieval
Retrieve text content from an URL :
result = client.get_website_text("https://www.example.com")
print(result)
Retrieve text in markdown format from an URL:
result = client.get_website_markdown("https://www.example.com")
print(result)
Get a screenshot of an URL:
result = client.get_website_screenshot("https://www.example.com")
print(f"Screenshot available at: {result['url']}")
URL-based Querying
Query content from a specific URL:
response = client.query_from_url(
url="https://www.example.com/article",
query="What is the main topic of this article?",
response_language="it",
answer_type="text" # default is "text" if not specified
)
print(response)
Openperplex uses custom exceptions for error handling. It's recommended to always wrap your API calls in try-except blocks to handle potential errors gracefully. Here's an example of how to implement error handling:
from openperplex import Openperplex, OpenperplexError
client = Openperplex("your_api_key_here")
try:
result = client.search("What is the meaning of life?")
print(result)
except OpenperplexError as e:
print(f"An error occurred: {e.status_code} - {e.detail}")
except Exception as e:
print(f"An unexpected error occurred: {str(e)}")
Thank you @marcelocecin!
Base integration ready at: https://pipedream.com/apps/openperplex
@YassKhazzan prepared brand new openai docs for us https://docs.openperplex.com/introduction Thank you too!
Name of app / service OpenPerplex
Link to developer documentation https://api.openperplex.com/pythonLibrary https://github.com/YassKhazzan/openperplex_backend_os