This module is simply just an API Wrapper and account generator. It serves as an API wrapper with free copilots.
This module uses emailnator to generate new accounts. As you know, when you create a new account, you will have 5 copilots. That's how it works! This module will generate you new gmails (using @googlemail.com right now) with emailnator and you will have UNLIMITED COPILOTS!
First thing first, Perplexity.ai is protected by cloudflare, and emailnator too. We need to open this pages manually and get the cookies. Do not forget these cookies are temporary, so you need to renew them continuously. Here how to get your cookies.
import perplexity
perplexity_headers = {
<your headers here>
}
perplexity_cookies = {
<your cookies here>
}
emailnator_headers = {
<your headers here>
}
emailnator_cookies = {
<your cookies here>
}
# If you're going to use your own account, login to your account and copy headers/cookies (reload the page). Set "own" as True, and do not call "create_account" function. This will deactivate copilot and file upload limit controls
perplexity_cli = perplexity.Client(perplexity_headers, perplexity_cookies, own=False)
perplexity_cli.create_account(emailnator_headers, emailnator_cookies) # Creates a new gmail, so your 5 copilots will be renewed. You can pass this one if you are not going to use "copilot" mode
# takes a string as query, and returns a string as answer.
def my_text_prompt_solver(query):
return input(f'{query}: ')
# takes a string as description and a dictionary as options. Dictionary consists of ids and values. Example: {1: "Orange", 2: "Banana"}
# returns a list of integers which are ids of selected options. Let's say you selected "Banana", function should return [2]
def my_checkbox_prompt_solver(description, options):
print(description + '\n' + '\n'.join([str(x) + ' - ' + options[x] for x in options]))
return [int(input('--> '))]
# modes = ['concise', 'copilot']
# focus = ['internet', 'scholar', 'wolfram', 'writing', 'youtube', 'reddit']
# files = file list, each element of list is tuple like this: (data, filename)
# follow_up = last query info for follow-up queries, you can directly pass response json from a query, look at second example below.
# ai_model = ['default', 'experimental', 'gpt-4', 'claude-2.1', 'gemini pro'] only works for own=True clients (perplexity.Client(..., own=True))
# solvers, list of functions to answer questions of ai while using copilot, there are 2 type of solvers, text and checkbox. If you do not define function for a solver, questions in that solver type will be skipped
resp = perplexity_cli.search('Your query here', mode='copilot', focus='internet', files=[(open('myfile.txt', 'rb').read(), 'txt'), (open('myfile2.pdf', 'rb').read(), 'pdf')], ai_model='default', solvers={
'text': my_text_prompt_solver,
'checkbox': my_checkbox_prompt_solver
})
print(resp)
# second example to show how to use follow-up queries
# you can't use file uploads on follow-up queries
# you can pass response json from a query directly like below
resp2 = perplexity_cli.search('Your query here', mode='copilot', focus='internet', follow_up=resp, solvers={
'text': my_text_prompt_solver,
'checkbox': my_checkbox_prompt_solver
})
print(resp2)
# perplexity_cli.create_account(emailnator_headers, emailnator_cookies) # Call this function again when you run out of copilots
import perplexity_async
import asyncio
perplexity_headers = {
<your headers here>
}
perplexity_cookies = {
<your cookies here>
}
emailnator_headers = {
<your headers here>
}
emailnator_cookies = {
<your cookies here>
}
# takes a string as query, and returns a string as answer.
async def my_text_prompt_solver(query):
return input(f'{query}: ')
# takes a string as description and a dictionary as options. Dictionary consists of ids and values. Example: {1: "Orange", 2: "Banana"}
# returns a list of integers which are ids of selected options. Let's say you selected "Banana", function should return [2]
async def my_checkbox_prompt_solver(description, options):
print(description + '\n' + '\n'.join([str(x) + ' - ' + options[x] for x in options]))
return [int(input('--> '))]
async def test():
# If you're going to use your own account, login to your account and copy headers/cookies (reload the page). Set "own" as True, and do not call "create_account" function. This will deactivate copilot and file upload limit controls
perplexity_cli = await perplexity_async.Client(perplexity_headers, perplexity_cookies, own=False)
await perplexity_cli.create_account(emailnator_headers, emailnator_cookies) # Creates a new gmail, so your 5 copilots will be renewed. You can pass this one if you are not going to use "copilot" mode
# modes = ['concise', 'copilot']
# focus = ['internet', 'scholar', 'writing', 'wolfram', 'youtube', 'reddit']
# files = file list, each element of list is tuple like this: (data, filetype) perplexity supports two file types, txt and pdf
# follow_up = last query info for follow-up queries, you can directly pass response json from a query, look at second example below.
# ai_model = ['default', 'experimental', 'gpt-4', 'claude-2.1', 'gemini pro'] only works for own=True clients (perplexity_async.Client(..., own=True))
# solvers, list of functions to answer questions of ai while using copilot, there are 2 type of solvers, text and checkbox. If you do not define function for a solver, questions in that solver type will be skipped
resp = await perplexity_cli.search('Your query here', mode='copilot', focus='internet', files=[(open('myfile.txt', 'rb').read(), 'txt'), (open('myfile2.pdf', 'rb').read(), 'pdf')], ai_model='default', solvers={
'text': my_text_prompt_solver,
'checkbox': my_checkbox_prompt_solver
})
print(resp)
# second example to show how to use follow-up queries
# you can't use file uploads on follow-up queries
# you can pass response json from a query directly like below
resp2 = await perplexity_cli.search('Your query here', mode='copilot', focus='internet', follow_up=resp, solvers={
'text': my_text_prompt_solver,
'checkbox': my_checkbox_prompt_solver
})
print(resp2)
# await perplexity_cli.create_account(emailnator_headers, emailnator_cookies) # Call this function again when you're out of copilots
asyncio.run(test())
Do not forget these cookies are temporary, so you need to renew them continuously.