pocketflow/cookbook/pocketflow-chat
zachary62 556130d4f4 add chat 2025-03-21 14:10:12 -04:00
..
README.md add chat 2025-03-21 14:10:12 -04:00
main.py add chat 2025-03-21 14:10:12 -04:00
requirements.txt add chat 2025-03-21 14:10:12 -04:00
utils.py add chat 2025-03-21 14:10:12 -04:00

README.md

Simple PocketFlow Chat

A basic chat application using PocketFlow with OpenAI's GPT-4o model.

Features

  • Conversational chat interface in the terminal
  • Maintains full conversation history for context
  • Simple implementation demonstrating PocketFlow's node and flow concepts

Run It

  1. Make sure your OpenAI API key is set:

    export OPENAI_API_KEY="your-api-key-here"
    

    Alternatively, you can edit the utils.py file to include your API key directly.

  2. Install requirements and run the application:

    pip install -r requirements.txt
    python main.py
    

How It Works

flowchart LR
    chat[ChatNode] -->|continue| chat

The chat application uses:

  • A single ChatNode with a self-loop that:
    • Takes user input in the prep method
    • Sends the complete conversation history to GPT-4o
    • Adds responses to the conversation history
    • Loops back to continue the chat until the user types 'exit'

Files

  • main.py: Implementation of the ChatNode and chat flow
  • utils.py: Simple wrapper for calling the OpenAI API