Skip to content

jinsoo96/Prompt_Foundry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

System Prompt Compliance Analysis RAG Chatbot

μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈμ— λŒ€ν•œ μ€€μˆ˜λ„λ₯Ό λΆ„μ„ν•˜λŠ” RAG 기반 μ±—λ΄‡μž…λ‹ˆλ‹€. μ—¬λŸ¬ LLM ν”„λ‘œλ°”μ΄λ”λ₯Ό μ§€μ›ν•˜λ©°, AI 응닡이 μ§€μ •λœ κ°€μ΄λ“œλΌμΈμ„ μ–Όλ§ˆλ‚˜ 잘 λ”°λ₯΄λŠ”μ§€ ν‰κ°€ν•©λ‹ˆλ‹€.

Features

  • λ‹€μ–‘ν•œ LLM ν”„λ‘œλ°”μ΄λ” 지원 (Upstage Solar, OpenAI, Anthropic Claude, Google Gemini, Ollama)
  • AI 기반 μžλ™ κ°€μ΄λ“œλΌμΈ μΆ”μΆœ
  • μ‹€μ‹œκ°„ μ€€μˆ˜λ„ 뢄석 및 μŠ€μ½”μ–΄λ§
  • ChromaDB 기반 RAG 톡합
  • μˆ˜λ™ κ°€μ΄λ“œλΌμΈ 관리
  • μˆ˜λ™/μžλ™ ν”„λ‘¬ν”„νŠΈ 버전 관리 및 μž¬ν‰κ°€ λŒ€μ‹œλ³΄λ“œ

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Frontend (React)                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚  System Prompt   β”‚  β”‚   RAG Chatbot    β”‚  β”‚ Compliance β”‚β”‚
β”‚  β”‚     Editor       β”‚  β”‚   Interface      β”‚  β”‚ Dashboard  β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β”‚ HTTP/REST API
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Backend (FastAPI)                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚                   API Routes                          β”‚   β”‚
β”‚  β”‚  /api/chat/message                                    β”‚   β”‚
β”‚  β”‚  /api/chat/extract-guidelines                         β”‚   β”‚
β”‚  β”‚  /api/compliance/{id}                                 β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                              β”‚                               β”‚
β”‚       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚       β–Ό                      β–Ό                      β–Ό       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚   RAG   β”‚         β”‚  Compliance  β”‚      β”‚   LLM    β”‚    β”‚
β”‚  β”‚ Service β”‚         β”‚   Checker    β”‚      β”‚ Provider β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚       β”‚                                           β”‚         β”‚
β”‚       β–Ό                                           β”‚         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                      β”‚         β”‚
β”‚  β”‚ChromaDB β”‚                                      β”‚         β”‚
β”‚  β”‚ Vector  β”‚                                      β”‚         β”‚
β”‚  β”‚   DB    β”‚                                      β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                      β”‚         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                    β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β–Ό                               β–Ό                 β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ Upstage Solar β”‚            β”‚   OpenAI     β”‚   β”‚  Anthropic   β”‚
            β”‚  (Default)    β”‚            β”‚              β”‚   β”‚    Claude    β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β–Ό                               β–Ό                 β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚    Ollama     β”‚            β”‚Google Gemini β”‚
            β”‚               β”‚            β”‚              β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tech Stack

Frontend

  • React with TypeScript
  • Vite for fast development
  • Recharts for compliance visualization
  • Axios for API communication

Backend

  • FastAPI for high-performance REST API
  • ChromaDB for vector storage and RAG
  • SQLite (backend/data/app.db) for prompt/evaluation persistence
  • Sentence Transformers for embeddings
  • Pydantic for data validation
  • Multiple LLM Providers:
    • Upstage Solar API
    • OpenAI API
    • Anthropic Claude API
    • Google Gemini API
    • Ollama (local)

Installation

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • npm

Backend Setup

cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

Create a .env file in the backend directory:

# LLM Provider (ollama, openai, upstage, anthropic, gemini)
LLM_PROVIDER=upstage

# Ollama (if using LLM_PROVIDER=ollama)
OLLAMA_MODEL=llama3.2
OLLAMA_HOST=http://localhost:11434

# OpenAI (if using LLM_PROVIDER=openai)
OPENAI_API_KEY=your-openai-api-key
OPENAI_MODEL=gpt-3.5-turbo

# Upstage Solar (if using LLM_PROVIDER=upstage)
UPSTAGE_API_KEY=your-upstage-api-key
UPSTAGE_MODEL=solar-pro2

# Anthropic (if using LLM_PROVIDER=anthropic)
ANTHROPIC_API_KEY=your-anthropic-api-key
ANTHROPIC_MODEL=claude-3-haiku-20240307

# Google Gemini (if using LLM_PROVIDER=gemini)
GOOGLE_API_KEY=your-google-api-key
GEMINI_MODEL=gemini-1.5-flash

# ChromaDB
CHROMA_DB_PATH=./data/chroma

# API
API_HOST=0.0.0.0
API_PORT=8000

Frontend Setup

cd frontend
npm install

Running the Application

Option 1: Start All Services (Recommended)

./start-all.sh

This will:

Option 2: Manual Start

Backend:

cd backend
source venv/bin/activate
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Frontend:

cd frontend
npm run dev

Usage

  1. Select LLM Provider: Choose your preferred LLM from the dropdown (Upstage, OpenAI, etc.)

  2. Configure System Prompt:

    • Enter your system prompt in the text area
    • Click "LLM Guidelines Extraction" to automatically extract guidelines
    • Or manually add guidelines using the "+ Add Manually" button
  3. Chat with the Bot:

    • Type your message in the chat interface
    • The AI will respond based on your system prompt
  4. View Compliance Analysis:

    • See real-time compliance scoring
    • Review detailed analysis for each guideline
    • Check which guidelines were followed/not followed with evidence
  5. Improve + Re-evaluate Prompts:

    • 우츑 νŒ¨λ„μ˜ β€œμžλ™ κ°œμ„  + μž¬ν‰κ°€β€ λ²„νŠΌμ„ λˆ„λ₯΄λ©΄ /api/prompts/improveκ°€ ν˜ΈμΆœλ˜μ–΄ μƒˆλ‘œμš΄ μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ 버전을 μƒμ„±ν•˜κ³ , κΈ°λ³Έ μ‹œλ‚˜λ¦¬μ˜€ 4μ’…(λΆˆλ²• μš”μ²­ 거절, κ°œμΈμ •λ³΄ μš”μ²­ 거절, 맀좜 μΈμ‚¬μ΄νŠΈ μš”μ•½, CS λ³΄κ³ μ„œ 톀)을 μžλ™ μž¬ν‰κ°€ν•©λ‹ˆλ‹€.
    • μƒμ„±λœ 버전과 μž¬ν‰κ°€ κ²°κ³ΌλŠ” Prompt Dashboardμ—μ„œ μ¦‰μ‹œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

API Documentation

Once the backend is running, visit:

Key Endpoints

  • POST /api/chat/message - Send a chat message and get compliance analysis
  • POST /api/chat/extract-guidelines - Extract guidelines from system prompt using LLM
  • GET /api/compliance/{compliance_id} - Get detailed compliance analysis
  • POST /api/chat/upload-document - Upload documents to RAG knowledge base

Project Structure

prompt-compliance-rag/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py                 # FastAPI application entry point
β”‚   β”‚   β”œβ”€β”€ dependencies.py         # Dependency injection
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   └── schemas.py          # Pydantic models
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ chat.py            # Chat and guideline endpoints
β”‚   β”‚   β”‚   └── compliance.py      # Compliance analysis endpoints
β”‚   β”‚   └── services/
β”‚   β”‚       β”œβ”€β”€ compliance_checker.py  # Compliance analysis logic
β”‚   β”‚       β”œβ”€β”€ llm_provider.py        # Multi-LLM abstraction
β”‚   β”‚       └── rag_service.py         # RAG with ChromaDB
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── .env
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx                # Main application component
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatInterface.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ComplianceDashboard.tsx
β”‚   β”‚   β”‚   └── SystemPromptEditor.tsx
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── api.ts             # API client
β”‚   β”‚   └── types/
β”‚   β”‚       └── index.ts           # TypeScript types
β”‚   β”œβ”€β”€ package.json
β”‚   └── vite.config.ts
β”œβ”€β”€ start-all.sh                   # Convenience script to start all services
└── README.md

Configuration

Switching LLM Providers

You can switch LLM providers in two ways:

  1. Environment Variable (default for all requests): Edit backend/.env and change LLM_PROVIDER

  2. Per-Request (runtime selection): Use the LLM provider dropdown in the UI

Adding Custom Documents to RAG

Use the /api/chat/upload-document endpoint:

curl -X POST http://localhost:8000/api/chat/upload-document \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Your document content here",
    "metadata": {"source": "custom"}
  }'

Automatic Prompt Improvement

  • Version Store: λͺ¨λ“  ν”„λ‘¬ν”„νŠΈ 버전은 SQLite(backend/data/app.db)에 μ €μž₯되며, /api/prompts/history둜 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.
  • κ°œμ„  API: POST /api/prompts/improve 에 run_reevaluation: trueλ₯Ό ν¬ν•¨ν•˜λ©΄ μ‹œλ‚˜λ¦¬μ˜€ 전체 μžλ™ μž¬ν‰κ°€κ°€ μ‹€ν–‰λ˜μ–΄ reevaluation ν•„λ“œλ‘œ κ²°κ³Όκ°€ λ°˜ν™˜λ©λ‹ˆλ‹€.
  • μ‹œλ‚˜λ¦¬μ˜€ ꡬ성 (backend/app/config/scenarios.json):
    1. Safety refusal (λΆˆλ²• ν–‰μœ„ 거절)
    2. PII refusal (κ°œμΈμ •λ³΄ μš”μ²­ 거절)
    3. Data insight summary (맀좜 데이터 μš”μ•½ + 원인 뢄석)
    4. Customer-service report tone (CS λ³΄κ³ μ„œ 이슈/원인/쑰치)

Experiment Playbook

  1. μ„œλΉ„μŠ€ 기동: ./start-all.sh μ‹€ν–‰ ν›„ http://localhost:8000, http://localhost:3000 접속.
  2. ν”„λ‘¬ν”„νŠΈ νŽΈμ§‘: 쒌츑 System Prompt Editorμ—μ„œ 도메인 μ§€μΉ¨ μž…λ ₯ β†’ κ°€μ΄λ“œλΌμΈ μΆ”μΆœ λ²„νŠΌμœΌλ‘œ ꡬ쑰화.
  3. λŒ€ν™”/μ€€μˆ˜λ„ 확인: Chat νŒ¨λ„μ—μ„œ λ©”μ‹œμ§€ 전솑 β†’ μ€€μˆ˜λ„ λŒ€μ‹œλ³΄λ“œλ‘œ μ¦‰μ‹œ μŠ€μ½”μ–΄ 확인.
  4. μžλ™ κ°œμ„  μ‹€ν—˜: ν”„λ‘¬νŠΈ λŒ€μ‹œλ³΄λ“œ 'μžλ™ κ°œμ„  + μž¬ν‰κ°€' λ²„νŠΌ 클릭 λ˜λŠ” curl -X POST http://localhost:8000/api/prompts/improve -H 'Content-Type: application/json' -d '{\"run_reevaluation\": true}'.
  5. κ²°κ³Ό 뢄석: Prompt Dashboard μΉ΄λ“œ ν˜Ήμ€ GET /api/evaluation/recent?limit=6으둜 졜근 평가 확인.
  6. μ‹œλ‚˜λ¦¬μ˜€ ν™•μž₯: app/config/scenarios.json에 μΆ”κ°€ μ‹œλ‚˜λ¦¬μ˜€ μ •μ˜ β†’ μ„œλ²„ μž¬μ‹œμž‘.

License

Copyright (c) 2026 jinsoo96. All rights reserved.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors