This commit is contained in:
Timothy Jaeryang Baek
2026-03-17 17:58:01 -05:00
parent fcf7208352
commit de3317e26b
220 changed files with 17200 additions and 22836 deletions
@@ -13,7 +13,7 @@ def search_perplexity_search(
query: str,
count: int,
filter_list: Optional[list[str]] = None,
api_url: str = "https://api.perplexity.ai/search",
api_url: str = 'https://api.perplexity.ai/search',
user=None,
) -> list[SearchResult]:
"""Search using Perplexity API and return the results as a list of SearchResult objects.
@@ -29,10 +29,10 @@ def search_perplexity_search(
"""
# Handle PersistentConfig object
if hasattr(api_key, "__str__"):
if hasattr(api_key, '__str__'):
api_key = str(api_key)
if hasattr(api_url, "__str__"):
if hasattr(api_url, '__str__'):
api_url = str(api_url)
try:
@@ -40,13 +40,13 @@ def search_perplexity_search(
# Create payload for the API call
payload = {
"query": query,
"max_results": count,
'query': query,
'max_results': count,
}
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json',
}
# Forward user info headers if user is provided
@@ -54,20 +54,17 @@ def search_perplexity_search(
headers = include_user_info_headers(headers, user)
# Make the API request
response = requests.request("POST", url, json=payload, headers=headers)
response = requests.request('POST', url, json=payload, headers=headers)
# Parse the JSON response
json_response = response.json()
# Extract citations from the response
results = json_response.get("results", [])
results = json_response.get('results', [])
return [
SearchResult(
link=result["url"], title=result["title"], snippet=result["snippet"]
)
for result in results
SearchResult(link=result['url'], title=result['title'], snippet=result['snippet']) for result in results
]
except Exception as e:
log.error(f"Error searching with Perplexity Search API: {e}")
log.error(f'Error searching with Perplexity Search API: {e}')
return []