This document provides a comprehensive overview of all the scripts in the PineScript Expert Agent project, explaining their purpose, functionality, and usage order.
Purpose: Main implementation of the PineScript Expert Agent using Pydantic AI. Features:
- Defines the agent with OpenAI/OpenRouter model configuration
- Implements the retrieval tool for searching Pine Script documentation
- Contains the dependency injection mechanism for database and API connections
- Handles API key management and validation
Purpose: Defines the database schema for storing Pine Script documentation. Features:
- Creates tables with pgvector support for vector embeddings
- Includes validation functions to verify the database setup
- Defines the schema for the
pinescript_docstable
Purpose: Initial project setup script to prepare the environment. Features:
- Creates a virtual environment
- Installs dependencies from requirements.txt
- Sets up the .env file from the template
- Makes the shell script executable Usage: Run this first when setting up a new installation.
Purpose: Initializes the database with the required schema. Features:
- Creates necessary tables and extensions
- Verifies that pgvector is installed
- Checks and reports on database connection status
Usage: Run after
setup.pyto prepare the database.
Purpose: Utility to clear the database for a fresh start. Features:
- Removes all data from the pinescript_docs table
- Keeps schema intact
- Provides confirmation prompt for safety
Purpose: Crawls the TradingView Pine Script documentation. Features:
- Uses crawl4ai to extract documentation from the TradingView website
- Processes and splits documentation into sections
- Generates embeddings and stores in the database
Usage: Run after
init_db.pyto populate the database with documentation.
Purpose: Utility to inspect and query the database. Features:
- Counts entries in the database
- Lists document titles and URLs
- Tests search functionality
- Verifies vector quality
Purpose: Main entry point that provides multiple command options. Features:
interactive: Launches interactive shellquery: Processes a single querycheck: Verifies database setup Usage: The recommended way to interact with the agent.
Purpose: Provides an interactive command-line interface. Features:
- Command-line conversation with the agent
- History management
- Example queries
Usage: Run directly or through
run.py interactive.
Purpose: Streamlit UI with persistent conversation history. Features:
- Saves chat history to disk
- Maintains conversation context between sessions
- Same features as the regular Streamlit UI
- Example queries
- Status monitoring for database and API keys
Usage: Run with streamlit run streamlit_ui.py
Purpose: Debugging tool for API connections. Features:
- Tests OpenAI API connection
- Diagnoses API key issues
- Tests various client configurations Usage: Use when troubleshooting API connection problems.
For a new installation, follow these steps in order:
-
Initial Setup:
python setup.py
This prepares your environment, installing dependencies and setting up configuration files.
-
Database Initialization:
python init_db.py
This creates the necessary database schema with pgvector support.
-
Populate the Database (Crawl documentation):
python pinescript_crawler.py
-
Verify Setup:
python run.py check
This confirms that everything is set up correctly.
-
Run the Agent (choose one interface):
# Command-line interface python run.py interactive # Web interface streamlit run streamlit_ui.py
-
Clear Database: If you need to start fresh with documentation:
python clear_database.py
-
Inspect Database: To check the contents of the database:
python db_inspect.py count python db_inspect.py list python db_inspect.py search "your query" -
Debug API Issues: If you encounter API problems:
python api_debug.py