# weikeeyong/openai-pdf2campaigncontent architecture

> Architecture diagram of the GitHub repository weikeeyong/openai-pdf2campaigncontent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/weikeeyong/openai-pdf2campaigncontent
- Repository: https://github.com/weikeeyong/openai-pdf2campaigncontent

## Overview

##### Project type and purpose
- This is a lightweight Python proof-of-concept (POC) tool that automates the process of converting user-provided PDFs into campaign-style email content by leveraging the OpenAI API. It is not a full-stack web app but rather a CLI/script-driven workflow.

##### File structure
- Top level:
- README.md – project description and usage
- UploadPDF2Assistant.py – core script that uploads PDF, links it to a vector store, invokes the assistant, and prints HTML
- UploadPDF2Assistant-FunctionCalling.py – variant that uses OpenAI function-calling features
- No frontend directory, no web server config—this runs entirely as a local Python process that calls out to OpenAI services.

##### README for additional insights
- Workflow steps:
1. Upload local PDF
2. Link PDF to an OpenAI-backed vector store
3. Request content generation via an OpenAI Assistant (specified by Assistant ID)
4. Receive HTML email body
5. Clean up the uploaded file
- Prerequisites: configured OpenAI Assistant, Vector Store, API key management

##### Main components and their interactions
a. Local Orchestrator (Python script)
- Reads config/API key
- Prompts or accepts PDF file path
- Calls OpenAI “files” endpoint to upload
- Attaches the uploaded file to a vector store via API
- Polls for indexing completion
- Sends a chat/assistant request (or function call) to generate HTML content
- Receives and displays/stores the HTML
- Cleans up the file on the server
b. OpenAI Cloud Services
- File Storage Service (/files endpoint)
- Vector Store Service (PDF indexing & retrieval)
- Assistant Service (chat completions or function-calling)
c. Optional: Local Configuration (e.g., `.env` or `openai_key.txt`)

##### Architectural patterns and principles
- Orchestration script pattern: single-flow sequence
- Polling loop for asynchronous file indexing
- Clear separation between orchestration logic and external services
- Function-calling variant encapsulates logic into JSON function schemas

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Local Environment"
        Script1["UploadPDF2Assistant.py"]:::local
        Script2["UploadPDF2Assistant-FunctionCalling.py"]:::local
        Config["Config Store (.env / openai_key.txt)"]:::config
        README["README.md"]:::local
    end

    subgraph "OpenAI Cloud"
        FileStorage["File Storage Service<br/>(POST /v1/files, DELETE /v1/files/{id})"]:::cloud
        VectorStore["Vector Store Service<br/>(Indexing & Retrieval)"]:::cloud
        Assistant["Assistant Service<br/>(POST /v1/assistants/{id}/chat/completions)"]:::cloud
    end

    Script1 -->|"POST /v1/files"| FileStorage
    Script2 -->|"POST /v1/files"| FileStorage

    Script1 -->|"POST /v1/vector_store/attach"| VectorStore
    Script2 -->|"POST /v1/vector_store/attach"| VectorStore

    Script1 -.->|"polling for indexing status"| VectorStore
    Script2 -.->|"polling for indexing status"| VectorStore

    Script1 -->|"POST /v1/assistants/{id}/chat/completions"| Assistant
    Script2 -->|"POST /v1/assistants/{id}/chat/completions (function call)"| Assistant

    Assistant -->|"HTML response"| Script1
    Assistant -->|"HTML response"| Script2

    Script1 -->|"DELETE /v1/files/{id}"| FileStorage
    Script2 -->|"DELETE /v1/files/{id}"| FileStorage

    classDef local fill:#D6EAF8,stroke:#3498DB,stroke-width:1px;
    classDef cloud fill:#D5F5E3,stroke:#27AE60,stroke-width:1px;
    classDef config fill:#FCF3CF,stroke:#F1C40F,stroke-width:1px;

    click Script1 "https://github.com/weikeeyong/openai-pdf2campaigncontent/blob/main/UploadPDF2Assistant.py"
    click Script2 "https://github.com/weikeeyong/openai-pdf2campaigncontent/blob/main/UploadPDF2Assistant-FunctionCalling.py"
    click README "https://github.com/weikeeyong/openai-pdf2campaigncontent/blob/main/README.md"
```
