SuperAPI AI Directory

nanoPerplexityAI

The simplest open-source implementation of perplexity.ai.

Open website

About this tool

Purpose

nanoPerplexityAI is a minimalist open-source implementation of perplexity.ai, designed to demonstrate the basic principles of a large language model (LLM) question-answering service with Google search citations using very little code. The project does not include a fancy graphical interface or LLM agents; it completes the core workflow in only about 200 lines of Python code, making it suitable as an introductory example for learning retrieval-augmented generation (RAG) and search-based question-answering systems.

Main Capabilities

  • Receives user queries, and the LLM determines whether a Google search needs to be performed.
  • If a search is needed, the LLM rewrites the user query into search terms suitable for Google, in order to find relevant webpage URLs and scrape text.
  • Builds a prompt using the system prompt, webpage context, and user query, and calls the LLM API to generate an answer.
  • During the LLM's streaming generation, saves the response as a markdown file for easy visualization.
  • Users can enter questions in the terminal, and the script generates playground.md, with support for pressing s to save and q to quit.

Usage

After running python nanoPerplexityAI.py, the script prompts for a question, then generates an answer and writes it to playground.md. Users can enter s to save and q to quit. To get a real-time generation interface similar to PerplexityAI, you can use Visual Studio Code to open the preview of playground.md and observe the real-time generation effect while running the script. Other methods include opening it in Markdown Playground, or pushing the output markdown file to a GitHub repository for display.

Applicable Scenarios

  • Learning the implementation principles of a PerplexityAI-style search-based question-answering system.
  • Studying how an LLM decides whether to search, how it rewrites queries, and how it combines webpage context to generate answers.
  • Serving as a starting point for building more complex retrieval-augmented generation applications.

Limitations

  • The project does not involve a complex GUI or LLM agents, and only provides basic command-line interaction.
  • Similar to PerplexityAI, it does not reformat search results, so not all search results will be used and cited; this is because the priority is to display search results quickly and stream the LLM response to improve user experience.
  • In actual use, PerplexityAI searches sources it has already indexed, whereas this project obtains webpages through Google search.
  • Information about API key configuration, dependency installation, and the specific supported LLM providers is not provided in the materials.