This project offers both a TypeScript server (Node.js and Express) and a Python script to query the perplexity.ai website and fetch answers to user's questions. Both implementations use browser automation: the TypeScript server uses Puppeteer, while the Python script uses Selenium.
- Node.js (v14.0.0 or higher) and npm (v6.14.0 or higher) for TypeScript server
- Python (3.6 or higher) for Python script
- Clone the repository or download the source code.
git clone https://github.com/Arbaaz-Mahmood/Perplexity-API.git- Navigate to the project directory.
cd perplexity-query-api- Install the required dependencies.
npm install- Run the server using
ts-node:
npx ts-node app.tsThe server will start at http://localhost:3000 by default. Users can send a POST request to the /query endpoint with a JSON payload that includes a prompt field.
- Install the required Python packages:
pip install selenium beautifulsoup4 webdriver-manager- Install ChromeDriver:
- macOS:
- You can use Homebrew to install ChromeDriver:
brew install chromedriver - Make sure the installed ChromeDriver is in your
PATHenvironment variable.
- You can use Homebrew to install ChromeDriver:
- Windows:
- Download ChromeDriver from the official site.
- Extract the executable and add the folder containing the executable to your
PATHenvironment variable.
- Linux:
- Use the package manager for your distribution to install ChromeDriver.
- For example, on Ubuntu-based systems:
sudo apt-get install chromium-chromedriver - Make sure the installed ChromeDriver is in your
PATHenvironment variable.
- Run the
perplexity_query.pyscript:
python perplexity_query.pyThe Python script will prompt for a question, interact with the perplexity.ai website, and print the response to the console.
This project is licensed under the MIT License. See the LICENSE file for the full license text.