Skip to content

braindead-dev/ask-pg

Repository files navigation

PG Chat Logo

Chat with AI PG

An AI-powered chat application that lets you interact with a virtual Paul Graham, trained on his essays. Get insights, advice, and perspectives in PG's characteristic direct and concise style.

🌟 Features

  • Chat interface with AI Paul Graham
  • Trained on PG's essays for authentic responses
  • Real-time streaming responses
  • Modern, responsive UI built with Next.js and Tailwind CSS
  • Vector-based semantic search through PG's essays
  • Server-sent events for smooth chat experience

🚀 Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • npm or yarn
  • A Vercel KV database instance
  • An OpenAI API key

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/ask-pg.git
cd ask-pg
  1. Install dependencies:
npm install
# or
yarn install
  1. Set up environment variables by creating a .env file in the root directory:
OPENAI_API_KEY=your_openai_api_key_here
KV_URL=your_vercel_kv_url_here
KV_REST_API_READ_ONLY_TOKEN=your_kv_readonly_token_here
KV_REST_API_URL=your_kv_rest_api_url_here
  1. Set up the vector store by going to OpenAI's vector store page and creating a new vector store, and uploading the essays in /public/essays. Then, get the vector store ID and update the vectorStoreId in config/ai.ts.

  2. Run the development server:

npm run dev
# or
yarn dev
  1. Open http://localhost:3000 in your browser to start chatting!

🔧 Configuration

AI Configuration (config/ai.ts)

The config/ai.ts file contains important settings for the AI chat functionality:

  • model: Specifies the OpenAI model to use (default: "gpt-4o-mini")
  • defaultSystemPrompt: The system prompt that defines PG's personality and behavior
  • fileSearch: Configuration for the vector store search
    • vectorStoreId: ID for the vector store containing PG's essays
    • maxResults: Maximum number of essay results to return per search
  • storeResponse: Whether to store generated responses for later retrieval

Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key for accessing the GPT models
  • KV_URL: Vercel KV database URL for storing chat data
  • KV_REST_API_READ_ONLY_TOKEN: Read-only token for KV REST API access
  • KV_REST_API_URL: URL for the KV REST API endpoint

Vector Store Setup

Before the application can function properly, you'll need to:

  1. Upload Paul Graham's essays to OpenAI's vector storage
  2. Get your vector store ID from OpenAI
  3. Update the vectorStoreId in config/ai.ts with your vector store ID

Without this setup, the semantic search functionality that helps the AI reference PG's essays will not work.

🛠️ Tech Stack

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

⭐️ Support

If you find this project helpful, please consider giving it a star on GitHub!

About

Chat with an AI version of Paul Graham, with the context of his 200+ essays

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published