How talgaon4/promptcraft-api works
Project type and purpose
• This is a Python-based full-stack API library (PromptCraft API) with an interactive Streamlit frontend.
• Purpose: automatically optimize AI prompts by tracking usage, collecting feedback, and iteratively generating improved prompt versions via an LLM service.
File structure
• Top level:
• interface/: Streamlit app (interface/app.py, interface/launch.py)
• prompt_optimizer/: core library code
• tests, test_*.py: unit/integration tests
• prompt_optimizer modules:
• api.py, auto_optimizer.py, optimization_manager.py – external entrypoints
• core/: feedback_collector, models, optimizer_engine, prompt_manager, response_tracker
• services/llm_service.py – integration with external LLMs
• storage/: base & local_storage (persistence)
• strategies/: optimization strategies (bandit, reward_model, etc.)
README insights
• Exposes a PromptOptimizer class for registration, usage recording, feedback capture, and optimization.
• Dependencies: Python, Streamlit, LLM provider SDK.
a. Main components
1. Client Layer
• CLI / Python consumer using PromptOptimizer API
• Streamlit Web UI
2. API Layer
• prompt_optimizer/api.py
3. Core Engine
• Prompt Manager (register, versioning)
• Feedback Collector
• Response Tracker
• Optimizer Engine (orchestration)
• Optimization Manager & auto-optimizer
4. Strategy Modules
• Reward model bandit
• Simple AI strategy
• Component strategies (promotion, shadow testing, etc.)
5. Services
• LLM Service (external API wrapper)
6. Storage
• Local Storage (JSON, file, or extendable base storage)
b. Relationships and interactions
• Client → API: calls register_prompt, record_prompt_use, record_response, record_feedback, optimize_prompt
• API → Core Engine: delegates business logic
• Core Engine → Services/LLM: sends prompt text, retrieves LLM responses during optimization
• Core Engine → Storage: persists prompts, instances, responses, feedback, version history
• Strategy Modules are invoked by the Optimizer Engine to decide how to generate next prompt versions
• Streamlit UI ↔ API: REST-like or direct import for interactive operations and real-time visualizations
c. Architectural patterns & principles
• Layered architecture: separation between interface, API, business logic, persistence, and external services
• Strategy pattern: pluggable optimization algorithms under strategies/
• Dependency inversion: core refers to abstract storage base and LLM service interfaces
• Single responsibility: each module focuses on one aspect (e.g., feedback collection vs. prompt management)
d. Key technologies & frameworks
• Python (3.x)
• Streamlit (interface)
• External LLM provider SDK (wrapped in llm_service.py)
• Local JSON/file storage (local_storage.py) – swapable for databases
Detail
• Version history flow in the Prompt Manager component