How yusuke710/nanoperplexityai works
Project Overview & Type
• This project is an open-source, lightweight implementation of perplexity.ai. It is a single-script tool (around 200 lines of Python) that takes a user query, optionally performs a Google search to extract context from web pages, builds a prompt, and calls an LLM API (such as OpenAI’s) to generate a response. The responses are then streamed and saved into a markdown file.
• As an open-source tool, it focuses on rapid prototyping and minimalism without a complex GUI. The primary goal is to quickly generate LLM responses enriched by contextual data retrieved via a search.
Analyzing the File Structure
• Top-Level Files:
• The main executable is nanoPerplexityAI.py.
• playground.md serves as the dynamic output/visualization file.
• example_outputs/ holds pre-generated markdown answer examples.
• Directories like assets contain images and demo gifs that help illustrate the project.
• The experiments/ directory shows that some explorative code and optimization notes exist, which suggests active iterative development.
• Configuration files such as .gitignore and LICENSE.txt are present alongside the README that explains project usage and installation.
Core Architecture (as described in the README)
The README enumerates the following key steps:
a. Capturing the user query.
b. Deciding whether to trigger a Google search and fetching webpage content.
c. Composing a prompt by combining a system prompt, fetched context, and the user's query.
d. Making a call to the LLM API for generating the answer.
e. Streaming the answer to a markdown file (playground.md) for real-time output.
• User Interface (CLI Input):
• Mention that it’s a CLI-based input system that prompts the user.
• Query Processing Module:
• This module handles analyzing the user query and deciding if a Google search is required.
• Google Search Integration:
• An external component that, if triggered, calls the Google Search API via libraries like googlesearch-python, requests, BeautifulSoup4, etc.
• Prompt Builder:
• This component compiles the system prompt, the fetched webpage context, and the original query.
• LLM API Caller:
• External integration with the large language model (e.g., OpenAI API).
• Markdown Output Generator:
• This is in charge of streaming LLM responses and saving them in a markdown file (e.g., playground.md).
• File Storage & Assets:
• Although auxiliary, illustrate that the system outputs data (responses in markdown file) and also accesses static assets (assets/) for UI elements if needed.
• Optionally, add a component for “File System / Asset Storage” indicating usage of example_outputs and assets folders.
b. Depicting Relationships and Data Flow:
c. Architectural Patterns:
• Even though it is a small script, annotate that the architecture reflects a modular design:
• Separation between input handling, data fetching, processing, and external API integration.
• It employs a “pipeline” or “chain-of-responsibility” pattern to build and execute the query.
• Details about external dependencies (e.g., googlesearch-python, requests, beautifulsoup4, openai) alongside the respective components.
d. Technologies & Frameworks:
• Mention that the project is built in Python and uses specific third-party libraries as per the README install instructions.