Compare commits
1 Commits
e3d7e7de3a
...
fastapi_at
| Author | SHA1 | Date | |
|---|---|---|---|
| b96e0e0008 |
43
.env.example
43
.env.example
@@ -1,43 +0,0 @@
|
|||||||
# Daily Journal Prompt Generator - Environment Variables
|
|
||||||
# Copy this file to .env and fill in your values
|
|
||||||
|
|
||||||
# API Keys (required - at least one)
|
|
||||||
DEEPSEEK_API_KEY=your_deepseek_api_key_here
|
|
||||||
OPENAI_API_KEY=your_openai_api_key_here
|
|
||||||
|
|
||||||
# API Configuration
|
|
||||||
API_BASE_URL=https://api.deepseek.com
|
|
||||||
MODEL=deepseek-chat
|
|
||||||
|
|
||||||
# Application Settings
|
|
||||||
DEBUG=false
|
|
||||||
ENVIRONMENT=development
|
|
||||||
NODE_ENV=development
|
|
||||||
|
|
||||||
# Server Settings
|
|
||||||
HOST=0.0.0.0
|
|
||||||
PORT=8000
|
|
||||||
|
|
||||||
# CORS Settings (comma-separated list)
|
|
||||||
BACKEND_CORS_ORIGINS=http://localhost:3000,http://localhost:80
|
|
||||||
|
|
||||||
# Prompt Settings
|
|
||||||
MIN_PROMPT_LENGTH=500
|
|
||||||
MAX_PROMPT_LENGTH=1000
|
|
||||||
NUM_PROMPTS_PER_SESSION=6
|
|
||||||
CACHED_POOL_VOLUME=20
|
|
||||||
HISTORY_BUFFER_SIZE=60
|
|
||||||
FEEDBACK_HISTORY_SIZE=30
|
|
||||||
|
|
||||||
# File Paths
|
|
||||||
DATA_DIR=data
|
|
||||||
PROMPT_TEMPLATE_PATH=data/ds_prompt.txt
|
|
||||||
FEEDBACK_TEMPLATE_PATH=data/ds_feedback.txt
|
|
||||||
SETTINGS_CONFIG_PATH=data/settings.cfg
|
|
||||||
|
|
||||||
# Data File Names
|
|
||||||
PROMPTS_HISTORIC_FILE=prompts_historic.json
|
|
||||||
PROMPTS_POOL_FILE=prompts_pool.json
|
|
||||||
FEEDBACK_WORDS_FILE=feedback_words.json
|
|
||||||
FEEDBACK_HISTORIC_FILE=feedback_historic.json
|
|
||||||
|
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,6 +1,4 @@
|
|||||||
.env
|
.env
|
||||||
venv
|
venv
|
||||||
__pycache__
|
__pycache__
|
||||||
#historic_prompts.json
|
journal_prompt_*
|
||||||
#pool_prompts.json
|
|
||||||
#feedback_words.json
|
|
||||||
|
|||||||
683
AGENTS.md
683
AGENTS.md
@@ -1,683 +0,0 @@
|
|||||||
# Daily Journal Prompt Generator - Webapp Refactoring Plan
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
Refactor the existing Python CLI application into a modern web application with FastAPI backend and a lightweight frontend. The system will maintain all existing functionality while providing a web-based interface for easier access and better user experience.
|
|
||||||
|
|
||||||
## Development Philosophy & Planning Directive
|
|
||||||
|
|
||||||
### Early Development Flexibility
|
|
||||||
**Critical Principle**: At this early stage of development, backwards compatibility in APIs and data structures is NOT necessary. The primary focus should be on creating a clean, maintainable architecture that serves the application's needs effectively.
|
|
||||||
|
|
||||||
### Data Structure Freedom
|
|
||||||
Two key areas currently affect core JSON data:
|
|
||||||
1. **Text prompts sent as requests** - Can be modified for better API design
|
|
||||||
2. **Data cleaning and processing of responses** - Can be optimized for frontend consumption
|
|
||||||
|
|
||||||
**Directive**: If the easiest path forward involves changing JSON data structures, feel free to do so. The priority is architectural cleanliness and development efficiency over preserving existing data formats.
|
|
||||||
|
|
||||||
### Implementation Priorities
|
|
||||||
1. **Functionality First**: Get core features working correctly
|
|
||||||
2. **Clean Architecture**: Design APIs and data structures that make sense for the web application
|
|
||||||
3. **Developer Experience**: Create intuitive APIs that are easy to work with
|
|
||||||
4. **Performance**: Optimize for the web context (async operations, efficient data transfer)
|
|
||||||
|
|
||||||
### Migration Strategy
|
|
||||||
When data structure changes are necessary:
|
|
||||||
1. Document the changes clearly
|
|
||||||
2. Update all affected components (backend services, API endpoints, frontend components)
|
|
||||||
3. Test thoroughly to ensure all functionality works with new structures
|
|
||||||
4. Consider simple migration scripts if needed, but don't over-engineer for compatibility
|
|
||||||
|
|
||||||
This directive empowers developers to make necessary architectural improvements without being constrained by early design decisions.
|
|
||||||
|
|
||||||
## Current Architecture Analysis
|
|
||||||
|
|
||||||
### Existing CLI Application
|
|
||||||
- **Language**: Python 3.7+
|
|
||||||
- **Core Dependencies**: openai, python-dotenv, rich
|
|
||||||
- **Data Storage**: JSON files (`prompts_historic.json`, `prompts_pool.json`)
|
|
||||||
- **Configuration**: `.env` file for API keys, `settings.cfg` for app settings
|
|
||||||
- **Functionality**:
|
|
||||||
1. AI-powered prompt generation using OpenAI-compatible APIs
|
|
||||||
2. Smart repetition avoidance with 60-prompt history buffer
|
|
||||||
3. Prompt pool system for offline usage
|
|
||||||
4. Interactive CLI with rich formatting
|
|
||||||
|
|
||||||
### Key Features to Preserve
|
|
||||||
1. AI prompt generation with history awareness
|
|
||||||
2. Prompt pool management (fill, draw, stats)
|
|
||||||
3. Configuration via environment variables
|
|
||||||
4. JSON-based data persistence
|
|
||||||
5. All existing prompt generation logic
|
|
||||||
As the user discards prompts, the themes will be very slowly steered, so it's okay to take some inspiration from the history.
|
|
||||||
|
|
||||||
## Proposed Web Application Architecture
|
|
||||||
|
|
||||||
### Backend: FastAPI
|
|
||||||
**Rationale**: FastAPI provides async capabilities, automatic OpenAPI documentation, and excellent performance. It's well-suited for AI API integrations.
|
|
||||||
|
|
||||||
**Components**:
|
|
||||||
1. **API Endpoints**:
|
|
||||||
- `GET /api/prompts/draw` - Draw prompts from pool
|
|
||||||
- `POST /api/prompts/fill-pool` - Fill prompt pool using AI
|
|
||||||
- `GET /api/prompts/stats` - Get pool and history statistics
|
|
||||||
- `GET /api/prompts/history` - Get prompt history
|
|
||||||
- `POST /api/prompts/select/{prompt_id}` - Select a prompt for journaling
|
|
||||||
|
|
||||||
2. **Core Services**:
|
|
||||||
- PromptGeneratorService (adapted from existing logic)
|
|
||||||
- PromptPoolService (manages pool operations)
|
|
||||||
- HistoryService (manages 60-item cyclic buffer)
|
|
||||||
- AIClientService (OpenAI API integration)
|
|
||||||
|
|
||||||
3. **Data Layer**:
|
|
||||||
- **Initial Approach**: Keep JSON file storage (`prompts_historic.json`, `prompts_pool.json`)
|
|
||||||
- **Docker Volume**: Mount `./data` directory to `/app/data` for persistent JSON storage
|
|
||||||
- **Future Evolution**: SQLite database migration path (optional later phase)
|
|
||||||
- **Rationale**: Maintains compatibility with existing CLI app, simple file-based persistence
|
|
||||||
|
|
||||||
4. **Configuration**:
|
|
||||||
- Environment variables (API keys, settings)
|
|
||||||
- Pydantic models for validation
|
|
||||||
- Settings management with python-dotenv
|
|
||||||
|
|
||||||
### Frontend Options Analysis
|
|
||||||
|
|
||||||
#### Option: Astro-erudite with React Components
|
|
||||||
**Decision**: Use astro-erudite (minimalist Astro flavor) with React components for interactive elements.
|
|
||||||
|
|
||||||
**Rationale**:
|
|
||||||
- **astro-erudite**: Minimalist flavor of Astro focused on simplicity and content-first approach
|
|
||||||
- **React Components**: Allows using React's rich component ecosystem for interactive elements
|
|
||||||
- **Best of Both Worlds**: Astro's performance with React's interactivity where needed
|
|
||||||
- **Future Flexibility**: Can add more React components as features expand
|
|
||||||
- **Minimalist Philosophy**: Aligns with the simple, focused nature of the prompt generator
|
|
||||||
|
|
||||||
**Architecture**:
|
|
||||||
- astro-erudite handles page routing and static content
|
|
||||||
- React components for interactive elements (prompt selection, admin controls)
|
|
||||||
- Partial hydration for optimal performance
|
|
||||||
- Minimal styling approach (Tailwind CSS optional, can use simple CSS)
|
|
||||||
|
|
||||||
**Frontend Components**:
|
|
||||||
1. **Prompt Display Component**: Shows multiple prompts with selection
|
|
||||||
2. **Stats Dashboard**: Shows pool/history statistics
|
|
||||||
3. **Admin Panel**: Controls for filling pool, viewing history
|
|
||||||
4. **Responsive Design**: Mobile-friendly interface
|
|
||||||
|
|
||||||
### Docker & Docker Compose Setup
|
|
||||||
|
|
||||||
#### Multi-container Architecture
|
|
||||||
```
|
|
||||||
services:
|
|
||||||
backend:
|
|
||||||
build: ./backend
|
|
||||||
ports:
|
|
||||||
- "8000:8000"
|
|
||||||
volumes:
|
|
||||||
- ./backend:/app
|
|
||||||
- ./data:/app/data # For JSON file persistence
|
|
||||||
environment:
|
|
||||||
- DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY}
|
|
||||||
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
|
||||||
develop:
|
|
||||||
watch:
|
|
||||||
- action: sync
|
|
||||||
path: ./backend
|
|
||||||
target: /app
|
|
||||||
- action: rebuild
|
|
||||||
path: ./backend/requirements.txt
|
|
||||||
|
|
||||||
frontend:
|
|
||||||
build: ./frontend
|
|
||||||
ports:
|
|
||||||
- "3000:3000" # Development
|
|
||||||
- "80:80" # Production
|
|
||||||
volumes:
|
|
||||||
- ./frontend:/app
|
|
||||||
develop:
|
|
||||||
watch:
|
|
||||||
- action: sync
|
|
||||||
path: ./frontend/src
|
|
||||||
target: /app/src
|
|
||||||
- action: rebuild
|
|
||||||
path: ./frontend/package.json
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Dockerfile Examples
|
|
||||||
|
|
||||||
**Backend Dockerfile**:
|
|
||||||
```dockerfile
|
|
||||||
FROM python:3.11-slim
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY requirements.txt .
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
||||||
```
|
|
||||||
|
|
||||||
**Frontend Dockerfile (Astro)**:
|
|
||||||
```dockerfile
|
|
||||||
FROM node:18-alpine AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY package*.json .
|
|
||||||
RUN npm ci
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
FROM nginx:alpine
|
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
|
||||||
EXPOSE 80
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Refactoring Strategy
|
|
||||||
|
|
||||||
### Phase 1: Backend API Development ✓ COMPLETED
|
|
||||||
1. **Setup FastAPI project structure** ✓
|
|
||||||
- Created `backend/` directory with proper structure
|
|
||||||
- Set up virtual environment and dependencies
|
|
||||||
- Created main FastAPI application with lifespan management
|
|
||||||
|
|
||||||
2. **Adapt existing Python logic** ✓
|
|
||||||
- Refactored `generate_prompts.py` into modular services:
|
|
||||||
- `DataService`: Handles JSON file operations with async support
|
|
||||||
- `AIService`: Manages OpenAI/DeepSeek API calls
|
|
||||||
- `PromptService`: Main orchestrator service
|
|
||||||
- Maintained all original functionality
|
|
||||||
|
|
||||||
3. **Create API endpoints** ✓
|
|
||||||
- Prompt operations: `/api/v1/prompts/draw`, `/api/v1/prompts/fill-pool`, `/api/v1/prompts/stats`
|
|
||||||
- History operations: `/api/v1/prompts/history/stats`, `/api/v1/prompts/history`
|
|
||||||
- Feedback operations: `/api/v1/feedback/generate`, `/api/v1/feedback/rate`
|
|
||||||
- Comprehensive error handling and validation
|
|
||||||
|
|
||||||
4. **Data persistence** ✓
|
|
||||||
- Kept JSON file storage for compatibility
|
|
||||||
- Created `data/` directory with all existing files
|
|
||||||
- Implemented async file operations with aiofiles
|
|
||||||
- Added file backup and recovery mechanisms
|
|
||||||
|
|
||||||
5. **Testing** ✓
|
|
||||||
- Created comprehensive test script `test_backend.py`
|
|
||||||
- Verified all imports, configuration, and API structure
|
|
||||||
- All tests passing successfully
|
|
||||||
|
|
||||||
### Phase 2: Frontend Development ✓ COMPLETED
|
|
||||||
1. **Setup Astro project** ✓
|
|
||||||
- Created `frontend/` directory with Astro + React setup
|
|
||||||
- Configured development server with API proxy
|
|
||||||
- Set up build configuration for production
|
|
||||||
|
|
||||||
2. **Build UI components** ✓
|
|
||||||
- Created responsive layout with modern design
|
|
||||||
- Built `PromptDisplay` React component with mock data
|
|
||||||
- Built `StatsDashboard` React component with live statistics
|
|
||||||
- Implemented interactive prompt selection
|
|
||||||
|
|
||||||
3. **API integration** ✓
|
|
||||||
- Configured proxy for backend API calls
|
|
||||||
- Set up mock data for demonstration
|
|
||||||
- Prepared components for real API integration
|
|
||||||
|
|
||||||
### Phase 3: Dockerization & Deployment ✓ COMPLETED
|
|
||||||
1. **Docker configuration** ✓
|
|
||||||
- Created `backend/Dockerfile` with Python 3.11-slim
|
|
||||||
- Created `frontend/Dockerfile` with multi-stage build
|
|
||||||
- Created `docker-compose.yml` with full stack orchestration
|
|
||||||
- Added nginx configuration for frontend serving
|
|
||||||
|
|
||||||
2. **Environment setup** ✓
|
|
||||||
- Created `.env.example` with all required variables
|
|
||||||
- Set up volume mounts for data persistence
|
|
||||||
- Configured health checks for both services
|
|
||||||
- Added development watch mode for hot reload
|
|
||||||
|
|
||||||
3. **Deployment preparation** ✓
|
|
||||||
- Created comprehensive `API_DOCUMENTATION.md`
|
|
||||||
- Updated `README.md` with webapp instructions
|
|
||||||
- Created `run_webapp.sh` helper script
|
|
||||||
- Added error handling and validation throughout
|
|
||||||
|
|
||||||
## Technical Decisions
|
|
||||||
|
|
||||||
### 1. Authentication (Optional)
|
|
||||||
**Current**: None (single-user CLI)
|
|
||||||
**Webapp Option**: Basic session-based auth or JWT
|
|
||||||
**Recommendation**: Start without auth, add later if needed for multi-user
|
|
||||||
|
|
||||||
### 2. Data Storage Evolution
|
|
||||||
**Phase 1**: JSON files (maintain compatibility) ✓
|
|
||||||
**Phase 2**: SQLite with migration script
|
|
||||||
**Phase 3**: Optional PostgreSQL for scalability
|
|
||||||
|
|
||||||
### 3. API Design Principles
|
|
||||||
- RESTful endpoints ✓
|
|
||||||
- JSON responses ✓
|
|
||||||
- Consistent error handling ✓
|
|
||||||
- OpenAPI documentation ✓
|
|
||||||
- Versioning (v1/ prefix) ✓
|
|
||||||
|
|
||||||
### 4. Frontend State Management
|
|
||||||
**Simple approach**: React-like state with Astro components ✓
|
|
||||||
**If complex**: Consider lightweight state management (Zustand, Jotai)
|
|
||||||
**Initial**: Component-level state sufficient ✓
|
|
||||||
|
|
||||||
## Development Workflow
|
|
||||||
|
|
||||||
### Local Development
|
|
||||||
```bash
|
|
||||||
# Clone and setup
|
|
||||||
git clone <repo>
|
|
||||||
cd daily-journal-prompt-webapp
|
|
||||||
|
|
||||||
# Start with Docker Compose
|
|
||||||
docker-compose up --build
|
|
||||||
|
|
||||||
# Or develop separately
|
|
||||||
cd backend && uvicorn main:app --reload
|
|
||||||
cd frontend && npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
### Testing Strategy
|
|
||||||
- **Backend**: pytest with FastAPI TestClient
|
|
||||||
- **Frontend**: Vitest for unit tests, Playwright for E2E
|
|
||||||
- **Integration**: Docker Compose test environment
|
|
||||||
|
|
||||||
### CI/CD Considerations
|
|
||||||
- GitHub Actions for testing
|
|
||||||
- Docker image building
|
|
||||||
- Deployment to cloud platform (Render, Railway, Fly.io)
|
|
||||||
|
|
||||||
## Risk Assessment & Mitigation
|
|
||||||
|
|
||||||
### Risks
|
|
||||||
1. **API Key exposure**: Use environment variables, never commit to repo ✓
|
|
||||||
2. **Data loss during migration**: Backup JSON files, incremental migration ✓
|
|
||||||
3. **Performance issues**: Monitor API response times, optimize database queries
|
|
||||||
4. **Browser compatibility**: Use modern CSS/JS, test on target browsers ✓
|
|
||||||
|
|
||||||
### Mitigations
|
|
||||||
- Comprehensive testing ✓
|
|
||||||
- Gradual rollout ✓
|
|
||||||
- Monitoring and logging
|
|
||||||
- Regular backups ✓
|
|
||||||
|
|
||||||
## Success Metrics
|
|
||||||
|
|
||||||
1. **Functionality**: All CLI features available in webapp ✓
|
|
||||||
2. **Performance**: API response < 200ms, page load < 2s
|
|
||||||
3. **Usability**: Intuitive UI, mobile-responsive ✓
|
|
||||||
4. **Reliability**: 99.9% uptime, error rate < 1%
|
|
||||||
5. **Maintainability**: Clean code, good test coverage, documented APIs ✓
|
|
||||||
|
|
||||||
## Next Steps
|
|
||||||
|
|
||||||
### Immediate Actions ✓ COMPLETED
|
|
||||||
1. Create project structure with backend/frontend directories ✓
|
|
||||||
2. Set up FastAPI backend skeleton ✓
|
|
||||||
3. Begin refactoring core prompt generation logic ✓
|
|
||||||
4. Create basic Astro frontend ✓
|
|
||||||
5. Implement Docker configuration ✓
|
|
||||||
|
|
||||||
### Future Enhancements
|
|
||||||
1. User accounts and prompt history per user
|
|
||||||
2. Prompt customization options
|
|
||||||
3. Export functionality (PDF, Markdown)
|
|
||||||
4. Mobile app (React Native)
|
|
||||||
5. Social features (share prompts, community)
|
|
||||||
|
|
||||||
## Conclusion
|
|
||||||
The refactoring from CLI to webapp will significantly improve accessibility and user experience while maintaining all existing functionality. The proposed architecture using FastAPI + Astro provides a modern, performant, and maintainable foundation for future enhancements.
|
|
||||||
|
|
||||||
The phased approach allows for incremental development with clear milestones and risk mitigation at each step.
|
|
||||||
|
|
||||||
## Phase 1 Implementation Summary
|
|
||||||
|
|
||||||
### What Was Accomplished
|
|
||||||
1. **Complete Backend API** with all original CLI functionality
|
|
||||||
2. **Modern Frontend** with responsive design and interactive components
|
|
||||||
3. **Docker Configuration** for easy deployment and development
|
|
||||||
4. **Comprehensive Documentation** including API docs and setup instructions
|
|
||||||
5. **Testing Infrastructure** to ensure reliability
|
|
||||||
|
|
||||||
### Key Technical Achievements
|
|
||||||
- **Modular Service Architecture**: Clean separation of concerns
|
|
||||||
- **Async Operations**: Full async/await support for better performance
|
|
||||||
- **Error Handling**: Comprehensive error handling with custom exceptions
|
|
||||||
- **Data Compatibility**: Full backward compatibility with existing CLI data
|
|
||||||
- **Development Experience**: Hot reload, health checks, and easy setup
|
|
||||||
|
|
||||||
### Ready for Use
|
|
||||||
The web application is now ready for:
|
|
||||||
- Local development with Docker or manual setup
|
|
||||||
- Testing with existing prompt data
|
|
||||||
- Deployment to cloud platforms
|
|
||||||
- Further feature development
|
|
||||||
|
|
||||||
### Files Created/Modified
|
|
||||||
```
|
|
||||||
Created:
|
|
||||||
- backend/ (complete FastAPI application)
|
|
||||||
- frontend/ (complete Astro + React application)
|
|
||||||
- data/ (data directory with all existing files)
|
|
||||||
- docker-compose.yml
|
|
||||||
- .env.example
|
|
||||||
- API_DOCUMENTATION.md
|
|
||||||
- test_backend.py
|
|
||||||
- run_webapp.sh
|
|
||||||
|
|
||||||
Updated:
|
|
||||||
- README.md (webapp documentation)
|
|
||||||
- AGENTS.md (this file, with completion status)
|
|
||||||
```
|
|
||||||
|
|
||||||
The Phase 1 implementation successfully transforms the CLI tool into a modern web application while preserving all existing functionality and data compatibility.
|
|
||||||
|
|
||||||
## Docker Build Issue Resolution
|
|
||||||
|
|
||||||
**Problem**: The original Docker build was failing with the error:
|
|
||||||
```
|
|
||||||
npm error The `npm ci` command can only install with an existing package-lock.json or
|
|
||||||
npm error npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or
|
|
||||||
npm error later to generate a package-lock.json file, then try again.
|
|
||||||
```
|
|
||||||
|
|
||||||
**Solution**: Updated the frontend Dockerfile to use `npm install` instead of `npm ci` since no package-lock.json file exists yet. The updated Dockerfile now works correctly:
|
|
||||||
|
|
||||||
```dockerfile
|
|
||||||
# Install dependencies
|
|
||||||
# Use npm install for development (npm ci requires package-lock.json)
|
|
||||||
RUN npm install
|
|
||||||
```
|
|
||||||
|
|
||||||
**Verification**: Docker build now completes successfully and the frontend container can be built and run without errors.
|
|
||||||
|
|
||||||
## Docker Permission Error Resolution
|
|
||||||
|
|
||||||
**Problem**: The backend container was failing with the error:
|
|
||||||
```
|
|
||||||
PermissionError: [Errno 13] Permission denied: '/data'
|
|
||||||
```
|
|
||||||
|
|
||||||
**Root Cause**: The issue was in `backend/main.py` where the data directory path was incorrectly calculated:
|
|
||||||
```python
|
|
||||||
# Incorrect calculation
|
|
||||||
data_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data")
|
|
||||||
# This resulted in '/data' instead of '/app/data'
|
|
||||||
```
|
|
||||||
|
|
||||||
**Solution**: Fixed the path calculation to use the configuration-based approach:
|
|
||||||
```python
|
|
||||||
# Correct calculation using settings
|
|
||||||
from pathlib import Path
|
|
||||||
from app.core.config import settings
|
|
||||||
data_dir = Path(settings.DATA_DIR) # 'data' -> resolves to '/app/data' in container
|
|
||||||
data_dir.mkdir(exist_ok=True)
|
|
||||||
```
|
|
||||||
|
|
||||||
**Additional Considerations**:
|
|
||||||
1. **User Permissions**: The Dockerfile creates a non-root user `appuser` with UID 1000, which matches the typical host user UID for better volume permission compatibility.
|
|
||||||
2. **Volume Mount**: The docker-compose.yml mounts `./data:/app/data` ensuring data persistence.
|
|
||||||
3. **Directory Permissions**: The host `data/` directory has permissions `700` (owner only), but since the container user has the same UID (1000), it can access the directory.
|
|
||||||
|
|
||||||
**Verification**:
|
|
||||||
- Docker builds complete successfully for both backend and frontend
|
|
||||||
- Backend container starts without permission errors
|
|
||||||
- API endpoints respond correctly
|
|
||||||
- Health check endpoint returns `{"status": "healthy"}`
|
|
||||||
- FastAPI documentation endpoints (`/docs` and `/redoc`) are now always enabled
|
|
||||||
|
|
||||||
## FastAPI Documentation Endpoints Fix
|
|
||||||
|
|
||||||
**Problem**: FastAPI's built-in documentation endpoints (`/docs` and `/redoc`) were not working because they were only enabled when `DEBUG=true`.
|
|
||||||
|
|
||||||
**Root Cause**: In `backend/main.py`, the documentation endpoints were conditionally enabled:
|
|
||||||
```python
|
|
||||||
docs_url="/docs" if settings.DEBUG else None,
|
|
||||||
redoc_url="/redoc" if settings.DEBUG else None,
|
|
||||||
```
|
|
||||||
|
|
||||||
**Solution**: Removed the conditional logic to always enable documentation endpoints:
|
|
||||||
```python
|
|
||||||
docs_url="/docs",
|
|
||||||
redoc_url="/redoc",
|
|
||||||
```
|
|
||||||
|
|
||||||
**Verification**:
|
|
||||||
- `/docs` endpoint returns HTTP 200 with Swagger UI
|
|
||||||
- `/redoc` endpoint returns HTTP 200 with ReDoc documentation
|
|
||||||
- `/openapi.json` provides the OpenAPI schema
|
|
||||||
- Root endpoint correctly lists documentation URLs
|
|
||||||
|
|
||||||
## Frontend Improvements Completed
|
|
||||||
|
|
||||||
### Task 1: Fixed UI elements that shift on mouseover
|
|
||||||
**Problem**: Buttons and cards had `transform: translateY()` on hover, causing layout shifts and bad design.
|
|
||||||
|
|
||||||
**Solution**: Removed translate effects and replaced with more subtle hover effects:
|
|
||||||
- Buttons: Changed from `transform: translateY(-2px)` to `opacity: 0.95` with enhanced shadow
|
|
||||||
- Cards: Removed `transform: translateY(-4px)`, kept shadow enhancement only
|
|
||||||
|
|
||||||
**Result**: Clean, stable UI without distracting layout shifts.
|
|
||||||
|
|
||||||
### Task 2: Default page shows most recent prompt from history
|
|
||||||
**Problem**: Default page was drawing from pool and showing 6 prompts.
|
|
||||||
|
|
||||||
**Solution**:
|
|
||||||
1. Modified `PromptDisplay` component to fetch most recent prompt from history API
|
|
||||||
2. Changed to show only one prompt (most recent from history)
|
|
||||||
3. Added clear indication that this is the "Most Recent Prompt"
|
|
||||||
4. Integrated pool fullness indicator from `StatsDashboard`
|
|
||||||
|
|
||||||
**Result**: Default page now shows single most recent prompt with clear context and pool status.
|
|
||||||
|
|
||||||
### Task 3: UI buttons have working functionality
|
|
||||||
**Problem**: Buttons were using mock data without real API integration.
|
|
||||||
|
|
||||||
**Solution**:
|
|
||||||
1. **Fill Pool button**: Now calls `/api/v1/prompts/fill-pool` API endpoint
|
|
||||||
2. **Draw Prompts button**: Now calls `/api/v1/prompts/draw?count=3` API endpoint
|
|
||||||
3. **Use This Prompt button**: Marks prompt as used (simulated for now, ready for API integration)
|
|
||||||
4. **Stats Dashboard**: Now fetches real data from `/api/v1/prompts/stats` and `/api/v1/prompts/history/stats`
|
|
||||||
|
|
||||||
**Result**: All UI buttons now have functional API integration.
|
|
||||||
|
|
||||||
### Task 4: Changed default number drawn from pool to 3
|
|
||||||
**Problem**: Default was 6 prompts per session.
|
|
||||||
|
|
||||||
**Solution**:
|
|
||||||
1. Updated backend config: `NUM_PROMPTS_PER_SESSION: int = 3` (was 6)
|
|
||||||
2. Updated frontend to request 3 prompts when drawing
|
|
||||||
3. Verified `settings.cfg` already had `num_prompts = 3`
|
|
||||||
4. Updated UI labels from "Draw 6 Prompts" to "Draw 3 Prompts"
|
|
||||||
|
|
||||||
**Result**: System now draws 3 prompts by default, matching user preference.
|
|
||||||
|
|
||||||
### Summary of Frontend Changes
|
|
||||||
- ✅ Fixed hover animations causing layout shifts
|
|
||||||
- ✅ Default page shows single most recent prompt from history
|
|
||||||
- ✅ Pool fullness indicator integrated on main page
|
|
||||||
- ✅ All buttons have working API functionality
|
|
||||||
- ✅ Default draw count changed from 6 to 3
|
|
||||||
- ✅ Improved user experience with clearer prompts and status indicators
|
|
||||||
|
|
||||||
## Additional Frontend Issues Fixed
|
|
||||||
|
|
||||||
### Phase 1: Home page shows lowest position prompt from history
|
|
||||||
**Problem**: The home page claimed there were no prompts in history, but the API showed a completely full history.
|
|
||||||
|
|
||||||
**Root Cause**: The `PromptDisplay` component was incorrectly parsing the API response. The history API returns an array of prompt objects directly, but the component was looking for `data.prompts[0].prompt`.
|
|
||||||
|
|
||||||
**Solution**: Fixed the API response parsing to correctly handle the array structure:
|
|
||||||
- History API returns: `[{key: "...", text: "...", position: 0}, ...]`
|
|
||||||
- Component now correctly extracts: `data[0].text` for the most recent prompt
|
|
||||||
- Added proper error handling and fallback logic
|
|
||||||
|
|
||||||
**Verification**:
|
|
||||||
- History API returns 60 prompts (full history)
|
|
||||||
- Home page now shows the most recent prompt (position 0) from history
|
|
||||||
- No more "no prompts" message when history is full
|
|
||||||
|
|
||||||
### Phase 2: Clicking "Draw 3 new prompts" shows 3 prompts
|
|
||||||
**Problem**: Clicking "Draw 3 new prompts" only showed 1 prompt instead of 3.
|
|
||||||
|
|
||||||
**Root Cause**: The component was only displaying the first prompt from the drawn set (`data.prompts[0]`).
|
|
||||||
|
|
||||||
**Solution**: Modified the component to handle multiple prompts:
|
|
||||||
- When drawing from pool, show all drawn prompts (up to 3)
|
|
||||||
- Added `viewMode` state to track whether showing history or drawn prompts
|
|
||||||
- Updated UI to show appropriate labels and behavior for each mode
|
|
||||||
|
|
||||||
**Verification**:
|
|
||||||
- Draw API correctly returns 3 prompts when `count=3`
|
|
||||||
- Frontend now displays all 3 drawn prompts
|
|
||||||
- Users can select any of the drawn prompts to add to history
|
|
||||||
|
|
||||||
### Summary of Additional Fixes
|
|
||||||
- ✅ Fixed API response parsing for history endpoint
|
|
||||||
- ✅ Home page now correctly shows prompts from full history
|
|
||||||
- ✅ "Draw 3 new prompts" now shows all 3 drawn prompts
|
|
||||||
- ✅ Improved user experience with proper prompt selection
|
|
||||||
- ✅ Added visual distinction between history and drawn prompts
|
|
||||||
|
|
||||||
## Frontend Tasks Completed
|
|
||||||
|
|
||||||
### Task 1: Fixed duplicate buttons on main page ✓
|
|
||||||
**Problem**: There were two sets of buttons on the main page for getting new prompts - one set in the main card header and another in the "Quick Actions" card. Both sets were triggering the same functionality, creating redundancy.
|
|
||||||
|
|
||||||
**Solution**:
|
|
||||||
1. Removed the duplicate buttons from the main card header, keeping only the buttons in the "Quick Actions" card
|
|
||||||
2. Updated the "Quick Actions" buttons to properly trigger the React component functions via JavaScript
|
|
||||||
3. Simplified the UI to have only one working set of buttons for each action
|
|
||||||
|
|
||||||
**Result**: Cleaner interface with no redundant buttons. Users now have:
|
|
||||||
- One "Draw 3 Prompts" button that calls the PromptDisplay component's `handleDrawPrompts` function
|
|
||||||
- One "Fill Pool" button that calls the StatsDashboard component's `handleFillPool` function
|
|
||||||
- One "View History (API)" button that links directly to the API endpoint
|
|
||||||
|
|
||||||
### Task 2: Fixed disabled 'Add to History' button ✓
|
|
||||||
**Problem**: The "Add to History" button was incorrectly disabled when a prompt was selected. The logic was backwards: `disabled={selectedIndex !== null}` meant the button was disabled when a prompt WAS selected, not when NO prompt was selected.
|
|
||||||
|
|
||||||
**Solution**:
|
|
||||||
1. Fixed the disabled logic to `disabled={selectedIndex === null}` (disabled when no prompt is selected)
|
|
||||||
2. Updated button text to show "Select a Prompt First" when disabled and "Use Selected Prompt" when enabled
|
|
||||||
3. Improved user feedback with clearer button states
|
|
||||||
|
|
||||||
**Result**:
|
|
||||||
- Button is now properly enabled when a prompt is selected
|
|
||||||
- Clear visual feedback for users about selection state
|
|
||||||
- Intuitive workflow: select prompt → button enables → click to add to history
|
|
||||||
|
|
||||||
### Additional Improvements
|
|
||||||
- **Button labels**: Updated from "Draw 6 Prompts" to "Draw 3 Prompts" to match the new default
|
|
||||||
- **API integration**: All buttons now properly call backend API endpoints
|
|
||||||
- **Error handling**: Added better error messages and fallback behavior
|
|
||||||
- **UI consistency**: Removed layout-shifting hover effects for cleaner interface
|
|
||||||
|
|
||||||
### Verification
|
|
||||||
- ✅ Docker containers running successfully (backend, frontend, frontend-dev)
|
|
||||||
- ✅ All API endpoints responding correctly
|
|
||||||
- ✅ Frontend accessible at http://localhost:3000
|
|
||||||
- ✅ Backend documentation available at http://localhost:8000/docs
|
|
||||||
- ✅ History shows 60 prompts (full capacity)
|
|
||||||
- ✅ Draw endpoint returns 3 prompts as configured
|
|
||||||
- ✅ Fill pool endpoint successfully adds prompts to pool
|
|
||||||
- ✅ Button states work correctly (enabled/disabled based on selection)
|
|
||||||
|
|
||||||
The web application is now fully functional with a clean, intuitive interface that maintains all original CLI functionality while providing a modern web experience.
|
|
||||||
|
|
||||||
## Build Error Fixed ✓
|
|
||||||
|
|
||||||
**Problem**: There was a npm build error with syntax problem in `PromptDisplay.jsx`:
|
|
||||||
```
|
|
||||||
Expected "{" but found "\\"
|
|
||||||
Location: /app/src/components/PromptDisplay.jsx:184:29
|
|
||||||
```
|
|
||||||
|
|
||||||
**Root Cause**: Incorrectly escaped quotes in JSX syntax:
|
|
||||||
- `className=\\\"fas fa-history\\\"` (triple escaped quotes)
|
|
||||||
- Should be: `className="fas fa-history"`
|
|
||||||
|
|
||||||
**Solution**: Fixed the syntax error by removing the escaped quotes:
|
|
||||||
- Changed `className=\\\"fas fa-history\\\"` to `className="fas fa-history"`
|
|
||||||
- Verified no other similar issues in the file
|
|
||||||
|
|
||||||
**Verification**:
|
|
||||||
- ✅ Docker build now completes successfully
|
|
||||||
- ✅ Frontend container starts without errors
|
|
||||||
- ✅ Frontend accessible at http://localhost:3000
|
|
||||||
- ✅ All API endpoints working correctly
|
|
||||||
- ✅ No more syntax errors in build process
|
|
||||||
|
|
||||||
**Note on Container Startup Times**: For containerized development on consumer hardware, allow at least 8 seconds for containers to fully initialize before testing endpoints. This accounts for:
|
|
||||||
1. Container process startup (2-3 seconds)
|
|
||||||
2. Application initialization (2-3 seconds)
|
|
||||||
3. Network connectivity establishment (2-3 seconds)
|
|
||||||
4. Health check completion (1-2 seconds)
|
|
||||||
|
|
||||||
Use `sleep 8` in testing scripts to ensure reliable results.
|
|
||||||
|
|
||||||
## Frontend Bug Fix: "Add to History" Functionality ✓
|
|
||||||
|
|
||||||
### Problem Identified
|
|
||||||
1. **Prompt not actually added to history**: When clicking "Use Selected Prompt", a browser alert was shown but the prompt was not actually added to the history cyclic buffer
|
|
||||||
2. **Missing API integration**: The frontend was not calling any backend API to add prompts to history
|
|
||||||
3. **No visual feedback**: After adding a prompt, the page didn't refresh to show the updated history
|
|
||||||
|
|
||||||
### Solution Implemented
|
|
||||||
|
|
||||||
#### Backend Changes
|
|
||||||
1. **Updated `/api/v1/prompts/select` endpoint**:
|
|
||||||
- Changed from `/select/{prompt_index}` to `/select` with request body
|
|
||||||
- Added `SelectPromptRequest` model: `{"prompt_text": "..."}`
|
|
||||||
- Implemented actual history addition using `PromptService.add_prompt_to_history()`
|
|
||||||
- Returns position in history (e.g., "prompt00") and updated history size
|
|
||||||
|
|
||||||
2. **PromptService enhancement**:
|
|
||||||
- `add_prompt_to_history()` method now properly adds prompts to the cyclic buffer
|
|
||||||
- Prompts are added at position 0 (most recent), shifting existing prompts down
|
|
||||||
- Maintains history buffer size of 60 prompts
|
|
||||||
|
|
||||||
#### Frontend Changes
|
|
||||||
1. **Updated `handleAddToHistory` function**:
|
|
||||||
- Now sends actual prompt text to `/api/v1/prompts/select` endpoint
|
|
||||||
- Proper error handling for API failures
|
|
||||||
- Shows success message with position in history
|
|
||||||
|
|
||||||
2. **Improved user feedback**:
|
|
||||||
- After successful addition, refreshes the prompt display to show updated history
|
|
||||||
- The default view shows the most recent prompt from history (position 0)
|
|
||||||
- Clear error messages if API call fails
|
|
||||||
|
|
||||||
### Verification
|
|
||||||
- ✅ Backend endpoint responds correctly: `POST /api/v1/prompts/select`
|
|
||||||
- ✅ Prompts are added to history at position 0 (most recent)
|
|
||||||
- ✅ History cyclic buffer maintains 60-prompt limit
|
|
||||||
- ✅ Frontend properly refreshes to show updated history
|
|
||||||
- ✅ Error handling for all failure scenarios
|
|
||||||
|
|
||||||
### Example API Call
|
|
||||||
```bash
|
|
||||||
curl -X POST "http://localhost:8000/api/v1/prompts/select" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"prompt_text": "Your prompt text here"}'
|
|
||||||
```
|
|
||||||
|
|
||||||
### Response
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"selected_prompt": "Your prompt text here",
|
|
||||||
"position_in_history": "prompt00",
|
|
||||||
"history_size": 60
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The "Add to History" functionality is now fully operational. When users draw prompts from the pool, select one, and click "Use Selected Prompt", the prompt is actually added to the history cyclic buffer, and the page refreshes to show the updated most recent prompt.
|
|
||||||
@@ -1,375 +0,0 @@
|
|||||||
# Daily Journal Prompt Generator - API Documentation
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
The Daily Journal Prompt Generator API provides endpoints for generating, managing, and interacting with AI-powered journal writing prompts. The API is built with FastAPI and provides automatic OpenAPI documentation.
|
|
||||||
|
|
||||||
## Base URL
|
|
||||||
|
|
||||||
- Development: `http://localhost:8000`
|
|
||||||
- Production: `https://your-domain.com`
|
|
||||||
|
|
||||||
## API Version
|
|
||||||
|
|
||||||
All endpoints are prefixed with `/api/v1`
|
|
||||||
|
|
||||||
## Authentication
|
|
||||||
|
|
||||||
Currently, the API does not require authentication as it's designed for single-user use. Future versions may add authentication for multi-user support.
|
|
||||||
|
|
||||||
## Error Handling
|
|
||||||
|
|
||||||
All endpoints return appropriate HTTP status codes:
|
|
||||||
|
|
||||||
- `200`: Success
|
|
||||||
- `400`: Bad Request (validation errors)
|
|
||||||
- `404`: Resource Not Found
|
|
||||||
- `422`: Unprocessable Entity (request validation failed)
|
|
||||||
- `500`: Internal Server Error
|
|
||||||
|
|
||||||
Error responses follow this format:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"error": {
|
|
||||||
"type": "ErrorType",
|
|
||||||
"message": "Human-readable error message",
|
|
||||||
"details": {}, // Optional additional details
|
|
||||||
"status_code": 400
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Endpoints
|
|
||||||
|
|
||||||
### Prompt Operations
|
|
||||||
|
|
||||||
#### 1. Draw Prompts from Pool
|
|
||||||
**GET** `/api/v1/prompts/draw`
|
|
||||||
|
|
||||||
Draw prompts from the existing pool without making API calls.
|
|
||||||
|
|
||||||
**Query Parameters:**
|
|
||||||
- `count` (optional, integer): Number of prompts to draw (default: 6)
|
|
||||||
|
|
||||||
**Response:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"prompts": [
|
|
||||||
"Write about a time when...",
|
|
||||||
"Imagine you could..."
|
|
||||||
],
|
|
||||||
"count": 2,
|
|
||||||
"remaining_in_pool": 18
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 2. Fill Prompt Pool
|
|
||||||
**POST** `/api/v1/prompts/fill-pool`
|
|
||||||
|
|
||||||
Fill the prompt pool to target volume using AI.
|
|
||||||
|
|
||||||
**Response:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"added": 5,
|
|
||||||
"total_in_pool": 20,
|
|
||||||
"target_volume": 20
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 3. Get Pool Statistics
|
|
||||||
**GET** `/api/v1/prompts/stats`
|
|
||||||
|
|
||||||
Get statistics about the prompt pool.
|
|
||||||
|
|
||||||
**Response:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"total_prompts": 15,
|
|
||||||
"prompts_per_session": 6,
|
|
||||||
"target_pool_size": 20,
|
|
||||||
"available_sessions": 2,
|
|
||||||
"needs_refill": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 4. Get History Statistics
|
|
||||||
**GET** `/api/v1/prompts/history/stats`
|
|
||||||
|
|
||||||
Get statistics about prompt history.
|
|
||||||
|
|
||||||
**Response:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"total_prompts": 8,
|
|
||||||
"history_capacity": 60,
|
|
||||||
"available_slots": 52,
|
|
||||||
"is_full": false
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 5. Get Prompt History
|
|
||||||
**GET** `/api/v1/prompts/history`
|
|
||||||
|
|
||||||
Get prompt history with optional limit.
|
|
||||||
|
|
||||||
**Query Parameters:**
|
|
||||||
- `limit` (optional, integer): Maximum number of history items to return
|
|
||||||
|
|
||||||
**Response:**
|
|
||||||
```json
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"key": "prompt00",
|
|
||||||
"text": "Most recent prompt text...",
|
|
||||||
"position": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "prompt01",
|
|
||||||
"text": "Previous prompt text...",
|
|
||||||
"position": 1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 6. Select Prompt (Add to History)
|
|
||||||
**POST** `/api/v1/prompts/select/{prompt_index}`
|
|
||||||
|
|
||||||
Select a prompt from drawn prompts to add to history.
|
|
||||||
|
|
||||||
**Path Parameters:**
|
|
||||||
- `prompt_index` (integer): Index of the prompt to select (0-based)
|
|
||||||
|
|
||||||
**Note:** This endpoint requires session management and is not fully implemented in the initial version.
|
|
||||||
|
|
||||||
### Feedback Operations
|
|
||||||
|
|
||||||
#### 7. Generate Theme Feedback Words
|
|
||||||
**GET** `/api/v1/feedback/generate`
|
|
||||||
|
|
||||||
Generate 6 theme feedback words using AI based on historic prompts.
|
|
||||||
|
|
||||||
**Response:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"theme_words": ["creativity", "reflection", "growth", "memory", "imagination", "emotion"],
|
|
||||||
"count": 6
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 8. Rate Feedback Words
|
|
||||||
**POST** `/api/v1/feedback/rate`
|
|
||||||
|
|
||||||
Rate feedback words and update feedback system.
|
|
||||||
|
|
||||||
**Request Body:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"ratings": {
|
|
||||||
"creativity": 5,
|
|
||||||
"reflection": 6,
|
|
||||||
"growth": 4,
|
|
||||||
"memory": 3,
|
|
||||||
"imagination": 5,
|
|
||||||
"emotion": 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Response:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"feedback_words": [
|
|
||||||
{
|
|
||||||
"key": "feedback00",
|
|
||||||
"word": "creativity",
|
|
||||||
"weight": 5
|
|
||||||
},
|
|
||||||
// ... 5 more items
|
|
||||||
],
|
|
||||||
"added_to_history": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 9. Get Current Feedback Words
|
|
||||||
**GET** `/api/v1/feedback/current`
|
|
||||||
|
|
||||||
Get current feedback words with weights.
|
|
||||||
|
|
||||||
**Response:**
|
|
||||||
```json
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"key": "feedback00",
|
|
||||||
"word": "creativity",
|
|
||||||
"weight": 5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 10. Get Feedback History
|
|
||||||
**GET** `/api/v1/feedback/history`
|
|
||||||
|
|
||||||
Get feedback word history.
|
|
||||||
|
|
||||||
**Response:**
|
|
||||||
```json
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"key": "feedback00",
|
|
||||||
"word": "creativity"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Data Models
|
|
||||||
|
|
||||||
### PromptResponse
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"key": "string", // e.g., "prompt00"
|
|
||||||
"text": "string", // Prompt text content
|
|
||||||
"position": "integer" // Position in history (0 = most recent)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### PoolStatsResponse
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"total_prompts": "integer",
|
|
||||||
"prompts_per_session": "integer",
|
|
||||||
"target_pool_size": "integer",
|
|
||||||
"available_sessions": "integer",
|
|
||||||
"needs_refill": "boolean"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### HistoryStatsResponse
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"total_prompts": "integer",
|
|
||||||
"history_capacity": "integer",
|
|
||||||
"available_slots": "integer",
|
|
||||||
"is_full": "boolean"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### FeedbackWord
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"key": "string", // e.g., "feedback00"
|
|
||||||
"word": "string", // Feedback word
|
|
||||||
"weight": "integer" // Weight from 0-6
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
### Environment Variables
|
|
||||||
|
|
||||||
| Variable | Description | Default |
|
|
||||||
|----------|-------------|---------|
|
|
||||||
| `DEEPSEEK_API_KEY` | DeepSeek API key | (required) |
|
|
||||||
| `OPENAI_API_KEY` | OpenAI API key | (optional) |
|
|
||||||
| `API_BASE_URL` | API base URL | `https://api.deepseek.com` |
|
|
||||||
| `MODEL` | AI model to use | `deepseek-chat` |
|
|
||||||
| `DEBUG` | Debug mode | `false` |
|
|
||||||
| `ENVIRONMENT` | Environment | `development` |
|
|
||||||
| `HOST` | Server host | `0.0.0.0` |
|
|
||||||
| `PORT` | Server port | `8000` |
|
|
||||||
| `MIN_PROMPT_LENGTH` | Minimum prompt length | `500` |
|
|
||||||
| `MAX_PROMPT_LENGTH` | Maximum prompt length | `1000` |
|
|
||||||
| `NUM_PROMPTS_PER_SESSION` | Prompts per session | `6` |
|
|
||||||
| `CACHED_POOL_VOLUME` | Target pool size | `20` |
|
|
||||||
| `HISTORY_BUFFER_SIZE` | History capacity | `60` |
|
|
||||||
| `FEEDBACK_HISTORY_SIZE` | Feedback history capacity | `30` |
|
|
||||||
|
|
||||||
### File Structure
|
|
||||||
|
|
||||||
```
|
|
||||||
data/
|
|
||||||
├── prompts_historic.json # Historic prompts (cyclic buffer)
|
|
||||||
├── prompts_pool.json # Prompt pool
|
|
||||||
├── feedback_words.json # Current feedback words with weights
|
|
||||||
├── feedback_historic.json # Historic feedback words
|
|
||||||
├── ds_prompt.txt # Prompt generation template
|
|
||||||
├── ds_feedback.txt # Feedback analysis template
|
|
||||||
└── settings.cfg # Application settings
|
|
||||||
```
|
|
||||||
|
|
||||||
## Running the API
|
|
||||||
|
|
||||||
### Development
|
|
||||||
```bash
|
|
||||||
cd backend
|
|
||||||
uvicorn main:app --reload
|
|
||||||
```
|
|
||||||
|
|
||||||
### Production
|
|
||||||
```bash
|
|
||||||
cd backend
|
|
||||||
uvicorn main:app --host 0.0.0.0 --port 8000
|
|
||||||
```
|
|
||||||
|
|
||||||
### Docker
|
|
||||||
```bash
|
|
||||||
docker-compose up --build
|
|
||||||
```
|
|
||||||
|
|
||||||
## Interactive Documentation
|
|
||||||
|
|
||||||
FastAPI provides automatic interactive documentation:
|
|
||||||
|
|
||||||
- Swagger UI: `http://localhost:8000/docs`
|
|
||||||
- ReDoc: `http://localhost:8000/redoc`
|
|
||||||
|
|
||||||
## Rate Limiting
|
|
||||||
|
|
||||||
Currently, the API does not implement rate limiting. Consider implementing rate limiting in production if needed.
|
|
||||||
|
|
||||||
## CORS
|
|
||||||
|
|
||||||
CORS is configured to allow requests from:
|
|
||||||
- `http://localhost:3000` (frontend dev server)
|
|
||||||
- `http://localhost:80` (frontend production)
|
|
||||||
|
|
||||||
Additional origins can be configured via the `BACKEND_CORS_ORIGINS` environment variable.
|
|
||||||
|
|
||||||
## Health Check
|
|
||||||
|
|
||||||
**GET** `/health`
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"status": "healthy",
|
|
||||||
"service": "daily-journal-prompt-api"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Root Endpoint
|
|
||||||
|
|
||||||
**GET** `/`
|
|
||||||
|
|
||||||
Returns API information:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"name": "Daily Journal Prompt Generator API",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "API for generating and managing journal writing prompts",
|
|
||||||
"docs": "/docs",
|
|
||||||
"health": "/health"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Future Enhancements
|
|
||||||
|
|
||||||
1. **Authentication**: Add JWT or session-based authentication
|
|
||||||
2. **Rate Limiting**: Implement request rate limiting
|
|
||||||
3. **WebSocket Support**: Real-time prompt generation updates
|
|
||||||
4. **Export Functionality**: Export prompts to PDF/Markdown
|
|
||||||
5. **Prompt Customization**: User-defined prompt templates
|
|
||||||
6. **Multi-language Support**: Generate prompts in different languages
|
|
||||||
7. **Analytics**: Track prompt usage and user engagement
|
|
||||||
8. **Social Features**: Share prompts, community prompts
|
|
||||||
|
|
||||||
507
README.md
507
README.md
@@ -1,363 +1,262 @@
|
|||||||
# Daily Journal Prompt Generator - Web Application
|
# Daily Journal Prompt Generator
|
||||||
|
|
||||||
A modern web application for generating AI-powered journal writing prompts, refactored from a CLI tool to a full web stack with FastAPI backend and Astro frontend.
|
A Python tool that uses OpenAI-compatible AI endpoints to generate creative writing prompts for daily journaling. The tool maintains awareness of previous prompts to minimize repetition while providing diverse, thought-provoking topics for journal writing.
|
||||||
|
|
||||||
## ✨ Features
|
## ✨ Features
|
||||||
|
|
||||||
- **AI-Powered Prompt Generation**: Uses DeepSeek/OpenAI API to generate creative writing prompts
|
- **AI-Powered Prompt Generation**: Uses OpenAI-compatible APIs to generate creative writing prompts
|
||||||
- **Smart History System**: 60-prompt cyclic buffer to avoid repetition and steer themes
|
- **Smart Repetition Avoidance**: Maintains history of the last 60 prompts to minimize thematic overlap
|
||||||
- **Prompt Pool Management**: Caches prompts for offline use with automatic refilling
|
- **Multiple Options**: Generates 6 different prompt options for each session
|
||||||
- **Theme Feedback System**: AI analyzes your preferences to improve future prompts
|
- **Diverse Topics**: Covers a wide range of themes including memories, creativity, self-reflection, and imagination
|
||||||
- **Modern Web Interface**: Responsive design with intuitive UI
|
- **Simple Configuration**: Easy setup with environment variables for API keys
|
||||||
- **RESTful API**: Fully documented API for programmatic access
|
- **JSON-Based History**: Stores prompt history in a structured JSON format for easy management
|
||||||
- **Docker Support**: Easy deployment with Docker and Docker Compose
|
|
||||||
|
|
||||||
## 🏗️ Architecture
|
## 📋 Prerequisites
|
||||||
|
|
||||||
### Backend (FastAPI)
|
- Python 3.7+
|
||||||
- **Framework**: FastAPI with async/await support
|
- An API key from an OpenAI-compatible service (DeepSeek, OpenAI, etc.)
|
||||||
- **API Documentation**: Automatic OpenAPI/Swagger documentation
|
- Basic knowledge of Python and command line usage
|
||||||
- **Data Persistence**: JSON file storage with async file operations
|
|
||||||
- **Services**: Modular architecture with clear separation of concerns
|
|
||||||
- **Validation**: Pydantic models for request/response validation
|
|
||||||
- **Error Handling**: Comprehensive error handling with custom exceptions
|
|
||||||
|
|
||||||
### Frontend (Astro + React)
|
## 🚀 Installation & Setup
|
||||||
- **Framework**: Astro with React components for interactivity
|
|
||||||
- **Styling**: Custom CSS with modern design system
|
|
||||||
- **Responsive Design**: Mobile-first responsive layout
|
|
||||||
- **API Integration**: Proxy configuration for seamless backend communication
|
|
||||||
- **Component Architecture**: Reusable React components
|
|
||||||
|
|
||||||
### Infrastructure
|
1. **Clone the repository**:
|
||||||
- **Docker**: Multi-container setup with development and production configurations
|
```bash
|
||||||
- **Docker Compose**: Orchestration for local development
|
git clone <repository-url>
|
||||||
- **Nginx**: Reverse proxy for frontend serving
|
cd daily-journal-prompt
|
||||||
- **Health Checks**: Container health monitoring
|
```
|
||||||
|
|
||||||
|
2. **Set up a Python virtual environment (recommended)**:
|
||||||
|
```bash
|
||||||
|
# Create a virtual environment
|
||||||
|
python -m venv venv
|
||||||
|
|
||||||
|
# Activate the virtual environment
|
||||||
|
# On Linux/macOS:
|
||||||
|
source venv/bin/activate
|
||||||
|
# On Windows:
|
||||||
|
# venv\Scripts\activate
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Set up environment variables**:
|
||||||
|
```bash
|
||||||
|
cp example.env .env
|
||||||
|
```
|
||||||
|
|
||||||
|
Edit the `.env` file and add your API key:
|
||||||
|
```env
|
||||||
|
# DeepSeek
|
||||||
|
DEEPSEEK_API_KEY="sk-your-actual-api-key-here"
|
||||||
|
|
||||||
|
# Or for OpenAI
|
||||||
|
# OPENAI_API_KEY="sk-your-openai-api-key"
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Install required Python packages**:
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
## 📁 Project Structure
|
## 📁 Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
daily-journal-prompt/
|
daily-journal-prompt/
|
||||||
├── backend/ # FastAPI backend
|
├── README.md # This documentation
|
||||||
│ ├── app/
|
├── generate_prompts.py # Main Python script with rich interface
|
||||||
│ │ ├── api/v1/ # API endpoints
|
├── run.sh # Convenience bash script
|
||||||
│ │ ├── core/ # Configuration, logging, exceptions
|
├── test_project.py # Test suite for the project
|
||||||
│ │ ├── models/ # Pydantic models
|
├── requirements.txt # Python dependencies
|
||||||
│ │ └── services/ # Business logic services
|
├── ds_prompt.txt # AI prompt template for generating journal prompts
|
||||||
│ ├── main.py # FastAPI application entry point
|
├── historic_prompts.json # History of previous 60 prompts (JSON format)
|
||||||
│ └── requirements.txt # Python dependencies
|
├── pool_prompts.json # Pool of available prompts for selection (JSON format)
|
||||||
├── frontend/ # Astro frontend
|
├── example.env # Example environment configuration
|
||||||
│ ├── src/
|
├── .env # Your actual environment configuration (gitignored)
|
||||||
│ │ ├── components/ # React components
|
├── settings.cfg # Configuration file for prompt settings and pool size
|
||||||
│ │ ├── layouts/ # Layout components
|
└── .gitignore # Git ignore rules
|
||||||
│ │ ├── pages/ # Astro pages
|
|
||||||
│ │ └── styles/ # CSS styles
|
|
||||||
│ ├── astro.config.mjs # Astro configuration
|
|
||||||
│ └── package.json # Node.js dependencies
|
|
||||||
├── data/ # Data storage (mounted volume)
|
|
||||||
│ ├── prompts_historic.json # Historic prompts
|
|
||||||
│ ├── prompts_pool.json # Prompt pool
|
|
||||||
│ ├── feedback_words.json # Feedback words with weights
|
|
||||||
│ ├── feedback_historic.json # Historic feedback
|
|
||||||
│ ├── ds_prompt.txt # Prompt template
|
|
||||||
│ ├── ds_feedback.txt # Feedback template
|
|
||||||
│ └── settings.cfg # Application settings
|
|
||||||
├── docker-compose.yml # Docker Compose configuration
|
|
||||||
├── backend/Dockerfile # Backend Dockerfile
|
|
||||||
├── frontend/Dockerfile # Frontend Dockerfile
|
|
||||||
├── .env.example # Environment variables template
|
|
||||||
├── API_DOCUMENTATION.md # API documentation
|
|
||||||
├── AGENTS.md # Project planning and architecture
|
|
||||||
└── README.md # This file
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🚀 Quick Start
|
### File Descriptions
|
||||||
|
|
||||||
### Prerequisites
|
- **generate_prompts.py**: Main Python script with interactive mode, rich formatting, and full features
|
||||||
- Python 3.11+
|
- **run.sh**: Convenience bash script for easy execution
|
||||||
- Node.js 18+
|
- **test_project.py**: Test suite to verify project setup
|
||||||
- Docker and Docker Compose (optional)
|
- **requirements.txt**: Python dependencies (openai, python-dotenv, rich)
|
||||||
- API key from DeepSeek or OpenAI
|
- **ds_prompt.txt**: The core prompt template that instructs the AI to generate new journal prompts
|
||||||
|
- **historic_prompts.json**: JSON array containing the last 60 generated prompts (cyclic buffer)
|
||||||
|
- **pool_prompts.json**: JSON array containing the pool of available prompts for selection
|
||||||
|
- **example.env**: Template for your environment configuration
|
||||||
|
- **.env**: Your actual environment variables (not tracked in git for security)
|
||||||
|
- **settings.cfg**: Configuration file for prompt settings (length, count) and pool size
|
||||||
|
|
||||||
### Option 1: Docker (Recommended)
|
## 🎯 Quick Start
|
||||||
|
|
||||||
1. **Clone and setup**
|
### Using the Bash Script (Recommended)
|
||||||
```bash
|
|
||||||
git clone <repository-url>
|
|
||||||
cd daily-journal-prompt
|
|
||||||
cp .env.example .env
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **Edit .env file**
|
|
||||||
```bash
|
|
||||||
# Add your API key
|
|
||||||
DEEPSEEK_API_KEY=your_api_key_here
|
|
||||||
# or
|
|
||||||
OPENAI_API_KEY=your_api_key_here
|
|
||||||
```
|
|
||||||
|
|
||||||
3. **Start with Docker Compose**
|
|
||||||
```bash
|
|
||||||
docker-compose up --build
|
|
||||||
```
|
|
||||||
|
|
||||||
4. **Access the application**
|
|
||||||
- Frontend: http://localhost:3000
|
|
||||||
- Backend API: http://localhost:8000
|
|
||||||
- API Documentation: http://localhost:8000/docs
|
|
||||||
|
|
||||||
### Option 2: Manual Setup
|
|
||||||
|
|
||||||
#### Backend Setup
|
|
||||||
```bash
|
```bash
|
||||||
cd backend
|
# Make the script executable
|
||||||
python -m venv venv
|
chmod +x run.sh
|
||||||
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
||||||
|
# Generate prompts (default)
|
||||||
|
./run.sh
|
||||||
|
|
||||||
|
# Interactive mode with rich interface
|
||||||
|
./run.sh --interactive
|
||||||
|
|
||||||
|
|
||||||
|
# Show statistics
|
||||||
|
./run.sh --stats
|
||||||
|
|
||||||
|
# Show help
|
||||||
|
./run.sh --help
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using Python Directly
|
||||||
|
```bash
|
||||||
|
# First, activate your virtual environment (if using one)
|
||||||
|
# On Linux/macOS:
|
||||||
|
# source venv/bin/activate
|
||||||
|
# On Windows:
|
||||||
|
# venv\Scripts\activate
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
# Set environment variables
|
# Generate prompts (default)
|
||||||
export DEEPSEEK_API_KEY=your_api_key_here
|
python generate_prompts.py
|
||||||
# or
|
|
||||||
export OPENAI_API_KEY=your_api_key_here
|
# Interactive mode
|
||||||
|
python generate_prompts.py --interactive
|
||||||
|
|
||||||
|
# Show statistics
|
||||||
|
python generate_prompts.py --stats
|
||||||
|
|
||||||
# Run the backend
|
|
||||||
uvicorn main:app --reload
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Frontend Setup
|
### Testing Your Setup
|
||||||
```bash
|
```bash
|
||||||
cd frontend
|
# Run the test suite
|
||||||
npm install
|
python test_project.py
|
||||||
npm run dev
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 📚 API Usage
|
## 🔧 Usage
|
||||||
|
|
||||||
The API provides comprehensive endpoints for prompt management:
|
### New Pool-Based System
|
||||||
|
|
||||||
|
The system now uses a two-step process:
|
||||||
|
|
||||||
|
1. **Fill the Prompt Pool**: Generate prompts using AI and add them to the pool
|
||||||
|
2. **Draw from Pool**: Select prompts from the pool for journaling sessions
|
||||||
|
|
||||||
|
### Command Line Options
|
||||||
|
|
||||||
### Basic Operations
|
|
||||||
```bash
|
```bash
|
||||||
# Draw prompts from pool
|
# Default: Draw prompts from pool (no API call)
|
||||||
curl http://localhost:8000/api/v1/prompts/draw
|
python generate_prompts.py
|
||||||
|
|
||||||
# Fill prompt pool
|
# Interactive mode with menu
|
||||||
curl -X POST http://localhost:8000/api/v1/prompts/fill-pool
|
python generate_prompts.py --interactive
|
||||||
|
|
||||||
# Get statistics
|
# Fill the prompt pool using AI (makes API call)
|
||||||
curl http://localhost:8000/api/v1/prompts/stats
|
python generate_prompts.py --fill-pool
|
||||||
|
|
||||||
|
# Show pool statistics
|
||||||
|
python generate_prompts.py --pool-stats
|
||||||
|
|
||||||
|
# Show history statistics
|
||||||
|
python generate_prompts.py --stats
|
||||||
|
|
||||||
|
# Help
|
||||||
|
python generate_prompts.py --help
|
||||||
```
|
```
|
||||||
|
|
||||||
### Interactive Documentation
|
### Interactive Mode Options
|
||||||
Access the automatic API documentation at:
|
|
||||||
- Swagger UI: http://localhost:8000/docs
|
|
||||||
- ReDoc: http://localhost:8000/redoc
|
|
||||||
|
|
||||||
## 🔧 Configuration
|
1. **Draw prompts from pool (no API call)**: Displays and consumes prompts from the pool file
|
||||||
|
2. **Fill prompt pool using API**: Generates new prompts using AI and adds them to pool
|
||||||
|
3. **View pool statistics**: Shows pool size, target size, and available sessions
|
||||||
|
4. **View history statistics**: Shows historic prompt count and capacity
|
||||||
|
5. **Exit**: Quit the program
|
||||||
|
|
||||||
|
### Prompt Generation Process
|
||||||
|
|
||||||
|
1. User chooses to fill the prompt pool.
|
||||||
|
2. The system reads the template from `ds_prompt.txt`
|
||||||
|
3. It loads the previous 60 prompts from the fixed length cyclic buffer `historic_prompts.json`
|
||||||
|
4. The AI generates some number of new prompts, attempting to minimize repetition
|
||||||
|
5. The new prompts are used to fill the prompt pool to the `settings.cfg` configured value.
|
||||||
|
|
||||||
|
### Prompt Selection Process
|
||||||
|
|
||||||
|
1. A `settings.cfg` configurable number of prompts are drawn from the prompt pool and displayed to the user.
|
||||||
|
2. User selects one prompt for his/her journal writing session, which is added to the `historic_prompts.json` cyclic buffer.
|
||||||
|
3. All prompts which were displayed are removed from the prompt pool permanently.
|
||||||
|
|
||||||
|
## 📝 Prompt Examples
|
||||||
|
|
||||||
|
The tool generates prompts like these (from `historic_prompts.json`):
|
||||||
|
|
||||||
|
- **Memory-based**: "Describe a memory you have that is tied to a specific smell..."
|
||||||
|
- **Creative Writing**: "Invent a mythological creature for a modern urban setting..."
|
||||||
|
- **Self-Reflection**: "Write a dialogue between two aspects of yourself..."
|
||||||
|
- **Observational**: "Describe your current emotional state as a weather system..."
|
||||||
|
|
||||||
|
Each prompt is designed to inspire 1-2 pages of journal writing and ranges from 500-1000 characters.
|
||||||
|
|
||||||
|
## ⚙️ Configuration
|
||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
Create a `.env` file based on `.env.example`:
|
|
||||||
|
Create a `.env` file with your API configuration:
|
||||||
|
|
||||||
```env
|
```env
|
||||||
# Required: At least one API key
|
# For DeepSeek
|
||||||
DEEPSEEK_API_KEY=your_deepseek_api_key
|
DEEPSEEK_API_KEY="sk-your-deepseek-api-key"
|
||||||
OPENAI_API_KEY=your_openai_api_key
|
|
||||||
|
|
||||||
# Optional: Customize behavior
|
# For OpenAI
|
||||||
API_BASE_URL=https://api.deepseek.com
|
# OPENAI_API_KEY="sk-your-openai-api-key"
|
||||||
MODEL=deepseek-chat
|
|
||||||
DEBUG=false
|
# Optional: Custom API base URL
|
||||||
CACHED_POOL_VOLUME=20
|
# API_BASE_URL="https://api.deepseek.com"
|
||||||
NUM_PROMPTS_PER_SESSION=6
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Application Settings
|
### Prompt Template Customization
|
||||||
Edit `data/settings.cfg` to customize:
|
|
||||||
- Prompt length constraints
|
|
||||||
- Number of prompts per session
|
|
||||||
- Pool volume targets
|
|
||||||
|
|
||||||
## 🐛 Troubleshooting
|
You can modify `ds_prompt.txt` to change the prompt generation parameters:
|
||||||
|
|
||||||
### Docker Permission Issues
|
- Number of prompts generated (default: 6)
|
||||||
If you encounter permission errors when running Docker containers:
|
- Prompt length requirements (default: 500-1000 characters)
|
||||||
|
- Specific themes or constraints
|
||||||
|
- Output format specifications
|
||||||
|
|
||||||
1. **Check directory permissions**:
|
## 🔄 Maintaining Prompt History
|
||||||
```bash
|
|
||||||
ls -la data/
|
|
||||||
```
|
|
||||||
The `data/` directory should be readable/writable by your user (UID 1000 typically).
|
|
||||||
|
|
||||||
2. **Fix permissions** (if needed):
|
The `historic_prompts.json` file maintains a rolling history of the last 60 prompts. This helps:
|
||||||
```bash
|
|
||||||
chmod 700 data/
|
|
||||||
chown -R $(id -u):$(id -g) data/
|
|
||||||
```
|
|
||||||
|
|
||||||
3. **Verify Docker user matches host user**:
|
1. **Avoid repetition**: The AI references previous prompts to generate new, diverse topics
|
||||||
The Dockerfile creates a user with UID 1000. If your host user has a different UID:
|
2. **Track usage**: See what types of prompts have been generated
|
||||||
```bash
|
3. **Quality control**: Monitor the variety and quality of generated prompts
|
||||||
# Check your UID
|
|
||||||
id -u
|
|
||||||
|
|
||||||
# Update Dockerfile to match your UID
|
|
||||||
# Change: RUN useradd -m -u 1000 appuser
|
|
||||||
# To: RUN useradd -m -u YOUR_UID appuser
|
|
||||||
```
|
|
||||||
|
|
||||||
### npm Build Errors
|
|
||||||
If you see `npm ci` errors:
|
|
||||||
- The Dockerfile uses `npm install` instead of `npm ci` for development
|
|
||||||
- For production, generate a `package-lock.json` file first:
|
|
||||||
```bash
|
|
||||||
cd frontend
|
|
||||||
npm install
|
|
||||||
```
|
|
||||||
|
|
||||||
### API Connection Issues
|
|
||||||
If the backend can't connect to AI APIs:
|
|
||||||
1. Verify your API key is set in `.env`
|
|
||||||
2. Check network connectivity
|
|
||||||
3. Ensure the API service is available
|
|
||||||
|
|
||||||
## 🧪 Testing
|
|
||||||
|
|
||||||
Run the backend tests:
|
|
||||||
```bash
|
|
||||||
python test_backend.py
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🐳 Docker Development
|
|
||||||
|
|
||||||
### Development Mode
|
|
||||||
```bash
|
|
||||||
# Hot reload for both backend and frontend
|
|
||||||
docker-compose up --build
|
|
||||||
|
|
||||||
# View logs
|
|
||||||
docker-compose logs -f
|
|
||||||
|
|
||||||
# Stop services
|
|
||||||
docker-compose down
|
|
||||||
```
|
|
||||||
|
|
||||||
### Useful Commands
|
|
||||||
```bash
|
|
||||||
# Rebuild specific service
|
|
||||||
docker-compose build backend
|
|
||||||
|
|
||||||
# Run single service
|
|
||||||
docker-compose up backend
|
|
||||||
|
|
||||||
# Execute commands in container
|
|
||||||
docker-compose exec backend python -m pytest
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🔄 Migration from CLI
|
|
||||||
|
|
||||||
The web application maintains full compatibility with the original CLI data format:
|
|
||||||
|
|
||||||
1. **Data Files**: Existing JSON files are automatically used
|
|
||||||
2. **Templates**: Same prompt and feedback templates
|
|
||||||
3. **Settings**: Compatible settings.cfg format
|
|
||||||
4. **Functionality**: All CLI features available via API
|
|
||||||
|
|
||||||
## 📊 Features Comparison
|
|
||||||
|
|
||||||
| Feature | CLI Version | Web Version |
|
|
||||||
|---------|------------|-------------|
|
|
||||||
| Prompt Generation | ✅ | ✅ |
|
|
||||||
| Prompt Pool | ✅ | ✅ |
|
|
||||||
| History Management | ✅ | ✅ |
|
|
||||||
| Theme Feedback | ✅ | ✅ |
|
|
||||||
| Web Interface | ❌ | ✅ |
|
|
||||||
| REST API | ❌ | ✅ |
|
|
||||||
| Docker Support | ❌ | ✅ |
|
|
||||||
| Multi-user Ready | ❌ | ✅ (future) |
|
|
||||||
| Mobile Responsive | ❌ | ✅ |
|
|
||||||
|
|
||||||
## 🛠️ Development
|
|
||||||
|
|
||||||
### Backend Development
|
|
||||||
```bash
|
|
||||||
cd backend
|
|
||||||
# Install development dependencies
|
|
||||||
pip install -r requirements.txt
|
|
||||||
|
|
||||||
# Run with hot reload
|
|
||||||
uvicorn main:app --reload --host 0.0.0.0 --port 8000
|
|
||||||
|
|
||||||
# Run tests
|
|
||||||
python test_backend.py
|
|
||||||
```
|
|
||||||
|
|
||||||
### Frontend Development
|
|
||||||
```bash
|
|
||||||
cd frontend
|
|
||||||
# Install dependencies
|
|
||||||
npm install
|
|
||||||
|
|
||||||
# Run development server
|
|
||||||
npm run dev
|
|
||||||
|
|
||||||
# Build for production
|
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
### Code Structure
|
|
||||||
- **Backend**: Follows FastAPI best practices with dependency injection
|
|
||||||
- **Frontend**: Uses Astro islands architecture with React components
|
|
||||||
- **Services**: Async/await pattern for I/O operations
|
|
||||||
- **Error Handling**: Comprehensive error handling at all levels
|
|
||||||
|
|
||||||
## 🤝 Contributing
|
## 🤝 Contributing
|
||||||
|
|
||||||
1. Fork the repository
|
Contributions are welcome! Here are some ways you can contribute:
|
||||||
2. Create a feature branch
|
|
||||||
3. Make your changes
|
|
||||||
4. Add tests if applicable
|
|
||||||
5. Submit a pull request
|
|
||||||
|
|
||||||
### Development Guidelines
|
1. **Add new prompt templates** for different writing styles
|
||||||
- Follow PEP 8 for Python code
|
2. **Improve the AI prompt engineering** for better results
|
||||||
- Use TypeScript for React components when possible
|
3. **Add support for more AI providers**
|
||||||
- Write meaningful commit messages
|
4. **Create a CLI interface** for easier usage
|
||||||
- Update documentation for new features
|
5. **Add tests** to ensure reliability
|
||||||
- Add tests for new functionality
|
|
||||||
|
|
||||||
## 📄 License
|
## 📄 License
|
||||||
|
|
||||||
This project is licensed under the MIT License - see the LICENSE file for details.
|
[Add appropriate license information here]
|
||||||
|
|
||||||
## 🙏 Acknowledgments
|
## 🙏 Acknowledgments
|
||||||
|
|
||||||
- Built with [FastAPI](https://fastapi.tiangolo.com/)
|
- Inspired by the need for consistent journaling practice
|
||||||
- Frontend with [Astro](https://astro.build/)
|
- Built with OpenAI-compatible AI services
|
||||||
- AI integration with [OpenAI](https://openai.com/) and [DeepSeek](https://www.deepseek.com/)
|
- Community contributions welcome
|
||||||
- Icons from [Font Awesome](https://fontawesome.com/)
|
|
||||||
|
|
||||||
## 📞 Support
|
## 🆘 Support
|
||||||
|
|
||||||
- **Issues**: Use GitHub Issues for bug reports and feature requests
|
For issues, questions, or suggestions:
|
||||||
- **Documentation**: Check `API_DOCUMENTATION.md` for API details
|
1. Check the existing issues on GitHub
|
||||||
- **Examples**: See the test files for usage examples
|
2. Create a new issue with detailed information
|
||||||
|
3. Provide examples of problematic prompts or errors
|
||||||
## 🚀 Deployment
|
|
||||||
|
|
||||||
### Cloud Platforms
|
|
||||||
- **Render**: One-click deployment with Docker
|
|
||||||
- **Railway**: Easy deployment with environment management
|
|
||||||
- **Fly.io**: Global deployment with edge computing
|
|
||||||
- **AWS/GCP/Azure**: Traditional cloud deployment
|
|
||||||
|
|
||||||
### Deployment Steps
|
|
||||||
1. Set environment variables
|
|
||||||
2. Build Docker images
|
|
||||||
3. Configure database (if migrating from JSON)
|
|
||||||
4. Set up reverse proxy (nginx/caddy)
|
|
||||||
5. Configure SSL certificates
|
|
||||||
6. Set up monitoring and logging
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Happy Journaling! 📓✨**
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
FROM python:3.11-slim
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Install system dependencies
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
gcc \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Copy requirements first for better caching
|
|
||||||
COPY requirements.txt .
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
|
||||||
|
|
||||||
# Copy application code
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Create non-root user
|
|
||||||
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
|
|
||||||
USER appuser
|
|
||||||
|
|
||||||
# Expose port
|
|
||||||
EXPOSE 8000
|
|
||||||
|
|
||||||
# Health check
|
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
||||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
|
||||||
|
|
||||||
# Run the application
|
|
||||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
||||||
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
"""
|
|
||||||
API router for version 1 endpoints.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
from app.api.v1.endpoints import prompts, feedback
|
|
||||||
|
|
||||||
# Create main API router
|
|
||||||
api_router = APIRouter()
|
|
||||||
|
|
||||||
# Include endpoint routers
|
|
||||||
api_router.include_router(prompts.router, prefix="/prompts", tags=["prompts"])
|
|
||||||
api_router.include_router(feedback.router, prefix="/feedback", tags=["feedback"])
|
|
||||||
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
"""
|
|
||||||
Feedback-related API endpoints.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import List, Dict
|
|
||||||
from fastapi import APIRouter, HTTPException, Depends, status
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
from app.services.prompt_service import PromptService
|
|
||||||
from app.models.prompt import FeedbackWord, RateFeedbackWordsRequest, RateFeedbackWordsResponse
|
|
||||||
|
|
||||||
# Create router
|
|
||||||
router = APIRouter()
|
|
||||||
|
|
||||||
# Response models
|
|
||||||
class GenerateFeedbackWordsResponse(BaseModel):
|
|
||||||
"""Response model for generating feedback words."""
|
|
||||||
theme_words: List[str]
|
|
||||||
count: int = 6
|
|
||||||
|
|
||||||
# Service dependency
|
|
||||||
async def get_prompt_service() -> PromptService:
|
|
||||||
"""Dependency to get PromptService instance."""
|
|
||||||
return PromptService()
|
|
||||||
|
|
||||||
@router.get("/generate", response_model=GenerateFeedbackWordsResponse)
|
|
||||||
async def generate_feedback_words(
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Generate 6 theme feedback words using AI.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of 6 theme words for feedback
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
theme_words = await prompt_service.generate_theme_feedback_words()
|
|
||||||
|
|
||||||
if len(theme_words) != 6:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Expected 6 theme words, got {len(theme_words)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
return GenerateFeedbackWordsResponse(
|
|
||||||
theme_words=theme_words,
|
|
||||||
count=len(theme_words)
|
|
||||||
)
|
|
||||||
except ValueError as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
|
||||||
detail=str(e)
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error generating feedback words: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@router.post("/rate", response_model=RateFeedbackWordsResponse)
|
|
||||||
async def rate_feedback_words(
|
|
||||||
request: RateFeedbackWordsRequest,
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Rate feedback words and update feedback system.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request: Dictionary of word to rating (0-6)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Updated feedback words
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
feedback_words = await prompt_service.update_feedback_words(request.ratings)
|
|
||||||
|
|
||||||
return RateFeedbackWordsResponse(
|
|
||||||
feedback_words=feedback_words,
|
|
||||||
added_to_history=True
|
|
||||||
)
|
|
||||||
except ValueError as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
|
||||||
detail=str(e)
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error rating feedback words: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@router.get("/current", response_model=List[FeedbackWord])
|
|
||||||
async def get_current_feedback_words(
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Get current feedback words with weights.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of current feedback words with weights
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
# This would need to be implemented in PromptService
|
|
||||||
# For now, return empty list
|
|
||||||
return []
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error getting current feedback words: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@router.get("/history")
|
|
||||||
async def get_feedback_history(
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Get feedback word history.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of historic feedback words
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
# This would need to be implemented in PromptService
|
|
||||||
# For now, return empty list
|
|
||||||
return []
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error getting feedback history: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
"""
|
|
||||||
Prompt-related API endpoints.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import List, Optional
|
|
||||||
from fastapi import APIRouter, HTTPException, Depends, status
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
from app.services.prompt_service import PromptService
|
|
||||||
from app.models.prompt import PromptResponse, PoolStatsResponse, HistoryStatsResponse
|
|
||||||
|
|
||||||
# Create router
|
|
||||||
router = APIRouter()
|
|
||||||
|
|
||||||
# Response models
|
|
||||||
class DrawPromptsResponse(BaseModel):
|
|
||||||
"""Response model for drawing prompts."""
|
|
||||||
prompts: List[str]
|
|
||||||
count: int
|
|
||||||
remaining_in_pool: int
|
|
||||||
|
|
||||||
class FillPoolResponse(BaseModel):
|
|
||||||
"""Response model for filling prompt pool."""
|
|
||||||
added: int
|
|
||||||
total_in_pool: int
|
|
||||||
target_volume: int
|
|
||||||
|
|
||||||
class SelectPromptRequest(BaseModel):
|
|
||||||
"""Request model for selecting a prompt."""
|
|
||||||
prompt_text: str
|
|
||||||
|
|
||||||
class SelectPromptResponse(BaseModel):
|
|
||||||
"""Response model for selecting a prompt."""
|
|
||||||
selected_prompt: str
|
|
||||||
position_in_history: str # e.g., "prompt00"
|
|
||||||
history_size: int
|
|
||||||
|
|
||||||
# Service dependency
|
|
||||||
async def get_prompt_service() -> PromptService:
|
|
||||||
"""Dependency to get PromptService instance."""
|
|
||||||
return PromptService()
|
|
||||||
|
|
||||||
@router.get("/draw", response_model=DrawPromptsResponse)
|
|
||||||
async def draw_prompts(
|
|
||||||
count: Optional[int] = None,
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Draw prompts from the pool.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
count: Number of prompts to draw (defaults to settings.NUM_PROMPTS_PER_SESSION)
|
|
||||||
prompt_service: PromptService instance
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of prompts drawn from pool
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
prompts = await prompt_service.draw_prompts_from_pool(count)
|
|
||||||
pool_size = prompt_service.get_pool_size()
|
|
||||||
|
|
||||||
return DrawPromptsResponse(
|
|
||||||
prompts=prompts,
|
|
||||||
count=len(prompts),
|
|
||||||
remaining_in_pool=pool_size
|
|
||||||
)
|
|
||||||
except ValueError as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
|
||||||
detail=str(e)
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error drawing prompts: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@router.post("/fill-pool", response_model=FillPoolResponse)
|
|
||||||
async def fill_prompt_pool(
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Fill the prompt pool to target volume using AI.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Information about added prompts
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
added_count = await prompt_service.fill_pool_to_target()
|
|
||||||
pool_size = prompt_service.get_pool_size()
|
|
||||||
target_volume = prompt_service.get_target_volume()
|
|
||||||
|
|
||||||
return FillPoolResponse(
|
|
||||||
added=added_count,
|
|
||||||
total_in_pool=pool_size,
|
|
||||||
target_volume=target_volume
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error filling prompt pool: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@router.get("/stats", response_model=PoolStatsResponse)
|
|
||||||
async def get_pool_stats(
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Get statistics about the prompt pool.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Pool statistics
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
return await prompt_service.get_pool_stats()
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error getting pool stats: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@router.get("/history/stats", response_model=HistoryStatsResponse)
|
|
||||||
async def get_history_stats(
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Get statistics about prompt history.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
History statistics
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
return await prompt_service.get_history_stats()
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error getting history stats: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@router.get("/history", response_model=List[PromptResponse])
|
|
||||||
async def get_prompt_history(
|
|
||||||
limit: Optional[int] = None,
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Get prompt history.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
limit: Maximum number of history items to return
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of historical prompts
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
return await prompt_service.get_prompt_history(limit)
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error getting prompt history: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@router.post("/select", response_model=SelectPromptResponse)
|
|
||||||
async def select_prompt(
|
|
||||||
request: SelectPromptRequest,
|
|
||||||
prompt_service: PromptService = Depends(get_prompt_service)
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Select a prompt to add to history.
|
|
||||||
|
|
||||||
Adds the provided prompt text to the historic prompts cyclic buffer.
|
|
||||||
The prompt will be added at position 0 (most recent), shifting existing prompts down.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
request: SelectPromptRequest containing the prompt text
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Confirmation of prompt selection with position in history
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
# Add the prompt to history
|
|
||||||
position_key = await prompt_service.add_prompt_to_history(request.prompt_text)
|
|
||||||
|
|
||||||
# Get updated history stats
|
|
||||||
history_stats = await prompt_service.get_history_stats()
|
|
||||||
|
|
||||||
return SelectPromptResponse(
|
|
||||||
selected_prompt=request.prompt_text,
|
|
||||||
position_in_history=position_key,
|
|
||||||
history_size=history_stats.total_prompts
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=f"Error selecting prompt: {str(e)}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
"""
|
|
||||||
Configuration settings for the application.
|
|
||||||
Uses Pydantic settings management with environment variable support.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
from typing import List, Optional
|
|
||||||
from pydantic_settings import BaseSettings
|
|
||||||
from pydantic import AnyHttpUrl, validator
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
|
||||||
"""Application settings."""
|
|
||||||
|
|
||||||
# API Settings
|
|
||||||
API_V1_STR: str = "/api/v1"
|
|
||||||
PROJECT_NAME: str = "Daily Journal Prompt Generator API"
|
|
||||||
VERSION: str = "1.0.0"
|
|
||||||
DEBUG: bool = False
|
|
||||||
ENVIRONMENT: str = "development"
|
|
||||||
|
|
||||||
# Server Settings
|
|
||||||
HOST: str = "0.0.0.0"
|
|
||||||
PORT: int = 8000
|
|
||||||
|
|
||||||
# CORS Settings
|
|
||||||
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = [
|
|
||||||
"http://localhost:3000", # Frontend dev server
|
|
||||||
"http://localhost:80", # Frontend production
|
|
||||||
]
|
|
||||||
|
|
||||||
# API Keys
|
|
||||||
DEEPSEEK_API_KEY: Optional[str] = None
|
|
||||||
OPENAI_API_KEY: Optional[str] = None
|
|
||||||
API_BASE_URL: str = "https://api.deepseek.com"
|
|
||||||
MODEL: str = "deepseek-chat"
|
|
||||||
|
|
||||||
# Application Settings
|
|
||||||
MIN_PROMPT_LENGTH: int = 500
|
|
||||||
MAX_PROMPT_LENGTH: int = 1000
|
|
||||||
NUM_PROMPTS_PER_SESSION: int = 3
|
|
||||||
CACHED_POOL_VOLUME: int = 20
|
|
||||||
HISTORY_BUFFER_SIZE: int = 60
|
|
||||||
FEEDBACK_HISTORY_SIZE: int = 30
|
|
||||||
|
|
||||||
# File Paths (relative to project root)
|
|
||||||
DATA_DIR: str = "data"
|
|
||||||
PROMPT_TEMPLATE_PATH: str = "data/ds_prompt.txt"
|
|
||||||
FEEDBACK_TEMPLATE_PATH: str = "data/ds_feedback.txt"
|
|
||||||
SETTINGS_CONFIG_PATH: str = "data/settings.cfg"
|
|
||||||
|
|
||||||
# Data File Names (relative to DATA_DIR)
|
|
||||||
PROMPTS_HISTORIC_FILE: str = "prompts_historic.json"
|
|
||||||
PROMPTS_POOL_FILE: str = "prompts_pool.json"
|
|
||||||
FEEDBACK_WORDS_FILE: str = "feedback_words.json"
|
|
||||||
FEEDBACK_HISTORIC_FILE: str = "feedback_historic.json"
|
|
||||||
|
|
||||||
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
|
||||||
def assemble_cors_origins(cls, v: str | List[str]) -> List[str] | str:
|
|
||||||
"""Parse CORS origins from string or list."""
|
|
||||||
if isinstance(v, str) and not v.startswith("["):
|
|
||||||
return [i.strip() for i in v.split(",")]
|
|
||||||
elif isinstance(v, (list, str)):
|
|
||||||
return v
|
|
||||||
raise ValueError(v)
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
"""Pydantic configuration."""
|
|
||||||
env_file = ".env"
|
|
||||||
case_sensitive = True
|
|
||||||
extra = "ignore"
|
|
||||||
|
|
||||||
|
|
||||||
# Create global settings instance
|
|
||||||
settings = Settings()
|
|
||||||
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
"""
|
|
||||||
Exception handlers for the application.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
from typing import Any, Dict
|
|
||||||
from fastapi import FastAPI, Request, status
|
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
from fastapi.exceptions import RequestValidationError
|
|
||||||
from pydantic import ValidationError as PydanticValidationError
|
|
||||||
|
|
||||||
from app.core.exceptions import DailyJournalPromptException
|
|
||||||
from app.core.logging import setup_logging
|
|
||||||
|
|
||||||
logger = setup_logging()
|
|
||||||
|
|
||||||
|
|
||||||
def setup_exception_handlers(app: FastAPI) -> None:
|
|
||||||
"""Set up exception handlers for the FastAPI application."""
|
|
||||||
|
|
||||||
@app.exception_handler(DailyJournalPromptException)
|
|
||||||
async def daily_journal_prompt_exception_handler(
|
|
||||||
request: Request,
|
|
||||||
exc: DailyJournalPromptException,
|
|
||||||
) -> JSONResponse:
|
|
||||||
"""Handle DailyJournalPromptException."""
|
|
||||||
logger.error(f"DailyJournalPromptException: {exc.detail}")
|
|
||||||
return JSONResponse(
|
|
||||||
status_code=exc.status_code,
|
|
||||||
content={
|
|
||||||
"error": {
|
|
||||||
"type": exc.__class__.__name__,
|
|
||||||
"message": str(exc.detail),
|
|
||||||
"status_code": exc.status_code,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@app.exception_handler(RequestValidationError)
|
|
||||||
async def request_validation_exception_handler(
|
|
||||||
request: Request,
|
|
||||||
exc: RequestValidationError,
|
|
||||||
) -> JSONResponse:
|
|
||||||
"""Handle request validation errors."""
|
|
||||||
logger.warning(f"RequestValidationError: {exc.errors()}")
|
|
||||||
return JSONResponse(
|
|
||||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
||||||
content={
|
|
||||||
"error": {
|
|
||||||
"type": "ValidationError",
|
|
||||||
"message": "Invalid request data",
|
|
||||||
"details": exc.errors(),
|
|
||||||
"status_code": status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@app.exception_handler(PydanticValidationError)
|
|
||||||
async def pydantic_validation_exception_handler(
|
|
||||||
request: Request,
|
|
||||||
exc: PydanticValidationError,
|
|
||||||
) -> JSONResponse:
|
|
||||||
"""Handle Pydantic validation errors."""
|
|
||||||
logger.warning(f"PydanticValidationError: {exc.errors()}")
|
|
||||||
return JSONResponse(
|
|
||||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
||||||
content={
|
|
||||||
"error": {
|
|
||||||
"type": "ValidationError",
|
|
||||||
"message": "Invalid data format",
|
|
||||||
"details": exc.errors(),
|
|
||||||
"status_code": status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@app.exception_handler(Exception)
|
|
||||||
async def generic_exception_handler(
|
|
||||||
request: Request,
|
|
||||||
exc: Exception,
|
|
||||||
) -> JSONResponse:
|
|
||||||
"""Handle all other exceptions."""
|
|
||||||
logger.exception(f"Unhandled exception: {exc}")
|
|
||||||
return JSONResponse(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
content={
|
|
||||||
"error": {
|
|
||||||
"type": "InternalServerError",
|
|
||||||
"message": "An unexpected error occurred",
|
|
||||||
"status_code": status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@app.exception_handler(404)
|
|
||||||
async def not_found_exception_handler(
|
|
||||||
request: Request,
|
|
||||||
exc: Exception,
|
|
||||||
) -> JSONResponse:
|
|
||||||
"""Handle 404 Not Found errors."""
|
|
||||||
logger.warning(f"404 Not Found: {request.url}")
|
|
||||||
return JSONResponse(
|
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
|
||||||
content={
|
|
||||||
"error": {
|
|
||||||
"type": "NotFoundError",
|
|
||||||
"message": f"Resource not found: {request.url}",
|
|
||||||
"status_code": status.HTTP_404_NOT_FOUND,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@app.exception_handler(405)
|
|
||||||
async def method_not_allowed_exception_handler(
|
|
||||||
request: Request,
|
|
||||||
exc: Exception,
|
|
||||||
) -> JSONResponse:
|
|
||||||
"""Handle 405 Method Not Allowed errors."""
|
|
||||||
logger.warning(f"405 Method Not Allowed: {request.method} {request.url}")
|
|
||||||
return JSONResponse(
|
|
||||||
status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
|
|
||||||
content={
|
|
||||||
"error": {
|
|
||||||
"type": "MethodNotAllowedError",
|
|
||||||
"message": f"Method {request.method} not allowed for {request.url}",
|
|
||||||
"status_code": status.HTTP_405_METHOD_NOT_ALLOWED,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
"""
|
|
||||||
Custom exceptions for the application.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Any, Dict, Optional
|
|
||||||
from fastapi import HTTPException, status
|
|
||||||
|
|
||||||
|
|
||||||
class DailyJournalPromptException(HTTPException):
|
|
||||||
"""Base exception for Daily Journal Prompt application."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail: Any = None,
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(status_code=status_code, detail=detail, headers=headers)
|
|
||||||
|
|
||||||
|
|
||||||
class ValidationError(DailyJournalPromptException):
|
|
||||||
"""Exception for validation errors."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
detail: Any = "Validation error",
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class NotFoundError(DailyJournalPromptException):
|
|
||||||
"""Exception for resource not found errors."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
detail: Any = "Resource not found",
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UnauthorizedError(DailyJournalPromptException):
|
|
||||||
"""Exception for unauthorized access errors."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
detail: Any = "Unauthorized access",
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ForbiddenError(DailyJournalPromptException):
|
|
||||||
"""Exception for forbidden access errors."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
detail: Any = "Forbidden access",
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AIServiceError(DailyJournalPromptException):
|
|
||||||
"""Exception for AI service errors."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
detail: Any = "AI service error",
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class DataServiceError(DailyJournalPromptException):
|
|
||||||
"""Exception for data service errors."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
detail: Any = "Data service error",
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationError(DailyJournalPromptException):
|
|
||||||
"""Exception for configuration errors."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
detail: Any = "Configuration error",
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PromptPoolEmptyError(DailyJournalPromptException):
|
|
||||||
"""Exception for empty prompt pool."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
detail: Any = "Prompt pool is empty",
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class InsufficientPoolSizeError(DailyJournalPromptException):
|
|
||||||
"""Exception for insufficient pool size."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
current_size: int,
|
|
||||||
requested: int,
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
detail = f"Pool only has {current_size} prompts, requested {requested}"
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TemplateNotFoundError(DailyJournalPromptException):
|
|
||||||
"""Exception for missing template files."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
template_name: str,
|
|
||||||
headers: Optional[Dict[str, str]] = None,
|
|
||||||
) -> None:
|
|
||||||
detail = f"Template not found: {template_name}"
|
|
||||||
super().__init__(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=detail,
|
|
||||||
headers=headers,
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
"""
|
|
||||||
Logging configuration for the application.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from app.core.config import settings
|
|
||||||
|
|
||||||
|
|
||||||
def setup_logging(
|
|
||||||
logger_name: str = "daily_journal_prompt",
|
|
||||||
log_level: Optional[str] = None,
|
|
||||||
) -> logging.Logger:
|
|
||||||
"""
|
|
||||||
Set up logging configuration.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
logger_name: Name of the logger
|
|
||||||
log_level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Configured logger instance
|
|
||||||
"""
|
|
||||||
if log_level is None:
|
|
||||||
log_level = "DEBUG" if settings.DEBUG else "INFO"
|
|
||||||
|
|
||||||
# Create logger
|
|
||||||
logger = logging.getLogger(logger_name)
|
|
||||||
logger.setLevel(getattr(logging, log_level.upper()))
|
|
||||||
|
|
||||||
# Remove existing handlers to avoid duplicates
|
|
||||||
logger.handlers.clear()
|
|
||||||
|
|
||||||
# Create console handler
|
|
||||||
console_handler = logging.StreamHandler(sys.stdout)
|
|
||||||
console_handler.setLevel(getattr(logging, log_level.upper()))
|
|
||||||
|
|
||||||
# Create formatter
|
|
||||||
formatter = logging.Formatter(
|
|
||||||
"%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
||||||
datefmt="%Y-%m-%d %H:%M:%S"
|
|
||||||
)
|
|
||||||
console_handler.setFormatter(formatter)
|
|
||||||
|
|
||||||
# Add handler to logger
|
|
||||||
logger.addHandler(console_handler)
|
|
||||||
|
|
||||||
# Prevent propagation to root logger
|
|
||||||
logger.propagate = False
|
|
||||||
|
|
||||||
return logger
|
|
||||||
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
"""
|
|
||||||
Pydantic models for prompt-related data.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import List, Optional, Dict, Any
|
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
|
|
||||||
|
|
||||||
class PromptResponse(BaseModel):
|
|
||||||
"""Response model for a single prompt."""
|
|
||||||
key: str = Field(..., description="Prompt key (e.g., 'prompt00')")
|
|
||||||
text: str = Field(..., description="Prompt text content")
|
|
||||||
position: int = Field(..., description="Position in history (0 = most recent)")
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
"""Pydantic configuration."""
|
|
||||||
from_attributes = True
|
|
||||||
|
|
||||||
|
|
||||||
class PoolStatsResponse(BaseModel):
|
|
||||||
"""Response model for pool statistics."""
|
|
||||||
total_prompts: int = Field(..., description="Total prompts in pool")
|
|
||||||
prompts_per_session: int = Field(..., description="Prompts drawn per session")
|
|
||||||
target_pool_size: int = Field(..., description="Target pool volume")
|
|
||||||
available_sessions: int = Field(..., description="Available sessions in pool")
|
|
||||||
needs_refill: bool = Field(..., description="Whether pool needs refilling")
|
|
||||||
|
|
||||||
|
|
||||||
class HistoryStatsResponse(BaseModel):
|
|
||||||
"""Response model for history statistics."""
|
|
||||||
total_prompts: int = Field(..., description="Total prompts in history")
|
|
||||||
history_capacity: int = Field(..., description="Maximum history capacity")
|
|
||||||
available_slots: int = Field(..., description="Available slots in history")
|
|
||||||
is_full: bool = Field(..., description="Whether history is full")
|
|
||||||
|
|
||||||
|
|
||||||
class FeedbackWord(BaseModel):
|
|
||||||
"""Model for a feedback word with weight."""
|
|
||||||
key: str = Field(..., description="Feedback key (e.g., 'feedback00')")
|
|
||||||
word: str = Field(..., description="Feedback word")
|
|
||||||
weight: int = Field(..., ge=0, le=6, description="Weight from 0-6")
|
|
||||||
|
|
||||||
|
|
||||||
class FeedbackHistoryItem(BaseModel):
|
|
||||||
"""Model for a feedback history item (word only, no weight)."""
|
|
||||||
key: str = Field(..., description="Feedback key (e.g., 'feedback00')")
|
|
||||||
word: str = Field(..., description="Feedback word")
|
|
||||||
|
|
||||||
|
|
||||||
class GeneratePromptsRequest(BaseModel):
|
|
||||||
"""Request model for generating prompts."""
|
|
||||||
count: Optional[int] = Field(
|
|
||||||
None,
|
|
||||||
ge=1,
|
|
||||||
le=20,
|
|
||||||
description="Number of prompts to generate (defaults to settings)"
|
|
||||||
)
|
|
||||||
use_history: bool = Field(
|
|
||||||
True,
|
|
||||||
description="Whether to use historic prompts as context"
|
|
||||||
)
|
|
||||||
use_feedback: bool = Field(
|
|
||||||
True,
|
|
||||||
description="Whether to use feedback words as context"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GeneratePromptsResponse(BaseModel):
|
|
||||||
"""Response model for generated prompts."""
|
|
||||||
prompts: List[str] = Field(..., description="Generated prompts")
|
|
||||||
count: int = Field(..., description="Number of prompts generated")
|
|
||||||
used_history: bool = Field(..., description="Whether history was used")
|
|
||||||
used_feedback: bool = Field(..., description="Whether feedback was used")
|
|
||||||
|
|
||||||
|
|
||||||
class RateFeedbackWordsRequest(BaseModel):
|
|
||||||
"""Request model for rating feedback words."""
|
|
||||||
ratings: Dict[str, int] = Field(
|
|
||||||
...,
|
|
||||||
description="Dictionary of word to rating (0-6)"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class RateFeedbackWordsResponse(BaseModel):
|
|
||||||
"""Response model for rated feedback words."""
|
|
||||||
feedback_words: List[FeedbackWord] = Field(..., description="Rated feedback words")
|
|
||||||
added_to_history: bool = Field(..., description="Whether added to history")
|
|
||||||
|
|
||||||
@@ -1,337 +0,0 @@
|
|||||||
"""
|
|
||||||
AI service for handling OpenAI/DeepSeek API calls.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
from typing import List, Dict, Any, Optional
|
|
||||||
from openai import OpenAI, AsyncOpenAI
|
|
||||||
|
|
||||||
from app.core.config import settings
|
|
||||||
from app.core.logging import setup_logging
|
|
||||||
|
|
||||||
logger = setup_logging()
|
|
||||||
|
|
||||||
|
|
||||||
class AIService:
|
|
||||||
"""Service for handling AI API calls."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""Initialize AI service."""
|
|
||||||
api_key = settings.DEEPSEEK_API_KEY or settings.OPENAI_API_KEY
|
|
||||||
if not api_key:
|
|
||||||
raise ValueError("No API key found. Set DEEPSEEK_API_KEY or OPENAI_API_KEY in environment.")
|
|
||||||
|
|
||||||
self.client = AsyncOpenAI(
|
|
||||||
api_key=api_key,
|
|
||||||
base_url=settings.API_BASE_URL
|
|
||||||
)
|
|
||||||
self.model = settings.MODEL
|
|
||||||
|
|
||||||
def _clean_ai_response(self, response_content: str) -> str:
|
|
||||||
"""
|
|
||||||
Clean up AI response content to handle common formatting issues.
|
|
||||||
|
|
||||||
Handles:
|
|
||||||
1. Leading/trailing backticks (```json ... ```)
|
|
||||||
2. Leading "json" string on its own line
|
|
||||||
3. Extra whitespace and newlines
|
|
||||||
"""
|
|
||||||
content = response_content.strip()
|
|
||||||
|
|
||||||
# Remove leading/trailing backticks (```json ... ```)
|
|
||||||
if content.startswith('```'):
|
|
||||||
lines = content.split('\n')
|
|
||||||
if len(lines) > 1:
|
|
||||||
first_line = lines[0].strip()
|
|
||||||
if 'json' in first_line.lower() or first_line == '```':
|
|
||||||
content = '\n'.join(lines[1:])
|
|
||||||
|
|
||||||
# Remove trailing backticks if present
|
|
||||||
if content.endswith('```'):
|
|
||||||
content = content[:-3].rstrip()
|
|
||||||
|
|
||||||
# Remove leading "json" string on its own line (case-insensitive)
|
|
||||||
lines = content.split('\n')
|
|
||||||
if len(lines) > 0:
|
|
||||||
first_line = lines[0].strip().lower()
|
|
||||||
if first_line == 'json':
|
|
||||||
content = '\n'.join(lines[1:])
|
|
||||||
|
|
||||||
# Also handle the case where "json" might be at the beginning of the first line
|
|
||||||
content = content.strip()
|
|
||||||
if content.lower().startswith('json\n'):
|
|
||||||
content = content[4:].strip()
|
|
||||||
|
|
||||||
return content.strip()
|
|
||||||
|
|
||||||
async def generate_prompts(
|
|
||||||
self,
|
|
||||||
prompt_template: str,
|
|
||||||
historic_prompts: List[Dict[str, str]],
|
|
||||||
feedback_words: Optional[List[Dict[str, Any]]] = None,
|
|
||||||
count: Optional[int] = None,
|
|
||||||
min_length: Optional[int] = None,
|
|
||||||
max_length: Optional[int] = None
|
|
||||||
) -> List[str]:
|
|
||||||
"""
|
|
||||||
Generate journal prompts using AI.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
prompt_template: Base prompt template
|
|
||||||
historic_prompts: List of historic prompts for context
|
|
||||||
feedback_words: List of feedback words with weights
|
|
||||||
count: Number of prompts to generate
|
|
||||||
min_length: Minimum prompt length
|
|
||||||
max_length: Maximum prompt length
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of generated prompts
|
|
||||||
"""
|
|
||||||
if count is None:
|
|
||||||
count = settings.NUM_PROMPTS_PER_SESSION
|
|
||||||
if min_length is None:
|
|
||||||
min_length = settings.MIN_PROMPT_LENGTH
|
|
||||||
if max_length is None:
|
|
||||||
max_length = settings.MAX_PROMPT_LENGTH
|
|
||||||
|
|
||||||
# Prepare the full prompt
|
|
||||||
full_prompt = self._prepare_prompt(
|
|
||||||
prompt_template,
|
|
||||||
historic_prompts,
|
|
||||||
feedback_words,
|
|
||||||
count,
|
|
||||||
min_length,
|
|
||||||
max_length
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(f"Generating {count} prompts with AI")
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Call the AI API
|
|
||||||
response = await self.client.chat.completions.create(
|
|
||||||
model=self.model,
|
|
||||||
messages=[
|
|
||||||
{
|
|
||||||
"role": "system",
|
|
||||||
"content": "You are a creative writing assistant that generates journal prompts. Always respond with valid JSON."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": full_prompt
|
|
||||||
}
|
|
||||||
],
|
|
||||||
temperature=0.7,
|
|
||||||
max_tokens=2000
|
|
||||||
)
|
|
||||||
|
|
||||||
response_content = response.choices[0].message.content
|
|
||||||
logger.debug(f"AI response received: {len(response_content)} characters")
|
|
||||||
|
|
||||||
# Parse the response
|
|
||||||
prompts = self._parse_prompt_response(response_content, count)
|
|
||||||
logger.info(f"Successfully parsed {len(prompts)} prompts from AI response")
|
|
||||||
|
|
||||||
return prompts
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error calling AI API: {e}")
|
|
||||||
logger.debug(f"Full prompt sent to API: {full_prompt[:500]}...")
|
|
||||||
raise
|
|
||||||
|
|
||||||
def _prepare_prompt(
|
|
||||||
self,
|
|
||||||
template: str,
|
|
||||||
historic_prompts: List[Dict[str, str]],
|
|
||||||
feedback_words: Optional[List[Dict[str, Any]]],
|
|
||||||
count: int,
|
|
||||||
min_length: int,
|
|
||||||
max_length: int
|
|
||||||
) -> str:
|
|
||||||
"""Prepare the full prompt with all context."""
|
|
||||||
# Add the instruction for the specific number of prompts
|
|
||||||
prompt_instruction = f"Please generate {count} writing prompts, each between {min_length} and {max_length} characters."
|
|
||||||
|
|
||||||
# Start with template and instruction
|
|
||||||
full_prompt = f"{template}\n\n{prompt_instruction}"
|
|
||||||
|
|
||||||
# Add historic prompts if available
|
|
||||||
if historic_prompts:
|
|
||||||
historic_context = json.dumps(historic_prompts, indent=2)
|
|
||||||
full_prompt = f"{full_prompt}\n\nPrevious prompts:\n{historic_context}"
|
|
||||||
|
|
||||||
# Add feedback words if available
|
|
||||||
if feedback_words:
|
|
||||||
feedback_context = json.dumps(feedback_words, indent=2)
|
|
||||||
full_prompt = f"{full_prompt}\n\nFeedback words:\n{feedback_context}"
|
|
||||||
|
|
||||||
return full_prompt
|
|
||||||
|
|
||||||
def _parse_prompt_response(self, response_content: str, expected_count: int) -> List[str]:
|
|
||||||
"""Parse AI response to extract prompts."""
|
|
||||||
cleaned_content = self._clean_ai_response(response_content)
|
|
||||||
|
|
||||||
try:
|
|
||||||
data = json.loads(cleaned_content)
|
|
||||||
|
|
||||||
if isinstance(data, list):
|
|
||||||
if len(data) >= expected_count:
|
|
||||||
return data[:expected_count]
|
|
||||||
else:
|
|
||||||
logger.warning(f"AI returned {len(data)} prompts, expected {expected_count}")
|
|
||||||
return data
|
|
||||||
elif isinstance(data, dict):
|
|
||||||
logger.warning("AI returned dictionary format, expected list format")
|
|
||||||
prompts = []
|
|
||||||
for i in range(expected_count):
|
|
||||||
key = f"newprompt{i}"
|
|
||||||
if key in data:
|
|
||||||
prompts.append(data[key])
|
|
||||||
return prompts
|
|
||||||
else:
|
|
||||||
logger.warning(f"AI returned unexpected data type: {type(data)}")
|
|
||||||
return []
|
|
||||||
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
logger.warning("AI response is not valid JSON, attempting to extract prompts...")
|
|
||||||
return self._extract_prompts_from_text(response_content, expected_count)
|
|
||||||
|
|
||||||
def _extract_prompts_from_text(self, text: str, expected_count: int) -> List[str]:
|
|
||||||
"""Extract prompts from plain text response."""
|
|
||||||
lines = text.strip().split('\n')
|
|
||||||
prompts = []
|
|
||||||
|
|
||||||
for line in lines[:expected_count]:
|
|
||||||
line = line.strip()
|
|
||||||
if line and len(line) > 50: # Reasonable minimum length for a prompt
|
|
||||||
prompts.append(line)
|
|
||||||
|
|
||||||
return prompts
|
|
||||||
|
|
||||||
async def generate_theme_feedback_words(
|
|
||||||
self,
|
|
||||||
feedback_template: str,
|
|
||||||
historic_prompts: List[Dict[str, str]],
|
|
||||||
current_feedback_words: Optional[List[Dict[str, Any]]] = None,
|
|
||||||
historic_feedback_words: Optional[List[Dict[str, str]]] = None
|
|
||||||
) -> List[str]:
|
|
||||||
"""
|
|
||||||
Generate theme feedback words using AI.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
feedback_template: Feedback analysis template
|
|
||||||
historic_prompts: List of historic prompts for context
|
|
||||||
current_feedback_words: Current feedback words with weights
|
|
||||||
historic_feedback_words: Historic feedback words (just words)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of 6 theme words
|
|
||||||
"""
|
|
||||||
# Prepare the full prompt
|
|
||||||
full_prompt = self._prepare_feedback_prompt(
|
|
||||||
feedback_template,
|
|
||||||
historic_prompts,
|
|
||||||
current_feedback_words,
|
|
||||||
historic_feedback_words
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info("Generating theme feedback words with AI")
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Call the AI API
|
|
||||||
response = await self.client.chat.completions.create(
|
|
||||||
model=self.model,
|
|
||||||
messages=[
|
|
||||||
{
|
|
||||||
"role": "system",
|
|
||||||
"content": "You are a creative writing assistant that analyzes writing prompts. Always respond with valid JSON."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": full_prompt
|
|
||||||
}
|
|
||||||
],
|
|
||||||
temperature=0.7,
|
|
||||||
max_tokens=1000
|
|
||||||
)
|
|
||||||
|
|
||||||
response_content = response.choices[0].message.content
|
|
||||||
logger.debug(f"AI feedback response received: {len(response_content)} characters")
|
|
||||||
|
|
||||||
# Parse the response
|
|
||||||
theme_words = self._parse_feedback_response(response_content)
|
|
||||||
logger.info(f"Successfully parsed {len(theme_words)} theme words from AI response")
|
|
||||||
|
|
||||||
if len(theme_words) != 6:
|
|
||||||
logger.warning(f"Expected 6 theme words, got {len(theme_words)}")
|
|
||||||
|
|
||||||
return theme_words
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error calling AI API for feedback: {e}")
|
|
||||||
logger.debug(f"Full feedback prompt sent to API: {full_prompt[:500]}...")
|
|
||||||
raise
|
|
||||||
|
|
||||||
def _prepare_feedback_prompt(
|
|
||||||
self,
|
|
||||||
template: str,
|
|
||||||
historic_prompts: List[Dict[str, str]],
|
|
||||||
current_feedback_words: Optional[List[Dict[str, Any]]],
|
|
||||||
historic_feedback_words: Optional[List[Dict[str, str]]]
|
|
||||||
) -> str:
|
|
||||||
"""Prepare the full feedback prompt."""
|
|
||||||
if not historic_prompts:
|
|
||||||
raise ValueError("No historic prompts available for feedback analysis")
|
|
||||||
|
|
||||||
full_prompt = f"{template}\n\nPrevious prompts:\n{json.dumps(historic_prompts, indent=2)}"
|
|
||||||
|
|
||||||
# Add current feedback words if available
|
|
||||||
if current_feedback_words:
|
|
||||||
feedback_context = json.dumps(current_feedback_words, indent=2)
|
|
||||||
full_prompt = f"{full_prompt}\n\nCurrent feedback themes (with weights):\n{feedback_context}"
|
|
||||||
|
|
||||||
# Add historic feedback words if available
|
|
||||||
if historic_feedback_words:
|
|
||||||
feedback_historic_context = json.dumps(historic_feedback_words, indent=2)
|
|
||||||
full_prompt = f"{full_prompt}\n\nHistoric feedback themes (just words):\n{feedback_historic_context}"
|
|
||||||
|
|
||||||
return full_prompt
|
|
||||||
|
|
||||||
def _parse_feedback_response(self, response_content: str) -> List[str]:
|
|
||||||
"""Parse AI response to extract theme words."""
|
|
||||||
cleaned_content = self._clean_ai_response(response_content)
|
|
||||||
|
|
||||||
try:
|
|
||||||
data = json.loads(cleaned_content)
|
|
||||||
|
|
||||||
if isinstance(data, list):
|
|
||||||
theme_words = []
|
|
||||||
for word in data:
|
|
||||||
if isinstance(word, str):
|
|
||||||
theme_words.append(word.lower().strip())
|
|
||||||
else:
|
|
||||||
theme_words.append(str(word).lower().strip())
|
|
||||||
return theme_words
|
|
||||||
else:
|
|
||||||
logger.warning(f"AI returned unexpected data type for feedback: {type(data)}")
|
|
||||||
return []
|
|
||||||
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
logger.warning("AI feedback response is not valid JSON, attempting to extract theme words...")
|
|
||||||
return self._extract_theme_words_from_text(response_content)
|
|
||||||
|
|
||||||
def _extract_theme_words_from_text(self, text: str) -> List[str]:
|
|
||||||
"""Extract theme words from plain text response."""
|
|
||||||
lines = text.strip().split('\n')
|
|
||||||
theme_words = []
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
line = line.strip()
|
|
||||||
if line and len(line) < 50: # Theme words should be short
|
|
||||||
words = [w.lower().strip('.,;:!?()[]{}\"\'') for w in line.split()]
|
|
||||||
theme_words.extend(words)
|
|
||||||
|
|
||||||
if len(theme_words) >= 6:
|
|
||||||
break
|
|
||||||
|
|
||||||
return theme_words[:6]
|
|
||||||
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
"""
|
|
||||||
Data service for handling JSON file operations.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import aiofiles
|
|
||||||
from typing import Any, List, Dict, Optional
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from app.core.config import settings
|
|
||||||
from app.core.logging import setup_logging
|
|
||||||
|
|
||||||
logger = setup_logging()
|
|
||||||
|
|
||||||
|
|
||||||
class DataService:
|
|
||||||
"""Service for handling data persistence in JSON files."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""Initialize data service."""
|
|
||||||
self.data_dir = Path(settings.DATA_DIR)
|
|
||||||
self.data_dir.mkdir(exist_ok=True)
|
|
||||||
|
|
||||||
def _get_file_path(self, filename: str) -> Path:
|
|
||||||
"""Get full path for a data file."""
|
|
||||||
return self.data_dir / filename
|
|
||||||
|
|
||||||
async def load_json(self, filename: str, default: Any = None) -> Any:
|
|
||||||
"""
|
|
||||||
Load JSON data from file.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
filename: Name of the JSON file
|
|
||||||
default: Default value if file doesn't exist or is invalid
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Loaded data or default value
|
|
||||||
"""
|
|
||||||
file_path = self._get_file_path(filename)
|
|
||||||
|
|
||||||
if not file_path.exists():
|
|
||||||
logger.warning(f"File {filename} not found, returning default")
|
|
||||||
return default if default is not None else []
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with aiofiles.open(file_path, 'r', encoding='utf-8') as f:
|
|
||||||
content = await f.read()
|
|
||||||
return json.loads(content)
|
|
||||||
except json.JSONDecodeError as e:
|
|
||||||
logger.error(f"Error decoding JSON from {filename}: {e}")
|
|
||||||
return default if default is not None else []
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error loading {filename}: {e}")
|
|
||||||
return default if default is not None else []
|
|
||||||
|
|
||||||
async def save_json(self, filename: str, data: Any) -> bool:
|
|
||||||
"""
|
|
||||||
Save data to JSON file.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
filename: Name of the JSON file
|
|
||||||
data: Data to save
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
True if successful, False otherwise
|
|
||||||
"""
|
|
||||||
file_path = self._get_file_path(filename)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Create backup of existing file if it exists
|
|
||||||
if file_path.exists():
|
|
||||||
backup_path = file_path.with_suffix('.json.bak')
|
|
||||||
async with aiofiles.open(file_path, 'r', encoding='utf-8') as src:
|
|
||||||
async with aiofiles.open(backup_path, 'w', encoding='utf-8') as dst:
|
|
||||||
await dst.write(await src.read())
|
|
||||||
|
|
||||||
# Save new data
|
|
||||||
async with aiofiles.open(file_path, 'w', encoding='utf-8') as f:
|
|
||||||
await f.write(json.dumps(data, indent=2, ensure_ascii=False))
|
|
||||||
|
|
||||||
logger.info(f"Saved data to {filename}")
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error saving {filename}: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def load_prompts_historic(self) -> List[Dict[str, str]]:
|
|
||||||
"""Load historic prompts from JSON file."""
|
|
||||||
return await self.load_json(
|
|
||||||
settings.PROMPTS_HISTORIC_FILE,
|
|
||||||
default=[]
|
|
||||||
)
|
|
||||||
|
|
||||||
async def save_prompts_historic(self, prompts: List[Dict[str, str]]) -> bool:
|
|
||||||
"""Save historic prompts to JSON file."""
|
|
||||||
return await self.save_json(settings.PROMPTS_HISTORIC_FILE, prompts)
|
|
||||||
|
|
||||||
async def load_prompts_pool(self) -> List[str]:
|
|
||||||
"""Load prompt pool from JSON file."""
|
|
||||||
return await self.load_json(
|
|
||||||
settings.PROMPTS_POOL_FILE,
|
|
||||||
default=[]
|
|
||||||
)
|
|
||||||
|
|
||||||
async def save_prompts_pool(self, prompts: List[str]) -> bool:
|
|
||||||
"""Save prompt pool to JSON file."""
|
|
||||||
return await self.save_json(settings.PROMPTS_POOL_FILE, prompts)
|
|
||||||
|
|
||||||
async def load_feedback_words(self) -> List[Dict[str, Any]]:
|
|
||||||
"""Load feedback words from JSON file."""
|
|
||||||
return await self.load_json(
|
|
||||||
settings.FEEDBACK_WORDS_FILE,
|
|
||||||
default=[]
|
|
||||||
)
|
|
||||||
|
|
||||||
async def save_feedback_words(self, feedback_words: List[Dict[str, Any]]) -> bool:
|
|
||||||
"""Save feedback words to JSON file."""
|
|
||||||
return await self.save_json(settings.FEEDBACK_WORDS_FILE, feedback_words)
|
|
||||||
|
|
||||||
async def load_feedback_historic(self) -> List[Dict[str, str]]:
|
|
||||||
"""Load historic feedback words from JSON file."""
|
|
||||||
return await self.load_json(
|
|
||||||
settings.FEEDBACK_HISTORIC_FILE,
|
|
||||||
default=[]
|
|
||||||
)
|
|
||||||
|
|
||||||
async def save_feedback_historic(self, feedback_words: List[Dict[str, str]]) -> bool:
|
|
||||||
"""Save historic feedback words to JSON file."""
|
|
||||||
return await self.save_json(settings.FEEDBACK_HISTORIC_FILE, feedback_words)
|
|
||||||
|
|
||||||
async def load_prompt_template(self) -> str:
|
|
||||||
"""Load prompt template from file."""
|
|
||||||
template_path = Path(settings.PROMPT_TEMPLATE_PATH)
|
|
||||||
if not template_path.exists():
|
|
||||||
logger.error(f"Prompt template not found at {template_path}")
|
|
||||||
return ""
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with aiofiles.open(template_path, 'r', encoding='utf-8') as f:
|
|
||||||
return await f.read()
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error loading prompt template: {e}")
|
|
||||||
return ""
|
|
||||||
|
|
||||||
async def load_feedback_template(self) -> str:
|
|
||||||
"""Load feedback template from file."""
|
|
||||||
template_path = Path(settings.FEEDBACK_TEMPLATE_PATH)
|
|
||||||
if not template_path.exists():
|
|
||||||
logger.error(f"Feedback template not found at {template_path}")
|
|
||||||
return ""
|
|
||||||
|
|
||||||
try:
|
|
||||||
async with aiofiles.open(template_path, 'r', encoding='utf-8') as f:
|
|
||||||
return await f.read()
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error loading feedback template: {e}")
|
|
||||||
return ""
|
|
||||||
|
|
||||||
async def load_settings_config(self) -> Dict[str, Any]:
|
|
||||||
"""Load settings from config file."""
|
|
||||||
config_path = Path(settings.SETTINGS_CONFIG_PATH)
|
|
||||||
if not config_path.exists():
|
|
||||||
logger.warning(f"Settings config not found at {config_path}")
|
|
||||||
return {}
|
|
||||||
|
|
||||||
try:
|
|
||||||
import configparser
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read(config_path)
|
|
||||||
|
|
||||||
settings_dict = {}
|
|
||||||
if 'prompts' in config:
|
|
||||||
prompts_section = config['prompts']
|
|
||||||
settings_dict['min_length'] = int(prompts_section.get('min_length', settings.MIN_PROMPT_LENGTH))
|
|
||||||
settings_dict['max_length'] = int(prompts_section.get('max_length', settings.MAX_PROMPT_LENGTH))
|
|
||||||
settings_dict['num_prompts'] = int(prompts_section.get('num_prompts', settings.NUM_PROMPTS_PER_SESSION))
|
|
||||||
|
|
||||||
if 'prefetch' in config:
|
|
||||||
prefetch_section = config['prefetch']
|
|
||||||
settings_dict['cached_pool_volume'] = int(prefetch_section.get('cached_pool_volume', settings.CACHED_POOL_VOLUME))
|
|
||||||
|
|
||||||
return settings_dict
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error loading settings config: {e}")
|
|
||||||
return {}
|
|
||||||
|
|
||||||
@@ -1,416 +0,0 @@
|
|||||||
"""
|
|
||||||
Main prompt service that orchestrates prompt generation and management.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import List, Dict, Any, Optional
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from app.core.config import settings
|
|
||||||
from app.core.logging import setup_logging
|
|
||||||
from app.services.data_service import DataService
|
|
||||||
from app.services.ai_service import AIService
|
|
||||||
from app.models.prompt import (
|
|
||||||
PromptResponse,
|
|
||||||
PoolStatsResponse,
|
|
||||||
HistoryStatsResponse,
|
|
||||||
FeedbackWord,
|
|
||||||
FeedbackHistoryItem
|
|
||||||
)
|
|
||||||
|
|
||||||
logger = setup_logging()
|
|
||||||
|
|
||||||
|
|
||||||
class PromptService:
|
|
||||||
"""Main service for prompt generation and management."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""Initialize prompt service with dependencies."""
|
|
||||||
self.data_service = DataService()
|
|
||||||
self.ai_service = AIService()
|
|
||||||
|
|
||||||
# Load settings from config file
|
|
||||||
self.settings_config = {}
|
|
||||||
|
|
||||||
# Cache for loaded data
|
|
||||||
self._prompts_historic_cache = None
|
|
||||||
self._prompts_pool_cache = None
|
|
||||||
self._feedback_words_cache = None
|
|
||||||
self._feedback_historic_cache = None
|
|
||||||
self._prompt_template_cache = None
|
|
||||||
self._feedback_template_cache = None
|
|
||||||
|
|
||||||
async def _load_settings_config(self):
|
|
||||||
"""Load settings from config file if not already loaded."""
|
|
||||||
if not self.settings_config:
|
|
||||||
self.settings_config = await self.data_service.load_settings_config()
|
|
||||||
|
|
||||||
async def _get_setting(self, key: str, default: Any) -> Any:
|
|
||||||
"""Get setting value, preferring config file over environment."""
|
|
||||||
await self._load_settings_config()
|
|
||||||
return self.settings_config.get(key, default)
|
|
||||||
|
|
||||||
# Data loading methods with caching
|
|
||||||
async def get_prompts_historic(self) -> List[Dict[str, str]]:
|
|
||||||
"""Get historic prompts with caching."""
|
|
||||||
if self._prompts_historic_cache is None:
|
|
||||||
self._prompts_historic_cache = await self.data_service.load_prompts_historic()
|
|
||||||
return self._prompts_historic_cache
|
|
||||||
|
|
||||||
async def get_prompts_pool(self) -> List[str]:
|
|
||||||
"""Get prompt pool with caching."""
|
|
||||||
if self._prompts_pool_cache is None:
|
|
||||||
self._prompts_pool_cache = await self.data_service.load_prompts_pool()
|
|
||||||
return self._prompts_pool_cache
|
|
||||||
|
|
||||||
async def get_feedback_words(self) -> List[Dict[str, Any]]:
|
|
||||||
"""Get feedback words with caching."""
|
|
||||||
if self._feedback_words_cache is None:
|
|
||||||
self._feedback_words_cache = await self.data_service.load_feedback_words()
|
|
||||||
return self._feedback_words_cache
|
|
||||||
|
|
||||||
async def get_feedback_historic(self) -> List[Dict[str, str]]:
|
|
||||||
"""Get historic feedback words with caching."""
|
|
||||||
if self._feedback_historic_cache is None:
|
|
||||||
self._feedback_historic_cache = await self.data_service.load_feedback_historic()
|
|
||||||
return self._feedback_historic_cache
|
|
||||||
|
|
||||||
async def get_prompt_template(self) -> str:
|
|
||||||
"""Get prompt template with caching."""
|
|
||||||
if self._prompt_template_cache is None:
|
|
||||||
self._prompt_template_cache = await self.data_service.load_prompt_template()
|
|
||||||
return self._prompt_template_cache
|
|
||||||
|
|
||||||
async def get_feedback_template(self) -> str:
|
|
||||||
"""Get feedback template with caching."""
|
|
||||||
if self._feedback_template_cache is None:
|
|
||||||
self._feedback_template_cache = await self.data_service.load_feedback_template()
|
|
||||||
return self._feedback_template_cache
|
|
||||||
|
|
||||||
# Core prompt operations
|
|
||||||
async def draw_prompts_from_pool(self, count: Optional[int] = None) -> List[str]:
|
|
||||||
"""
|
|
||||||
Draw prompts from the pool.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
count: Number of prompts to draw
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of drawn prompts
|
|
||||||
"""
|
|
||||||
if count is None:
|
|
||||||
count = await self._get_setting('num_prompts', settings.NUM_PROMPTS_PER_SESSION)
|
|
||||||
|
|
||||||
pool = await self.get_prompts_pool()
|
|
||||||
|
|
||||||
if len(pool) < count:
|
|
||||||
raise ValueError(
|
|
||||||
f"Pool only has {len(pool)} prompts, requested {count}. "
|
|
||||||
f"Use fill-pool endpoint to add more prompts."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Draw prompts from the beginning of the pool
|
|
||||||
drawn_prompts = pool[:count]
|
|
||||||
remaining_pool = pool[count:]
|
|
||||||
|
|
||||||
# Update cache and save
|
|
||||||
self._prompts_pool_cache = remaining_pool
|
|
||||||
await self.data_service.save_prompts_pool(remaining_pool)
|
|
||||||
|
|
||||||
logger.info(f"Drew {len(drawn_prompts)} prompts from pool, {len(remaining_pool)} remaining")
|
|
||||||
return drawn_prompts
|
|
||||||
|
|
||||||
async def fill_pool_to_target(self) -> int:
|
|
||||||
"""
|
|
||||||
Fill the prompt pool to target volume.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Number of prompts added
|
|
||||||
"""
|
|
||||||
target_volume = await self._get_setting('cached_pool_volume', settings.CACHED_POOL_VOLUME)
|
|
||||||
current_pool = await self.get_prompts_pool()
|
|
||||||
current_size = len(current_pool)
|
|
||||||
|
|
||||||
if current_size >= target_volume:
|
|
||||||
logger.info(f"Pool already at target volume: {current_size}/{target_volume}")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
prompts_needed = target_volume - current_size
|
|
||||||
logger.info(f"Generating {prompts_needed} prompts to fill pool")
|
|
||||||
|
|
||||||
# Generate prompts
|
|
||||||
new_prompts = await self.generate_prompts(
|
|
||||||
count=prompts_needed,
|
|
||||||
use_history=True,
|
|
||||||
use_feedback=True
|
|
||||||
)
|
|
||||||
|
|
||||||
if not new_prompts:
|
|
||||||
logger.error("Failed to generate prompts for pool")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# Add to pool
|
|
||||||
updated_pool = current_pool + new_prompts
|
|
||||||
self._prompts_pool_cache = updated_pool
|
|
||||||
await self.data_service.save_prompts_pool(updated_pool)
|
|
||||||
|
|
||||||
added_count = len(new_prompts)
|
|
||||||
logger.info(f"Added {added_count} prompts to pool, new size: {len(updated_pool)}")
|
|
||||||
return added_count
|
|
||||||
|
|
||||||
async def generate_prompts(
|
|
||||||
self,
|
|
||||||
count: Optional[int] = None,
|
|
||||||
use_history: bool = True,
|
|
||||||
use_feedback: bool = True
|
|
||||||
) -> List[str]:
|
|
||||||
"""
|
|
||||||
Generate new prompts using AI.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
count: Number of prompts to generate
|
|
||||||
use_history: Whether to use historic prompts as context
|
|
||||||
use_feedback: Whether to use feedback words as context
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of generated prompts
|
|
||||||
"""
|
|
||||||
if count is None:
|
|
||||||
count = await self._get_setting('num_prompts', settings.NUM_PROMPTS_PER_SESSION)
|
|
||||||
|
|
||||||
min_length = await self._get_setting('min_length', settings.MIN_PROMPT_LENGTH)
|
|
||||||
max_length = await self._get_setting('max_length', settings.MAX_PROMPT_LENGTH)
|
|
||||||
|
|
||||||
# Load templates and data
|
|
||||||
prompt_template = await self.get_prompt_template()
|
|
||||||
if not prompt_template:
|
|
||||||
raise ValueError("Prompt template not found")
|
|
||||||
|
|
||||||
historic_prompts = await self.get_prompts_historic() if use_history else []
|
|
||||||
feedback_words = await self.get_feedback_words() if use_feedback else None
|
|
||||||
|
|
||||||
# Generate prompts using AI
|
|
||||||
new_prompts = await self.ai_service.generate_prompts(
|
|
||||||
prompt_template=prompt_template,
|
|
||||||
historic_prompts=historic_prompts,
|
|
||||||
feedback_words=feedback_words,
|
|
||||||
count=count,
|
|
||||||
min_length=min_length,
|
|
||||||
max_length=max_length
|
|
||||||
)
|
|
||||||
|
|
||||||
return new_prompts
|
|
||||||
|
|
||||||
async def add_prompt_to_history(self, prompt_text: str) -> str:
|
|
||||||
"""
|
|
||||||
Add a prompt to the historic prompts cyclic buffer.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
prompt_text: Prompt text to add
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Position key of the added prompt (e.g., "prompt00")
|
|
||||||
"""
|
|
||||||
historic_prompts = await self.get_prompts_historic()
|
|
||||||
|
|
||||||
# Create the new prompt object
|
|
||||||
new_prompt = {"prompt00": prompt_text}
|
|
||||||
|
|
||||||
# Shift all existing prompts down by one position
|
|
||||||
updated_prompts = [new_prompt]
|
|
||||||
|
|
||||||
# Add all existing prompts, shifting their numbers down by one
|
|
||||||
for i, prompt_dict in enumerate(historic_prompts):
|
|
||||||
if i >= settings.HISTORY_BUFFER_SIZE - 1: # Keep only HISTORY_BUFFER_SIZE prompts
|
|
||||||
break
|
|
||||||
|
|
||||||
# Get the prompt text
|
|
||||||
prompt_key = list(prompt_dict.keys())[0]
|
|
||||||
prompt_text = prompt_dict[prompt_key]
|
|
||||||
|
|
||||||
# Create prompt with new number (shifted down by one)
|
|
||||||
new_prompt_key = f"prompt{i+1:02d}"
|
|
||||||
updated_prompts.append({new_prompt_key: prompt_text})
|
|
||||||
|
|
||||||
# Update cache and save
|
|
||||||
self._prompts_historic_cache = updated_prompts
|
|
||||||
await self.data_service.save_prompts_historic(updated_prompts)
|
|
||||||
|
|
||||||
logger.info(f"Added prompt to history as prompt00, history size: {len(updated_prompts)}")
|
|
||||||
return "prompt00"
|
|
||||||
|
|
||||||
# Statistics methods
|
|
||||||
async def get_pool_stats(self) -> PoolStatsResponse:
|
|
||||||
"""Get statistics about the prompt pool."""
|
|
||||||
pool = await self.get_prompts_pool()
|
|
||||||
total_prompts = len(pool)
|
|
||||||
|
|
||||||
prompts_per_session = await self._get_setting('num_prompts', settings.NUM_PROMPTS_PER_SESSION)
|
|
||||||
target_pool_size = await self._get_setting('cached_pool_volume', settings.CACHED_POOL_VOLUME)
|
|
||||||
|
|
||||||
available_sessions = total_prompts // prompts_per_session if prompts_per_session > 0 else 0
|
|
||||||
needs_refill = total_prompts < target_pool_size
|
|
||||||
|
|
||||||
return PoolStatsResponse(
|
|
||||||
total_prompts=total_prompts,
|
|
||||||
prompts_per_session=prompts_per_session,
|
|
||||||
target_pool_size=target_pool_size,
|
|
||||||
available_sessions=available_sessions,
|
|
||||||
needs_refill=needs_refill
|
|
||||||
)
|
|
||||||
|
|
||||||
async def get_history_stats(self) -> HistoryStatsResponse:
|
|
||||||
"""Get statistics about prompt history."""
|
|
||||||
historic_prompts = await self.get_prompts_historic()
|
|
||||||
total_prompts = len(historic_prompts)
|
|
||||||
|
|
||||||
history_capacity = settings.HISTORY_BUFFER_SIZE
|
|
||||||
available_slots = max(0, history_capacity - total_prompts)
|
|
||||||
is_full = total_prompts >= history_capacity
|
|
||||||
|
|
||||||
return HistoryStatsResponse(
|
|
||||||
total_prompts=total_prompts,
|
|
||||||
history_capacity=history_capacity,
|
|
||||||
available_slots=available_slots,
|
|
||||||
is_full=is_full
|
|
||||||
)
|
|
||||||
|
|
||||||
async def get_prompt_history(self, limit: Optional[int] = None) -> List[PromptResponse]:
|
|
||||||
"""
|
|
||||||
Get prompt history.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
limit: Maximum number of history items to return
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of historical prompts
|
|
||||||
"""
|
|
||||||
historic_prompts = await self.get_prompts_historic()
|
|
||||||
|
|
||||||
if limit is not None:
|
|
||||||
historic_prompts = historic_prompts[:limit]
|
|
||||||
|
|
||||||
prompts = []
|
|
||||||
for i, prompt_dict in enumerate(historic_prompts):
|
|
||||||
prompt_key = list(prompt_dict.keys())[0]
|
|
||||||
prompt_text = prompt_dict[prompt_key]
|
|
||||||
|
|
||||||
prompts.append(PromptResponse(
|
|
||||||
key=prompt_key,
|
|
||||||
text=prompt_text,
|
|
||||||
position=i
|
|
||||||
))
|
|
||||||
|
|
||||||
return prompts
|
|
||||||
|
|
||||||
# Feedback operations
|
|
||||||
async def generate_theme_feedback_words(self) -> List[str]:
|
|
||||||
"""Generate 6 theme feedback words using AI."""
|
|
||||||
feedback_template = await self.get_feedback_template()
|
|
||||||
if not feedback_template:
|
|
||||||
raise ValueError("Feedback template not found")
|
|
||||||
|
|
||||||
historic_prompts = await self.get_prompts_historic()
|
|
||||||
if not historic_prompts:
|
|
||||||
raise ValueError("No historic prompts available for feedback analysis")
|
|
||||||
|
|
||||||
current_feedback_words = await self.get_feedback_words()
|
|
||||||
historic_feedback_words = await self.get_feedback_historic()
|
|
||||||
|
|
||||||
theme_words = await self.ai_service.generate_theme_feedback_words(
|
|
||||||
feedback_template=feedback_template,
|
|
||||||
historic_prompts=historic_prompts,
|
|
||||||
current_feedback_words=current_feedback_words,
|
|
||||||
historic_feedback_words=historic_feedback_words
|
|
||||||
)
|
|
||||||
|
|
||||||
return theme_words
|
|
||||||
|
|
||||||
async def update_feedback_words(self, ratings: Dict[str, int]) -> List[FeedbackWord]:
|
|
||||||
"""
|
|
||||||
Update feedback words with new ratings.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
ratings: Dictionary of word to rating (0-6)
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Updated feedback words
|
|
||||||
"""
|
|
||||||
if len(ratings) != 6:
|
|
||||||
raise ValueError(f"Expected 6 ratings, got {len(ratings)}")
|
|
||||||
|
|
||||||
feedback_items = []
|
|
||||||
for i, (word, rating) in enumerate(ratings.items()):
|
|
||||||
if not 0 <= rating <= 6:
|
|
||||||
raise ValueError(f"Rating for '{word}' must be between 0 and 6, got {rating}")
|
|
||||||
|
|
||||||
feedback_key = f"feedback{i:02d}"
|
|
||||||
feedback_items.append({
|
|
||||||
feedback_key: word,
|
|
||||||
"weight": rating
|
|
||||||
})
|
|
||||||
|
|
||||||
# Update cache and save
|
|
||||||
self._feedback_words_cache = feedback_items
|
|
||||||
await self.data_service.save_feedback_words(feedback_items)
|
|
||||||
|
|
||||||
# Also add to historic feedback
|
|
||||||
await self._add_feedback_words_to_history(feedback_items)
|
|
||||||
|
|
||||||
# Convert to FeedbackWord models
|
|
||||||
feedback_words = []
|
|
||||||
for item in feedback_items:
|
|
||||||
key = list(item.keys())[0]
|
|
||||||
word = item[key]
|
|
||||||
weight = item["weight"]
|
|
||||||
feedback_words.append(FeedbackWord(key=key, word=word, weight=weight))
|
|
||||||
|
|
||||||
logger.info(f"Updated feedback words with {len(feedback_words)} items")
|
|
||||||
return feedback_words
|
|
||||||
|
|
||||||
async def _add_feedback_words_to_history(self, feedback_items: List[Dict[str, Any]]) -> None:
|
|
||||||
"""Add feedback words to historic buffer."""
|
|
||||||
historic_feedback = await self.get_feedback_historic()
|
|
||||||
|
|
||||||
# Extract just the words from current feedback
|
|
||||||
new_feedback_words = []
|
|
||||||
for i, item in enumerate(feedback_items):
|
|
||||||
feedback_key = f"feedback{i:02d}"
|
|
||||||
if feedback_key in item:
|
|
||||||
word = item[feedback_key]
|
|
||||||
new_feedback_words.append({feedback_key: word})
|
|
||||||
|
|
||||||
if len(new_feedback_words) != 6:
|
|
||||||
logger.warning(f"Expected 6 feedback words, got {len(new_feedback_words)}. Not adding to history.")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Shift all existing feedback words down by 6 positions
|
|
||||||
updated_feedback_historic = new_feedback_words
|
|
||||||
|
|
||||||
# Add all existing feedback words, shifting their numbers down by 6
|
|
||||||
for i, feedback_dict in enumerate(historic_feedback):
|
|
||||||
if i >= settings.FEEDBACK_HISTORY_SIZE - 6: # Keep only FEEDBACK_HISTORY_SIZE items
|
|
||||||
break
|
|
||||||
|
|
||||||
feedback_key = list(feedback_dict.keys())[0]
|
|
||||||
word = feedback_dict[feedback_key]
|
|
||||||
|
|
||||||
new_feedback_key = f"feedback{i+6:02d}"
|
|
||||||
updated_feedback_historic.append({new_feedback_key: word})
|
|
||||||
|
|
||||||
# Update cache and save
|
|
||||||
self._feedback_historic_cache = updated_feedback_historic
|
|
||||||
await self.data_service.save_feedback_historic(updated_feedback_historic)
|
|
||||||
|
|
||||||
logger.info(f"Added 6 feedback words to history, history size: {len(updated_feedback_historic)}")
|
|
||||||
|
|
||||||
# Utility methods for API endpoints
|
|
||||||
def get_pool_size(self) -> int:
|
|
||||||
"""Get current pool size (synchronous for API endpoints)."""
|
|
||||||
if self._prompts_pool_cache is None:
|
|
||||||
raise RuntimeError("Pool cache not initialized")
|
|
||||||
return len(self._prompts_pool_cache)
|
|
||||||
|
|
||||||
def get_target_volume(self) -> int:
|
|
||||||
"""Get target pool volume (synchronous for API endpoints)."""
|
|
||||||
return settings.CACHED_POOL_VOLUME
|
|
||||||
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
"""
|
|
||||||
Daily Journal Prompt Generator - FastAPI Backend
|
|
||||||
Main application entry point
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
|
||||||
from contextlib import asynccontextmanager
|
|
||||||
|
|
||||||
from app.api.v1.api import api_router
|
|
||||||
from app.core.config import settings
|
|
||||||
from app.core.logging import setup_logging
|
|
||||||
from app.core.exception_handlers import setup_exception_handlers
|
|
||||||
|
|
||||||
# Setup logging
|
|
||||||
logger = setup_logging()
|
|
||||||
|
|
||||||
@asynccontextmanager
|
|
||||||
async def lifespan(app: FastAPI):
|
|
||||||
"""Lifespan context manager for startup and shutdown events."""
|
|
||||||
# Startup
|
|
||||||
logger.info("Starting Daily Journal Prompt Generator API")
|
|
||||||
logger.info(f"Environment: {settings.ENVIRONMENT}")
|
|
||||||
logger.info(f"Debug mode: {settings.DEBUG}")
|
|
||||||
|
|
||||||
# Create data directory if it doesn't exist
|
|
||||||
data_dir = Path(settings.DATA_DIR)
|
|
||||||
data_dir.mkdir(exist_ok=True)
|
|
||||||
logger.info(f"Data directory: {data_dir.absolute()}")
|
|
||||||
|
|
||||||
yield
|
|
||||||
|
|
||||||
# Shutdown
|
|
||||||
logger.info("Shutting down Daily Journal Prompt Generator API")
|
|
||||||
|
|
||||||
# Create FastAPI app
|
|
||||||
app = FastAPI(
|
|
||||||
title="Daily Journal Prompt Generator API",
|
|
||||||
description="API for generating and managing journal writing prompts",
|
|
||||||
version="1.0.0",
|
|
||||||
docs_url="/docs",
|
|
||||||
redoc_url="/redoc",
|
|
||||||
lifespan=lifespan
|
|
||||||
)
|
|
||||||
|
|
||||||
# Setup exception handlers
|
|
||||||
setup_exception_handlers(app)
|
|
||||||
|
|
||||||
# Configure CORS
|
|
||||||
if settings.BACKEND_CORS_ORIGINS:
|
|
||||||
app.add_middleware(
|
|
||||||
CORSMiddleware,
|
|
||||||
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
|
|
||||||
allow_credentials=True,
|
|
||||||
allow_methods=["*"],
|
|
||||||
allow_headers=["*"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Include API router
|
|
||||||
app.include_router(api_router, prefix="/api/v1")
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
async def root():
|
|
||||||
"""Root endpoint with API information."""
|
|
||||||
return {
|
|
||||||
"name": "Daily Journal Prompt Generator API",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "API for generating and managing journal writing prompts",
|
|
||||||
"docs": "/docs",
|
|
||||||
"redoc": "/redoc",
|
|
||||||
"health": "/health"
|
|
||||||
}
|
|
||||||
|
|
||||||
@app.get("/health")
|
|
||||||
async def health_check():
|
|
||||||
"""Health check endpoint."""
|
|
||||||
return {"status": "healthy", "service": "daily-journal-prompt-api"}
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import uvicorn
|
|
||||||
uvicorn.run(
|
|
||||||
"main:app",
|
|
||||||
host=settings.HOST,
|
|
||||||
port=settings.PORT,
|
|
||||||
reload=settings.DEBUG,
|
|
||||||
log_level="info"
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
fastapi>=0.104.0
|
|
||||||
uvicorn[standard]>=0.24.0
|
|
||||||
pydantic>=2.0.0
|
|
||||||
pydantic-settings>=2.0.0
|
|
||||||
python-dotenv>=1.0.0
|
|
||||||
openai>=1.0.0
|
|
||||||
aiofiles>=23.0.0
|
|
||||||
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
Request for generation of writing prompts for journaling
|
|
||||||
|
|
||||||
Payload:
|
|
||||||
The previous 60 prompts have been provided as a JSON array for reference.
|
|
||||||
The current 6 feedback themes have been provided. You will not re-use any of these most-recently used words here.
|
|
||||||
The previous 30 feedback themes are also provided. You should try to avoid re-using these unless it really makes sense to.
|
|
||||||
|
|
||||||
Guidelines:
|
|
||||||
Using the attached JSON of writing prompts, you should try to pick out 4 unique and intentionally vague single-word themes that apply to some portion of the list. They can range from common to uncommon words.
|
|
||||||
Then add 2 more single word divergent themes that are less related to the historic prompts and are somewhat different from the other 4 for a total of 6 words.
|
|
||||||
These 2 divergent themes give the user the option to steer away from existing themes.
|
|
||||||
Examples for the divergent themes could be the option to add a theme like technology when the other themes are related to beauty, or mortality when the other themes are very positive.
|
|
||||||
Be creative, don't just use my example.
|
|
||||||
A very high temperature AI response is warranted here to generate a large vocabulary.
|
|
||||||
|
|
||||||
Expected Output:
|
|
||||||
Output as a JSON list with just the six words, in lowercase.
|
|
||||||
Despite the provided history being a keyed list or dictionary, the expected return JSON will be a simple list with no keys.
|
|
||||||
Respond ONLY with valid JSON. No explanations, no markdown, no backticks.
|
|
||||||
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
Request for generation of writing prompts for journaling
|
|
||||||
|
|
||||||
Payload:
|
|
||||||
The previous 60 prompts have been provided as a JSON array for reference.
|
|
||||||
Some vague feedback themes have been provided, each having a weight value from 0 to 6.
|
|
||||||
|
|
||||||
Guidelines:
|
|
||||||
Please generate some number of individual writing prompts in English following these guidelines.
|
|
||||||
Topics can be diverse, and the whole batch should have no outright repetition.
|
|
||||||
These are meant to inspire one to two pages of writing in a journal as exercise.
|
|
||||||
|
|
||||||
Prompt History:
|
|
||||||
The provided history brackets two mechanisms.
|
|
||||||
The history will allow for reducing repetition, however some thematic overlap is acceptable. Try harder to avoid overlap with lower indices in the array.
|
|
||||||
As the user discards prompts, the themes will be very slowly steered, so it's okay to take some inspiration from the history.
|
|
||||||
|
|
||||||
Feedback Themes:
|
|
||||||
A JSON of single-word feedback themes is provided with each having a weight value from 0 to 6.
|
|
||||||
Consider these weighted themes only rarely when creating a new writing prompt. Most prompts should be created with full creative freedom.
|
|
||||||
Only gently influence writing prompts with these. It is better to have all generated prompts ignore a theme than have many reference a theme overtly.
|
|
||||||
|
|
||||||
Expected Output:
|
|
||||||
Output as a JSON list with the requested number of elements.
|
|
||||||
Despite the provided history being a keyed list or dictionary, the expected return JSON will be a simple list with no keys.
|
|
||||||
Respond ONLY with valid JSON. No explanations, no markdown, no backticks.
|
|
||||||
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"feedback00": "labyrinth"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback01": "residue"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback02": "tremor"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback03": "effigy"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback04": "quasar"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback05": "gossamer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback06": "resonance"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback07": "erosion"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback08": "surrender"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback09": "excess"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback10": "chaos"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback11": "fabric"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback12": "palimpsest"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback13": "lacuna"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback14": "efflorescence"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback15": "tessellation"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback16": "sublimation"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback17": "vertigo"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback18": "artifact"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback19": "mycelium"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback20": "threshold"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback21": "cartography"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback22": "spectacle"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback23": "friction"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback24": "mutation"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback25": "echo"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback26": "repair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback27": "velocity"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback28": "syntax"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback29": "divergence"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"feedback00": "labyrinth",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback01": "residue",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback02": "tremor",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback03": "effigy",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback04": "quasar",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback05": "gossamer",
|
|
||||||
"weight": 3
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"prompt00": "Imagine your childhood home has a secret room you never discovered. Describe what you imagine is inside. Is it a treasure trove of forgotten toys? A dusty library of family secrets? A perfectly preserved moment from a specific day? Now, as an adult, write about what you would hope to find there, and what that hope reveals about your relationship to your own past."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt01": "You discover a box of old keys. None are labeled. Describe their shapes, weights, and the sounds they make. Speculate on the doors, cabinets, or diaries they once unlocked. Choose one key and imagine the specific, significant thing it secured. Now, imagine throwing them all away, accepting that those locks will remain forever closed. Write about the liberation and the loss in that act of relinquishment."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt02": "Find a source of natural, repetitive sound—rain on a roof, waves on a shore, wind in leaves. Listen until the sound ceases to be 'noise' and becomes a pattern, a rhythm, a form of silence. Describe the moment your perception shifted. What thoughts or memories surfaced in the space created by this hypnotic auditory pattern? Write about the meditation inherent in repetition."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt03": "Describe a local landmark you've passed countless times but never truly examined—a statue, an old sign, a peculiar tree. Stop and study it for fifteen minutes. Record every detail, every crack, every stain. Now, research or imagine its history. How does this deep looking transform an invisible part of your landscape into a character with a story?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt04": "Test prompt for adding to history"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt05": "Choose a common phrase you use often (e.g., \"I'm fine,\" \"Just a minute,\" \"Don't worry about it\"). Dissect it. What does it truly mean when you say it? What does it conceal? What convenience does it provide? Now, for one day, vow not to use it. Chronicle the conversations that become longer, more awkward, or more honest as a result."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt06": "Recall a time you received a gift that was perfectly, inexplicably right for you. Describe the gift and the giver. What made it so resonant? Was it an understanding of a secret wish, a reflection of an unseen part of you, or a tool you didn't know you needed? Explore the magic of being seen and understood through the medium of an object."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt07": "Map a friendship as a shared garden. What did each of you plant in the initial soil? What has grown wild? What requires regular tending? Have there been seasons of drought or frost? Are there any beautiful, stubborn weeds? Write a gardener's diary entry about the current state of this plot, reflecting on its history and future."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt08": "Describe a skill you have that is entirely non-verbal—perhaps riding a bike, kneading dough, tuning an instrument by ear. Attempt to write a manual for this skill using only metaphors and physical sensations. Avoid technical terms. Can you translate embodied knowledge into prose? What is lost, and what is poetically gained?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt09": "Recall a scent that acts as a master key, unlocking a flood of specific, detailed memories. Describe the scent in non-scent words: is it sharp, round, velvety, brittle? Now, follow the key into the memory palace it opens. Don't just describe the memory; describe the architecture of the connection itself. How is scent wired so directly to the past?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt10": "Imagine you are a translator for a species that communicates through subtle shifts in temperature. Describe a recent emotional experience as a thermal map. Where in your body did the warmth of joy concentrate? Where did the cold front of anxiety settle? How would you translate this silent, somatic language into words for someone who only understands degrees and gradients?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt11": "Find a surface covered in a fine layer of dust—a windowsill, an old book, a forgotten picture frame. Describe this 'residue' of time and neglect. What stories does the pattern of settlement tell? Write about the act of wiping it away. Is it an erasure of history or a renewal? What clean surface is revealed, and does it feel like a loss or a gain?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt12": "Build a 'gossamer' bridge in your mind between two seemingly disconnected concepts: for example, baking bread and forgiveness, or traffic patterns and anxiety. Describe the fragile, translucent strands of logic or metaphor you use to connect them. Walk across this bridge. What new landscape do you find on the other side? Does the bridge hold, or dissolve after use?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt13": "Map a personal 'labyrinth' of procrastination or avoidance. What are its enticing entryways (\"I'll just check...\")? Its circular corridors of rationalization? Its terrifying center (the task itself)? Describe one recent journey into this maze. What finally provided the thread to lead you out, or what made you decide to sit in the center and confront the Minotaur?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt14": "Craft a mental 'effigy' of a piece of advice you were given that you've chosen to ignore. Give it form and substance. Do you keep it on a shelf, bury it, or ritually dismantle it? Write about the act of holding this representation of rejected wisdom. Does making it concrete help you understand your refusal, or simply honor the intention of the giver?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt15": "Recall a decision point that felt like standing at the mouth of a 'labyrinth,' with multiple winding paths ahead. Describe the initial confusion and the method you used to choose an entrance (logic, intuition, chance). Now, with hindsight, map the path you actually took. Were there dead ends or unexpected centers? Did the labyrinth lead you out, or deeper into understanding?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt16": "Contemplate a 'quasar'—an immensely luminous, distant celestial object. Use it as a metaphor for a source of guidance or inspiration in your life that feels both incredibly powerful and remote. Who or what is this distant beacon? Describe the 'light' it emits and the long journey it takes to reach you. How do you navigate by this ancient, brilliant, but fundamentally untouchable signal?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt17": "Describe a piece of music that left a 'residue' in your mind—a melody that loops unbidden, a lyric that sticks, a rhythm that syncs with your heartbeat. How does this auditory artifact resurface during quiet moments? What emotional or memory-laden dust has it collected? Write about the process of this mental replay, and whether you seek to amplify it or gently brush it away."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt18": "Recall a 'failed' experiment from your past—a recipe that flopped, a project abandoned, a relationship that didn't work. Instead of framing it as a mistake, analyze it as a valuable trial that produced data. What did you learn about the materials, the process, or yourself? How did the outcome diverge from your hypothesis? Write a lab report for this experiment, focusing on the insights gained rather than the desired product. How does this reframe 'failure'?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt19": "Chronicle the life cycle of a rumor or piece of gossip that reached you. Where did you first hear it? How did it mutate as it passed to you? What was your role—conduit, amplifier, skeptic, terminator? Analyze the social algorithm that governs such information transfer. What need did this rumor feed in its listeners? Write about the velocity and distortion of unverified stories through a community."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt20": "Recall a time you had to translate—not between languages, but between contexts: explaining a job to family, describing an emotion to someone who doesn't share it, making a technical concept accessible. Describe the words that failed you and the metaphors you crafted to bridge the gap. What was lost in translation? What was surprisingly clarified? Explore the act of building temporary, fragile bridges of understanding between internal and external worlds."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt21": "You discover a forgotten corner of a digital space you own—an old blog draft, a buried folder of photos, an abandoned social media profile. Explore this digital artifact as an archaeologist would a physical site. What does the layout, the language, the imagery tell you about a past self? Reconstruct the mindset of the person who created it. How does this digital echo compare to your current identity? Is it a charming relic or an unsettling ghost?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt22": "You are tasked with archiving a sound that is becoming obsolete—the click of a rotary phone, the chirp of a specific bird whose habitat is shrinking, the particular hum of an old appliance. Record a detailed description of this sound as if for a future museum. What are its frequencies, its rhythms, its emotional connotations? Now, imagine the silence that will exist in its place. What other, newer sounds will fill that auditory niche? Write an elegy for a vanishing sonic fingerprint."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt23": "Craft a mental effigy of a habit, fear, or desire you wish to understand better. Describe this symbolic representation in detail—its materials, its posture, its expression. Now, perform a symbolic action upon it: you might place it in a drawer, bury it in the garden of your mind, or set it adrift on an imaginary river. Chronicle this ritual. Does the act of creating and addressing the effigy change your relationship to the thing it represents, or does it merely make its presence more tangible?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt24": "Describe a labyrinth you have constructed in your own mind—not a physical maze, but a complex, recurring thought pattern or emotional state you find yourself navigating. What are its winding corridors (rationalizations), its dead ends (frustrations), and its potential center (understanding or acceptance)? Map one recent journey through this internal labyrinth. What subtle tremor of insight or fear guided your turns? How do you find your way out, or do you choose to remain within, exploring its familiar, intricate paths?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt25": "Examine a family tradition or ritual as if it were an ancient artifact. Break down its syntax: the required steps, the symbolic objects, the spoken phrases. Who are the keepers of this tradition? How has it mutated or diverged over generations? Participate in or recall this ritual with fresh eyes. What unspoken values and histories are encoded within its performance? What would be lost if it faded into oblivion?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt26": "Observe a plant growing in an unexpected place—a crack in the sidewalk, a gutter, a wall. Chronicle its struggle and persistence. Imagine the velocity of its growth against all odds. Write from the plant's perspective about its daily existence: the foot traffic, the weather, the search for sustenance. What can this resilient life form teach you about finding footholds and thriving in inhospitable environments?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt27": "Imagine your creative process as a room with many thresholds. Describe the room where you generate raw ideas—its mess, its energy. Then, describe the act of crossing the threshold into the room where you refine and edit. What changes in the atmosphere? What do you leave behind at the door, and what must you carry with you? Write about the architecture of your own creativity."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt28": "You are given a seed. It is not a magical seed, but an ordinary one from a fruit you ate. Instead of planting it, you decide to carry it with you for a week as a silent companion. Describe its presence in your pocket or bag. How does knowing it is there, a compact potential for an entire mycelial network of roots and a tree, subtly influence your days? Write about the weight of unactivated futures."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt29": "Recall a time you had to learn a new system or language quickly—a job, a software, a social circle. Describe the initial phase of feeling like an outsider, decoding the basic algorithms of behavior. Then, focus on the precise moment you felt you crossed the threshold from outsider to competent insider. What was the catalyst? A piece of understood jargon? A successfully completed task? Explore the subtle architecture of belonging."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt30": "You find an old, annotated map—perhaps in a book, or a tourist pamphlet from a trip long ago. Study the marks: circled sites, crossed-out routes, notes in the margin. Reconstruct the journey of the person who held this map. Where did they plan to go? Where did they actually go, based on the evidence? Write the travelogue of that forgotten expedition, blending the cartographic intention with the likely reality."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt31": "You encounter a door that is usually locked, but today it is slightly ajar. This is not a grand, mysterious portal, but an ordinary door—to a storage closet, a rooftop, a neighbor's garden gate. Write about the potent allure of this minor threshold. Do you push it open? What mundane or profound discovery lies on the other side? Explore the magnetism of accessible secrets in a world of usual boundaries."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt32": "Recall a piece of practical advice you received that functioned like a simple life algorithm: 'When X happens, do Y.' Examine a recent situation where you deliberately chose not to follow that algorithm. What prompted the deviation? What was the outcome? Describe the feeling of operating outside of a previously trusted internal program. Did the mutation feel like a mistake or an evolution?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt33": "Describe a piece of clothing you own that has been altered or mended multiple times. Trace the history of each repair. Who performed them, and under what circumstances? How does the garment's story of damage and restoration mirror larger cycles of wear and renewal in your own life? What does its continued use, despite its patched state, say about your relationship with impermanence and care?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt34": "You find an old, hand-drawn map that leads to a place in your neighborhood. Follow it. Does it lead you to a spot that still exists, or to a location now utterly changed? Describe the journey of reconciling the cartography of the past with the terrain of the present. What has been erased? What endures? What ghosts of previous journeys do you feel along the way?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt35": "Consider a skill you are learning. Break down its initial algorithm—the basic, rigid steps you must follow. Now, describe the moment when practice leads to mutation: the algorithm begins to dissolve into intuition, muscle memory, or personal style. Where are you in this process? Can you feel the old, clunky code still running beneath the new, fluid performance? Write about the uncomfortable, fruitful space between competence and mastery."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt36": "Analyze the unspoken social algorithm of a group you belong to—your family, your friend circle, your coworkers. What are the input rules (jokes that are allowed, topics to avoid)? What are the output expectations (laughter, support, problem-solving)? Now, imagine introducing a mutation: you break a minor, unwritten rule. Chronicle the system's response. Does it self-correct, reject the input, or adapt?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt37": "Imagine your daily routine is a genetic sequence. Identify a habitual behavior that feels like a dominant gene. Now, imagine a spontaneous mutation occurring in this sequence—one small, random change in the order or execution of your day. Follow the consequences. Does this mutation prove beneficial, harmful, or neutral? Does it replicate and become part of your new code? Write about the evolution of a personal habit through chance."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt38": "Your memory is a vast, dark archive. Choose a specific memory and imagine you are its archivist. Describe the process of retrieving it: locating the correct catalog number, the feel of the storage medium, the quality of the playback. Now, describe the process of conservation—what elements are fragile and in need of repair? Do you restore it to its original clarity, or preserve its current, faded state? What is the ethical duty of a self-archivist?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt39": "Examine a mended object in your possession—a book with tape, a garment with a patch, a glued-together mug. Describe the repair not as a flaw, but as a new feature, a record of care and continuity. Write the history of its breaking and its fixing. Who performed the repair, and what was their state of mind? How does the object's value now reside in its visible history of damage and healing?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt40": "Imagine you are a cartographer of sound. Map the auditory landscape of your current environment. Label the persistent drones, the intermittent rhythms, the sudden percussive events. What are the quiet zones? Where do sounds overlap to create new harmonies or dissonances? Now, imagine mutating one sound source—silencing a hum, amplifying a whisper, changing a rhythm. How does this single alteration redraw the entire sonic map and your emotional response to the space?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt41": "Contemplate the concept of a 'watershed'—a geographical dividing line. Now, identify a watershed moment in your own life: a decision, an event, or a realization that divided your experience into 'before' and 'after.' Describe the landscape of the 'before.' Then, detail the moment of the divide itself. Finally, look out over the 'after' territory. How did the paths available to you fundamentally diverge at that ridge line? What rivers of consequence began to flow in new directions?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt42": "Observe a spiderweb, a bird's nest, or another intricate natural construction. Describe it not as a static object, but as the recorded evidence of a process—a series of deliberate actions repeated to create a functional whole. Imagine you are an archaeologist from another planet discovering this artifact. What hypotheses would you form about the builder's intelligence, needs, and methods? Write your field report."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt43": "Walk through a familiar indoor space (your home, your office) in complete darkness, or with your eyes closed if safe. Navigate by touch, memory, and sound alone. Describe the experience. Which objects and spaces feel different? What details do you notice that vision usually overrides? Write about the knowledge held in your hands and feet, and the temporary oblivion of the visual world. How does this shift in primary sense redefine your understanding of the space?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt44": "You discover a single, worn-out glove lying on a park bench. Describe it in detail—its color, material, signs of wear. Write a speculative history for this artifact. Who owned it? How was it lost? From the glove's perspective, narrate its journey from a department store shelf to this moment of abandonment. What human warmth did it hold, and what does its solitary state signify about loss and separation?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt45": "Find a body of water—a puddle after rain, a pond, a riverbank. Look at your reflection, then disturb the surface with a touch or a thrown pebble. Watch the image shatter and slowly reform. Use this as a metaphor for a period of personal disruption in your life. Describe the 'shattering' event, the chaotic ripple period, and the gradual, never-quite-identical reformation of your sense of self. What was lost in the distortion, and what new facets were revealed?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt46": "You are handed a map of a city you know well, but it is from a century ago. Compare it to the modern layout. Which streets have vanished into oblivion, paved over or renamed? Which buildings are ghosts on the page? Choose one lost place and imagine walking its forgotten route today. What echoes of its past life—sounds, smells, activities—can you almost perceive beneath the contemporary surface? Write about the layers of history that coexist in a single geographic space."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt47": "What is something you've been putting off and why?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt48": "Recall a piece of art—a painting, song, film—that initially confused or repelled you, but that you later came to appreciate or love. Describe your first, negative reaction in detail. Then, trace the journey to understanding. What changed in you or your context that allowed a new interpretation? Write about the value of sitting with discomfort and the rewards of having your internal syntax for beauty challenged and expanded."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt49": "Imagine your life as a vast, intricate tapestry. Describe the overall scene it depicts. Now, find a single, loose thread—a small regret, an unresolved question, a path not taken. Write about gently pulling on that thread. What part of the tapestry begins to unravel? What new pattern or image is revealed—or destroyed—by following this divergence? Is the act one of repair or deconstruction?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt50": "Recall a dream that felt more real than waking life. Describe its internal logic, its emotional palette, and its lingering aftertaste. Now, write a 'practical guide' for navigating that specific dreamscape, as if for a tourist. What are the rules? What should one avoid? What treasures might be found? By treating the dream as a tangible place, what insights do you gain about the concerns of your subconscious?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt51": "Describe a public space you frequent (a library, a cafe, a park) at the exact moment it opens or closes. Capture the transition from emptiness to potential, or from activity to stillness. Focus on the staff or custodians who facilitate this transition—the unseen architects of these daily cycles. Write from the perspective of the space itself as it breathes in or out its human occupants. What residue of the day does it hold in the quiet?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt52": "Listen to a piece of music you know well, but focus exclusively on a single instrument or voice that usually resides in the background. Follow its thread through the entire composition. Describe its journey: when does it lead, when does it harmonize, when does it fall silent? Now, write a short story where this supporting element is the main character. How does shifting your auditory focus create a new narrative from familiar material?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt53": "Describe your reflection in a window at night, with the interior light creating a double exposure of your face and the dark world outside. What two versions of yourself are superimposed? Write a conversation between the 'inside' self, defined by your private space, and the 'outside' self, defined by the anonymous night. What do they want from each other? How does this liminal artifact—the glass—both separate and connect these identities?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt54": "Imagine you are a diver exploring the deep ocean of your own memory. Choose a specific, vivid memory and describe it as a submerged landscape. What creatures (emotions) swim there? What is the water pressure (emotional weight) like? Now, imagine a small, deliberate act of forgetting—letting a single detail of that memory dissolve into the murk. How does this selective oblivion change the entire ecosystem of that recollection? Does it create space for new growth, or does it feel like a loss of truth?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt55": "Recall a conversation that ended in a misunderstanding that was never resolved. Re-write the exchange, but introduce a single point of divergence—one person says something slightly different, or pauses a moment longer. How does this tiny change alter the entire trajectory of the conversation and potentially the relationship? Explore the butterfly effect in human dialogue."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt56": "Spend 15 minutes in complete silence, actively listening for the absence of a specific sound that is usually present (e.g., traffic, refrigerator hum, birds). Describe the quality of this crafted silence. What smaller sounds emerge in the void? How does your mind and body react to the deliberate removal of this sonic artifact? Explore the concept of oblivion as an active, perceptible state rather than a mere lack."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt57": "Describe a skill or talent you possess that feels like it's fading from lack of use—a language getting rusty, a sport you no longer play, an instrument gathering dust. Perform or practice it now, even if clumsily. Chronicle the physical and mental sensations of re-engagement. What echoes of proficiency remain? Is the knowledge truly gone, or merely dormant? Write about the relationship between mastery and oblivion."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt58": "Choose a common word (e.g., 'home,' 'work,' 'friend') and dissect its personal syntax. What rules, associations, and exceptions have you built around its meaning? Now, deliberately break one of those rules. Use the word in a context or with a definition that feels wrong to you. Write a paragraph that forces this new usage. How does corrupting your own internal language create space for new understanding?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt59": "Contemplate a personal habit or pattern you wish to change. Instead of focusing on breaking it, imagine it diverging—mutating into a new, slightly different pattern. Describe the old habit in detail, then design its evolved form. What small, intentional twist could redirect its energy? Write about a day living with this divergent habit. How does a shift in perspective, rather than eradication, alter your relationship to it?"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"prompt00": "You discover a box of old keys. None are labeled. Describe their shapes, weights, and the sounds they make. Speculate on the doors, cabinets, or diaries they once unlocked. Choose one key and imagine the specific, significant thing it secured. Now, imagine throwing them all away, accepting that those locks will remain forever closed. Write about the liberation and the loss in that act of relinquishment."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt01": "Find a source of natural, repetitive sound—rain on a roof, waves on a shore, wind in leaves. Listen until the sound ceases to be 'noise' and becomes a pattern, a rhythm, a form of silence. Describe the moment your perception shifted. What thoughts or memories surfaced in the space created by this hypnotic auditory pattern? Write about the meditation inherent in repetition."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt02": "Describe a local landmark you've passed countless times but never truly examined—a statue, an old sign, a peculiar tree. Stop and study it for fifteen minutes. Record every detail, every crack, every stain. Now, research or imagine its history. How does this deep looking transform an invisible part of your landscape into a character with a story?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt03": "Test prompt for adding to history"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt04": "Choose a common phrase you use often (e.g., \"I'm fine,\" \"Just a minute,\" \"Don't worry about it\"). Dissect it. What does it truly mean when you say it? What does it conceal? What convenience does it provide? Now, for one day, vow not to use it. Chronicle the conversations that become longer, more awkward, or more honest as a result."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt05": "Recall a time you received a gift that was perfectly, inexplicably right for you. Describe the gift and the giver. What made it so resonant? Was it an understanding of a secret wish, a reflection of an unseen part of you, or a tool you didn't know you needed? Explore the magic of being seen and understood through the medium of an object."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt06": "Map a friendship as a shared garden. What did each of you plant in the initial soil? What has grown wild? What requires regular tending? Have there been seasons of drought or frost? Are there any beautiful, stubborn weeds? Write a gardener's diary entry about the current state of this plot, reflecting on its history and future."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt07": "Describe a skill you have that is entirely non-verbal—perhaps riding a bike, kneading dough, tuning an instrument by ear. Attempt to write a manual for this skill using only metaphors and physical sensations. Avoid technical terms. Can you translate embodied knowledge into prose? What is lost, and what is poetically gained?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt08": "Recall a scent that acts as a master key, unlocking a flood of specific, detailed memories. Describe the scent in non-scent words: is it sharp, round, velvety, brittle? Now, follow the key into the memory palace it opens. Don't just describe the memory; describe the architecture of the connection itself. How is scent wired so directly to the past?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt09": "Imagine you are a translator for a species that communicates through subtle shifts in temperature. Describe a recent emotional experience as a thermal map. Where in your body did the warmth of joy concentrate? Where did the cold front of anxiety settle? How would you translate this silent, somatic language into words for someone who only understands degrees and gradients?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt10": "Find a surface covered in a fine layer of dust—a windowsill, an old book, a forgotten picture frame. Describe this 'residue' of time and neglect. What stories does the pattern of settlement tell? Write about the act of wiping it away. Is it an erasure of history or a renewal? What clean surface is revealed, and does it feel like a loss or a gain?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt11": "Build a 'gossamer' bridge in your mind between two seemingly disconnected concepts: for example, baking bread and forgiveness, or traffic patterns and anxiety. Describe the fragile, translucent strands of logic or metaphor you use to connect them. Walk across this bridge. What new landscape do you find on the other side? Does the bridge hold, or dissolve after use?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt12": "Map a personal 'labyrinth' of procrastination or avoidance. What are its enticing entryways (\"I'll just check...\")? Its circular corridors of rationalization? Its terrifying center (the task itself)? Describe one recent journey into this maze. What finally provided the thread to lead you out, or what made you decide to sit in the center and confront the Minotaur?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt13": "Craft a mental 'effigy' of a piece of advice you were given that you've chosen to ignore. Give it form and substance. Do you keep it on a shelf, bury it, or ritually dismantle it? Write about the act of holding this representation of rejected wisdom. Does making it concrete help you understand your refusal, or simply honor the intention of the giver?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt14": "Recall a decision point that felt like standing at the mouth of a 'labyrinth,' with multiple winding paths ahead. Describe the initial confusion and the method you used to choose an entrance (logic, intuition, chance). Now, with hindsight, map the path you actually took. Were there dead ends or unexpected centers? Did the labyrinth lead you out, or deeper into understanding?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt15": "Contemplate a 'quasar'—an immensely luminous, distant celestial object. Use it as a metaphor for a source of guidance or inspiration in your life that feels both incredibly powerful and remote. Who or what is this distant beacon? Describe the 'light' it emits and the long journey it takes to reach you. How do you navigate by this ancient, brilliant, but fundamentally untouchable signal?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt16": "Describe a piece of music that left a 'residue' in your mind—a melody that loops unbidden, a lyric that sticks, a rhythm that syncs with your heartbeat. How does this auditory artifact resurface during quiet moments? What emotional or memory-laden dust has it collected? Write about the process of this mental replay, and whether you seek to amplify it or gently brush it away."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt17": "Recall a 'failed' experiment from your past—a recipe that flopped, a project abandoned, a relationship that didn't work. Instead of framing it as a mistake, analyze it as a valuable trial that produced data. What did you learn about the materials, the process, or yourself? How did the outcome diverge from your hypothesis? Write a lab report for this experiment, focusing on the insights gained rather than the desired product. How does this reframe 'failure'?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt18": "Chronicle the life cycle of a rumor or piece of gossip that reached you. Where did you first hear it? How did it mutate as it passed to you? What was your role—conduit, amplifier, skeptic, terminator? Analyze the social algorithm that governs such information transfer. What need did this rumor feed in its listeners? Write about the velocity and distortion of unverified stories through a community."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt19": "Recall a time you had to translate—not between languages, but between contexts: explaining a job to family, describing an emotion to someone who doesn't share it, making a technical concept accessible. Describe the words that failed you and the metaphors you crafted to bridge the gap. What was lost in translation? What was surprisingly clarified? Explore the act of building temporary, fragile bridges of understanding between internal and external worlds."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt20": "You discover a forgotten corner of a digital space you own—an old blog draft, a buried folder of photos, an abandoned social media profile. Explore this digital artifact as an archaeologist would a physical site. What does the layout, the language, the imagery tell you about a past self? Reconstruct the mindset of the person who created it. How does this digital echo compare to your current identity? Is it a charming relic or an unsettling ghost?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt21": "You are tasked with archiving a sound that is becoming obsolete—the click of a rotary phone, the chirp of a specific bird whose habitat is shrinking, the particular hum of an old appliance. Record a detailed description of this sound as if for a future museum. What are its frequencies, its rhythms, its emotional connotations? Now, imagine the silence that will exist in its place. What other, newer sounds will fill that auditory niche? Write an elegy for a vanishing sonic fingerprint."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt22": "Craft a mental effigy of a habit, fear, or desire you wish to understand better. Describe this symbolic representation in detail—its materials, its posture, its expression. Now, perform a symbolic action upon it: you might place it in a drawer, bury it in the garden of your mind, or set it adrift on an imaginary river. Chronicle this ritual. Does the act of creating and addressing the effigy change your relationship to the thing it represents, or does it merely make its presence more tangible?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt23": "Describe a labyrinth you have constructed in your own mind—not a physical maze, but a complex, recurring thought pattern or emotional state you find yourself navigating. What are its winding corridors (rationalizations), its dead ends (frustrations), and its potential center (understanding or acceptance)? Map one recent journey through this internal labyrinth. What subtle tremor of insight or fear guided your turns? How do you find your way out, or do you choose to remain within, exploring its familiar, intricate paths?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt24": "Examine a family tradition or ritual as if it were an ancient artifact. Break down its syntax: the required steps, the symbolic objects, the spoken phrases. Who are the keepers of this tradition? How has it mutated or diverged over generations? Participate in or recall this ritual with fresh eyes. What unspoken values and histories are encoded within its performance? What would be lost if it faded into oblivion?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt25": "Observe a plant growing in an unexpected place—a crack in the sidewalk, a gutter, a wall. Chronicle its struggle and persistence. Imagine the velocity of its growth against all odds. Write from the plant's perspective about its daily existence: the foot traffic, the weather, the search for sustenance. What can this resilient life form teach you about finding footholds and thriving in inhospitable environments?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt26": "Imagine your creative process as a room with many thresholds. Describe the room where you generate raw ideas—its mess, its energy. Then, describe the act of crossing the threshold into the room where you refine and edit. What changes in the atmosphere? What do you leave behind at the door, and what must you carry with you? Write about the architecture of your own creativity."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt27": "You are given a seed. It is not a magical seed, but an ordinary one from a fruit you ate. Instead of planting it, you decide to carry it with you for a week as a silent companion. Describe its presence in your pocket or bag. How does knowing it is there, a compact potential for an entire mycelial network of roots and a tree, subtly influence your days? Write about the weight of unactivated futures."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt28": "Recall a time you had to learn a new system or language quickly—a job, a software, a social circle. Describe the initial phase of feeling like an outsider, decoding the basic algorithms of behavior. Then, focus on the precise moment you felt you crossed the threshold from outsider to competent insider. What was the catalyst? A piece of understood jargon? A successfully completed task? Explore the subtle architecture of belonging."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt29": "You find an old, annotated map—perhaps in a book, or a tourist pamphlet from a trip long ago. Study the marks: circled sites, crossed-out routes, notes in the margin. Reconstruct the journey of the person who held this map. Where did they plan to go? Where did they actually go, based on the evidence? Write the travelogue of that forgotten expedition, blending the cartographic intention with the likely reality."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt30": "You encounter a door that is usually locked, but today it is slightly ajar. This is not a grand, mysterious portal, but an ordinary door—to a storage closet, a rooftop, a neighbor's garden gate. Write about the potent allure of this minor threshold. Do you push it open? What mundane or profound discovery lies on the other side? Explore the magnetism of accessible secrets in a world of usual boundaries."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt31": "Recall a piece of practical advice you received that functioned like a simple life algorithm: 'When X happens, do Y.' Examine a recent situation where you deliberately chose not to follow that algorithm. What prompted the deviation? What was the outcome? Describe the feeling of operating outside of a previously trusted internal program. Did the mutation feel like a mistake or an evolution?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt32": "Describe a piece of clothing you own that has been altered or mended multiple times. Trace the history of each repair. Who performed them, and under what circumstances? How does the garment's story of damage and restoration mirror larger cycles of wear and renewal in your own life? What does its continued use, despite its patched state, say about your relationship with impermanence and care?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt33": "You find an old, hand-drawn map that leads to a place in your neighborhood. Follow it. Does it lead you to a spot that still exists, or to a location now utterly changed? Describe the journey of reconciling the cartography of the past with the terrain of the present. What has been erased? What endures? What ghosts of previous journeys do you feel along the way?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt34": "Consider a skill you are learning. Break down its initial algorithm—the basic, rigid steps you must follow. Now, describe the moment when practice leads to mutation: the algorithm begins to dissolve into intuition, muscle memory, or personal style. Where are you in this process? Can you feel the old, clunky code still running beneath the new, fluid performance? Write about the uncomfortable, fruitful space between competence and mastery."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt35": "Analyze the unspoken social algorithm of a group you belong to—your family, your friend circle, your coworkers. What are the input rules (jokes that are allowed, topics to avoid)? What are the output expectations (laughter, support, problem-solving)? Now, imagine introducing a mutation: you break a minor, unwritten rule. Chronicle the system's response. Does it self-correct, reject the input, or adapt?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt36": "Imagine your daily routine is a genetic sequence. Identify a habitual behavior that feels like a dominant gene. Now, imagine a spontaneous mutation occurring in this sequence—one small, random change in the order or execution of your day. Follow the consequences. Does this mutation prove beneficial, harmful, or neutral? Does it replicate and become part of your new code? Write about the evolution of a personal habit through chance."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt37": "Your memory is a vast, dark archive. Choose a specific memory and imagine you are its archivist. Describe the process of retrieving it: locating the correct catalog number, the feel of the storage medium, the quality of the playback. Now, describe the process of conservation—what elements are fragile and in need of repair? Do you restore it to its original clarity, or preserve its current, faded state? What is the ethical duty of a self-archivist?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt38": "Examine a mended object in your possession—a book with tape, a garment with a patch, a glued-together mug. Describe the repair not as a flaw, but as a new feature, a record of care and continuity. Write the history of its breaking and its fixing. Who performed the repair, and what was their state of mind? How does the object's value now reside in its visible history of damage and healing?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt39": "Imagine you are a cartographer of sound. Map the auditory landscape of your current environment. Label the persistent drones, the intermittent rhythms, the sudden percussive events. What are the quiet zones? Where do sounds overlap to create new harmonies or dissonances? Now, imagine mutating one sound source—silencing a hum, amplifying a whisper, changing a rhythm. How does this single alteration redraw the entire sonic map and your emotional response to the space?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt40": "Contemplate the concept of a 'watershed'—a geographical dividing line. Now, identify a watershed moment in your own life: a decision, an event, or a realization that divided your experience into 'before' and 'after.' Describe the landscape of the 'before.' Then, detail the moment of the divide itself. Finally, look out over the 'after' territory. How did the paths available to you fundamentally diverge at that ridge line? What rivers of consequence began to flow in new directions?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt41": "Observe a spiderweb, a bird's nest, or another intricate natural construction. Describe it not as a static object, but as the recorded evidence of a process—a series of deliberate actions repeated to create a functional whole. Imagine you are an archaeologist from another planet discovering this artifact. What hypotheses would you form about the builder's intelligence, needs, and methods? Write your field report."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt42": "Walk through a familiar indoor space (your home, your office) in complete darkness, or with your eyes closed if safe. Navigate by touch, memory, and sound alone. Describe the experience. Which objects and spaces feel different? What details do you notice that vision usually overrides? Write about the knowledge held in your hands and feet, and the temporary oblivion of the visual world. How does this shift in primary sense redefine your understanding of the space?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt43": "You discover a single, worn-out glove lying on a park bench. Describe it in detail—its color, material, signs of wear. Write a speculative history for this artifact. Who owned it? How was it lost? From the glove's perspective, narrate its journey from a department store shelf to this moment of abandonment. What human warmth did it hold, and what does its solitary state signify about loss and separation?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt44": "Find a body of water—a puddle after rain, a pond, a riverbank. Look at your reflection, then disturb the surface with a touch or a thrown pebble. Watch the image shatter and slowly reform. Use this as a metaphor for a period of personal disruption in your life. Describe the 'shattering' event, the chaotic ripple period, and the gradual, never-quite-identical reformation of your sense of self. What was lost in the distortion, and what new facets were revealed?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt45": "You are handed a map of a city you know well, but it is from a century ago. Compare it to the modern layout. Which streets have vanished into oblivion, paved over or renamed? Which buildings are ghosts on the page? Choose one lost place and imagine walking its forgotten route today. What echoes of its past life—sounds, smells, activities—can you almost perceive beneath the contemporary surface? Write about the layers of history that coexist in a single geographic space."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt46": "What is something you've been putting off and why?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt47": "Recall a piece of art—a painting, song, film—that initially confused or repelled you, but that you later came to appreciate or love. Describe your first, negative reaction in detail. Then, trace the journey to understanding. What changed in you or your context that allowed a new interpretation? Write about the value of sitting with discomfort and the rewards of having your internal syntax for beauty challenged and expanded."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt48": "Imagine your life as a vast, intricate tapestry. Describe the overall scene it depicts. Now, find a single, loose thread—a small regret, an unresolved question, a path not taken. Write about gently pulling on that thread. What part of the tapestry begins to unravel? What new pattern or image is revealed—or destroyed—by following this divergence? Is the act one of repair or deconstruction?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt49": "Recall a dream that felt more real than waking life. Describe its internal logic, its emotional palette, and its lingering aftertaste. Now, write a 'practical guide' for navigating that specific dreamscape, as if for a tourist. What are the rules? What should one avoid? What treasures might be found? By treating the dream as a tangible place, what insights do you gain about the concerns of your subconscious?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt50": "Describe a public space you frequent (a library, a cafe, a park) at the exact moment it opens or closes. Capture the transition from emptiness to potential, or from activity to stillness. Focus on the staff or custodians who facilitate this transition—the unseen architects of these daily cycles. Write from the perspective of the space itself as it breathes in or out its human occupants. What residue of the day does it hold in the quiet?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt51": "Listen to a piece of music you know well, but focus exclusively on a single instrument or voice that usually resides in the background. Follow its thread through the entire composition. Describe its journey: when does it lead, when does it harmonize, when does it fall silent? Now, write a short story where this supporting element is the main character. How does shifting your auditory focus create a new narrative from familiar material?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt52": "Describe your reflection in a window at night, with the interior light creating a double exposure of your face and the dark world outside. What two versions of yourself are superimposed? Write a conversation between the 'inside' self, defined by your private space, and the 'outside' self, defined by the anonymous night. What do they want from each other? How does this liminal artifact—the glass—both separate and connect these identities?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt53": "Imagine you are a diver exploring the deep ocean of your own memory. Choose a specific, vivid memory and describe it as a submerged landscape. What creatures (emotions) swim there? What is the water pressure (emotional weight) like? Now, imagine a small, deliberate act of forgetting—letting a single detail of that memory dissolve into the murk. How does this selective oblivion change the entire ecosystem of that recollection? Does it create space for new growth, or does it feel like a loss of truth?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt54": "Recall a conversation that ended in a misunderstanding that was never resolved. Re-write the exchange, but introduce a single point of divergence—one person says something slightly different, or pauses a moment longer. How does this tiny change alter the entire trajectory of the conversation and potentially the relationship? Explore the butterfly effect in human dialogue."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt55": "Spend 15 minutes in complete silence, actively listening for the absence of a specific sound that is usually present (e.g., traffic, refrigerator hum, birds). Describe the quality of this crafted silence. What smaller sounds emerge in the void? How does your mind and body react to the deliberate removal of this sonic artifact? Explore the concept of oblivion as an active, perceptible state rather than a mere lack."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt56": "Describe a skill or talent you possess that feels like it's fading from lack of use—a language getting rusty, a sport you no longer play, an instrument gathering dust. Perform or practice it now, even if clumsily. Chronicle the physical and mental sensations of re-engagement. What echoes of proficiency remain? Is the knowledge truly gone, or merely dormant? Write about the relationship between mastery and oblivion."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt57": "Choose a common word (e.g., 'home,' 'work,' 'friend') and dissect its personal syntax. What rules, associations, and exceptions have you built around its meaning? Now, deliberately break one of those rules. Use the word in a context or with a definition that feels wrong to you. Write a paragraph that forces this new usage. How does corrupting your own internal language create space for new understanding?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt58": "Contemplate a personal habit or pattern you wish to change. Instead of focusing on breaking it, imagine it diverging—mutating into a new, slightly different pattern. Describe the old habit in detail, then design its evolved form. What small, intentional twist could redirect its energy? Write about a day living with this divergent habit. How does a shift in perspective, rather than eradication, alter your relationship to it?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt59": "Describe a routine journey you make (a commute, a walk to the store) but narrate it as if you are a traveler in a foreign, slightly surreal land. Give fantastical names to ordinary landmarks. Interpret mundane events as portents or rituals. What hidden narrative or mythic structure can you impose on this familiar path? How does this reframing reveal the magic latent in the everyday?"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
[
|
|
||||||
"You are given a notebook with one rule: you must fill it with questions only. No answers, no statements, just questions. Write the first page of this notebook. Let the questions range from the mundane ('Why is the sky that particular blue today?') to the profound ('What does my kindness cost me?'). Explore the shape of a mind engaged in pure, open inquiry, free from the pressure of resolution.",
|
|
||||||
"Describe a piece of technology you use daily (a phone, a stove, a car) as if it were a living, breathing creature with its own moods and needs. Personify its sounds, its heat, its occasional malfunctions. Write a day in the life from its perspective. What does it 'experience'? How does it perceive your touch and your dependence? Does it feel like a symbiotic partner or a captive servant?",
|
|
||||||
"Recall a time you witnessed a complete stranger perform a small, unexpected act of kindness. Describe the scene in detail, focusing on the micro-expressions and the subtle shift in the atmosphere. Now, imagine the ripple effects of that act. How might it have altered the recipient's day, and perhaps beyond? Write about the invisible network of goodwill that exists in the mundane, and your role as a silent observer in that moment.",
|
|
||||||
"Choose a color that has been significant to you at different points in your life. Trace its appearances: a childhood toy, a piece of clothing, a room's paint, a natural phenomenon. How has your relationship with this hue evolved? Does it represent a constant thread or a changing symbol? Write an ode to this color, exploring its personal resonance and its objective, physical properties of light.",
|
|
||||||
"You are tasked with creating a time capsule for your current self to open in ten years. Select five non-digital objects that, together, create a portrait of your present life. Describe each object and justify its inclusion. What story do these artifacts tell about your values, your struggles, your joys? Now, write the letter you would include, addressed to your future self. What questions would you ask? What hopes would you express?",
|
|
||||||
"Observe a cloud formation for an extended period. Chronicle its slow transformation from one shape into another. Resist the urge to name it (a dragon, a ship). Instead, describe the pure process of morphing, the dissipation and coagulation of vapor. Use this as a metaphor for a change in your own life that was gradual, inevitable, and beautiful in its impermanence. How do you document a process that leaves no solid artifact?",
|
|
||||||
"Recall a book you read that fundamentally changed your perspective. Describe the mental landscape before you encountered it. Then, detail the specific passage or concept that acted as a key, unlocking a new way of seeing. How did the syntax of the author's thoughts rewire your own? Write about the intimate, silent collaboration between reader and text that results in personal evolution.",
|
|
||||||
"Find a spot where nature is reclaiming a human structure—ivy on a fence, moss on a step, a crack in asphalt sprouting weeds. Describe this slow-motion negotiation between the built and the wild. Who is winning? Is it a battle or a collaboration? Write from the perspective of one of these natural reclaiming agents. What is its patient, relentless strategy? What does it think of the rigid geometry it is softening?",
|
|
||||||
"Describe a flavor or taste combination that you find uniquely comforting. Deconstruct it into its elemental parts. Now, research or imagine its origin story. How did these ingredients first come together? Follow that history through trade routes, cultural fusion, or family tradition. How does knowing this deeper history alter the simple act of tasting? Does it add layers, or strip the comfort down to its essential chemistry?",
|
|
||||||
"Imagine your mind has a 'peripheral vision' for ideas—thoughts and intuitions that linger just outside your direct focus. Spend a day paying attention to these faint mental tremors. Jot them down. At day's end, examine your notes. Do these peripheral thoughts form a pattern? Are they fears, creative sparks, forgotten tasks? Write about the value of tuning into the quiet background noise of your own consciousness.",
|
|
||||||
"You receive a package with no return address. Inside is an object you have never seen before, but it feels vaguely, unsettlingly familiar. Describe this object in meticulous detail. What is its function? What does its design imply about its maker or its intended use? Write the story of how you interact with this mysterious artifact. Do you display it, hide it, or try to return it to a non-existent sender? What does your choice reveal?"
|
|
||||||
]
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
[
|
|
||||||
"Describe a piece of public art you have a strong reaction to, positive or negative. Interact with it physically—walk around it, touch it if allowed, view it from different angles. How does your physical relationship to the object change your intellectual or emotional response? Write a review that focuses solely on the bodily experience of the art, rather than its purported meaning.",
|
|
||||||
"Recall a time you had to wait much longer than anticipated—in a line, for news, for a person. Describe the internal landscape of that waiting. How did your mind occupy itself? What petty annoyances or profound thoughts surfaced in the stretched time? Write about the architecture of patience and the unexpected creations that can bloom in its empty spaces.",
|
|
||||||
"Imagine your childhood home has a secret room you never discovered. Describe what you imagine is inside. Is it a treasure trove of forgotten toys? A dusty library of family secrets? A perfectly preserved moment from a specific day? Now, as an adult, write about what you would hope to find there, and what that hope reveals about your relationship to your own past.",
|
|
||||||
"You are given a notebook with one rule: you must fill it with questions only. No answers, no statements, just questions. Write the first page of this notebook. Let the questions range from the mundane ('Why is the sky that particular blue today?') to the profound ('What does my kindness cost me?'). Explore the shape of a mind engaged in pure, open inquiry, free from the pressure of resolution.",
|
|
||||||
"Describe a piece of technology you use daily (a phone, a stove, a car) as if it were a living, breathing creature with its own moods and needs. Personify its sounds, its heat, its occasional malfunctions. Write a day in the life from its perspective. What does it 'experience'? How does it perceive your touch and your dependence? Does it feel like a symbiotic partner or a captive servant?",
|
|
||||||
"Recall a time you witnessed a complete stranger perform a small, unexpected act of kindness. Describe the scene in detail, focusing on the micro-expressions and the subtle shift in the atmosphere. Now, imagine the ripple effects of that act. How might it have altered the recipient's day, and perhaps beyond? Write about the invisible network of goodwill that exists in the mundane, and your role as a silent observer in that moment.",
|
|
||||||
"Choose a color that has been significant to you at different points in your life. Trace its appearances: a childhood toy, a piece of clothing, a room's paint, a natural phenomenon. How has your relationship with this hue evolved? Does it represent a constant thread or a changing symbol? Write an ode to this color, exploring its personal resonance and its objective, physical properties of light.",
|
|
||||||
"You are tasked with creating a time capsule for your current self to open in ten years. Select five non-digital objects that, together, create a portrait of your present life. Describe each object and justify its inclusion. What story do these artifacts tell about your values, your struggles, your joys? Now, write the letter you would include, addressed to your future self. What questions would you ask? What hopes would you express?",
|
|
||||||
"Observe a cloud formation for an extended period. Chronicle its slow transformation from one shape into another. Resist the urge to name it (a dragon, a ship). Instead, describe the pure process of morphing, the dissipation and coagulation of vapor. Use this as a metaphor for a change in your own life that was gradual, inevitable, and beautiful in its impermanence. How do you document a process that leaves no solid artifact?",
|
|
||||||
"Recall a book you read that fundamentally changed your perspective. Describe the mental landscape before you encountered it. Then, detail the specific passage or concept that acted as a key, unlocking a new way of seeing. How did the syntax of the author's thoughts rewire your own? Write about the intimate, silent collaboration between reader and text that results in personal evolution.",
|
|
||||||
"Find a spot where nature is reclaiming a human structure—ivy on a fence, moss on a step, a crack in asphalt sprouting weeds. Describe this slow-motion negotiation between the built and the wild. Who is winning? Is it a battle or a collaboration? Write from the perspective of one of these natural reclaiming agents. What is its patient, relentless strategy? What does it think of the rigid geometry it is softening?",
|
|
||||||
"Describe a flavor or taste combination that you find uniquely comforting. Deconstruct it into its elemental parts. Now, research or imagine its origin story. How did these ingredients first come together? Follow that history through trade routes, cultural fusion, or family tradition. How does knowing this deeper history alter the simple act of tasting? Does it add layers, or strip the comfort down to its essential chemistry?",
|
|
||||||
"Imagine your mind has a 'peripheral vision' for ideas—thoughts and intuitions that linger just outside your direct focus. Spend a day paying attention to these faint mental tremors. Jot them down. At day's end, examine your notes. Do these peripheral thoughts form a pattern? Are they fears, creative sparks, forgotten tasks? Write about the value of tuning into the quiet background noise of your own consciousness.",
|
|
||||||
"You receive a package with no return address. Inside is an object you have never seen before, but it feels vaguely, unsettlingly familiar. Describe this object in meticulous detail. What is its function? What does its design imply about its maker or its intended use? Write the story of how you interact with this mysterious artifact. Do you display it, hide it, or try to return it to a non-existent sender? What does your choice reveal?"
|
|
||||||
]
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# settings.cfg
|
|
||||||
# This controls how many prompts are presented and consumed from the pool, as well as how much to pre-cache.
|
|
||||||
# This is used to maintain functionality offline for some number of iterations.
|
|
||||||
|
|
||||||
[prompts]
|
|
||||||
min_length = 500
|
|
||||||
max_length = 1000
|
|
||||||
num_prompts = 3
|
|
||||||
|
|
||||||
# Pool size can affect the prompts if is too high. Default 20.
|
|
||||||
[prefetch]
|
|
||||||
cached_pool_volume = 20
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
Demonstration of the feedback_historic.json cyclic buffer system.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
from generate_prompts import JournalPromptGenerator
|
|
||||||
|
|
||||||
def demonstrate_system():
|
|
||||||
"""Demonstrate the feedback historic system."""
|
|
||||||
print("="*70)
|
|
||||||
print("DEMONSTRATION: Feedback Historic Cyclic Buffer System")
|
|
||||||
print("="*70)
|
|
||||||
|
|
||||||
# Create a temporary .env file
|
|
||||||
with open(".env.demo", "w") as f:
|
|
||||||
f.write("DEEPSEEK_API_KEY=demo_key\n")
|
|
||||||
f.write("API_BASE_URL=https://api.deepseek.com\n")
|
|
||||||
f.write("MODEL=deepseek-chat\n")
|
|
||||||
|
|
||||||
# Initialize generator
|
|
||||||
generator = JournalPromptGenerator(config_path=".env.demo")
|
|
||||||
|
|
||||||
print("\n1. Initial state:")
|
|
||||||
print(f" - feedback_words: {len(generator.feedback_words)} items")
|
|
||||||
print(f" - feedback_historic: {len(generator.feedback_historic)} items")
|
|
||||||
|
|
||||||
# Create some sample feedback words
|
|
||||||
sample_words_batch1 = [
|
|
||||||
{"feedback00": "memory", "weight": 5},
|
|
||||||
{"feedback01": "time", "weight": 4},
|
|
||||||
{"feedback02": "nature", "weight": 3},
|
|
||||||
{"feedback03": "emotion", "weight": 6},
|
|
||||||
{"feedback04": "change", "weight": 2},
|
|
||||||
{"feedback05": "connection", "weight": 4}
|
|
||||||
]
|
|
||||||
|
|
||||||
print("\n2. Adding first batch of feedback words...")
|
|
||||||
generator.update_feedback_words(sample_words_batch1)
|
|
||||||
print(f" - Added 6 feedback words")
|
|
||||||
print(f" - feedback_historic now has: {len(generator.feedback_historic)} items")
|
|
||||||
|
|
||||||
# Show the historic items
|
|
||||||
print("\n Historic feedback words (no weights):")
|
|
||||||
for i, item in enumerate(generator.feedback_historic):
|
|
||||||
key = list(item.keys())[0]
|
|
||||||
print(f" {key}: {item[key]}")
|
|
||||||
|
|
||||||
# Add second batch
|
|
||||||
sample_words_batch2 = [
|
|
||||||
{"feedback00": "creativity", "weight": 5},
|
|
||||||
{"feedback01": "reflection", "weight": 4},
|
|
||||||
{"feedback02": "growth", "weight": 3},
|
|
||||||
{"feedback03": "transformation", "weight": 6},
|
|
||||||
{"feedback04": "journey", "weight": 2},
|
|
||||||
{"feedback05": "discovery", "weight": 4}
|
|
||||||
]
|
|
||||||
|
|
||||||
print("\n3. Adding second batch of feedback words...")
|
|
||||||
generator.update_feedback_words(sample_words_batch2)
|
|
||||||
print(f" - Added 6 more feedback words")
|
|
||||||
print(f" - feedback_historic now has: {len(generator.feedback_historic)} items")
|
|
||||||
|
|
||||||
print("\n Historic feedback words after second batch:")
|
|
||||||
print(" (New words at the top, old words shifted down)")
|
|
||||||
for i, item in enumerate(generator.feedback_historic[:12]): # Show first 12
|
|
||||||
key = list(item.keys())[0]
|
|
||||||
print(f" {key}: {item[key]}")
|
|
||||||
|
|
||||||
# Demonstrate the cyclic buffer by adding more batches
|
|
||||||
print("\n4. Demonstrating cyclic buffer (30 item limit)...")
|
|
||||||
print(" Adding 5 more batches (30 more words total)...")
|
|
||||||
|
|
||||||
for batch_num in range(3, 8):
|
|
||||||
batch_words = []
|
|
||||||
for j in range(6):
|
|
||||||
batch_words.append({f"feedback{j:02d}": f"batch{batch_num}_word{j+1}", "weight": 3})
|
|
||||||
generator.update_feedback_words(batch_words)
|
|
||||||
|
|
||||||
print(f" - feedback_historic now has: {len(generator.feedback_historic)} items (max 30)")
|
|
||||||
print(f" - Oldest items have been dropped to maintain 30-item limit")
|
|
||||||
|
|
||||||
# Show the structure
|
|
||||||
print("\n5. Checking file structure...")
|
|
||||||
if os.path.exists("feedback_historic.json"):
|
|
||||||
with open("feedback_historic.json", "r") as f:
|
|
||||||
data = json.load(f)
|
|
||||||
print(f" - feedback_historic.json exists with {len(data)} items")
|
|
||||||
print(f" - First item: {data[0]}")
|
|
||||||
print(f" - Last item: {data[-1]}")
|
|
||||||
print(f" - Items have keys (feedback00, feedback01, etc.) but no weights")
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
os.remove(".env.demo")
|
|
||||||
if os.path.exists("feedback_words.json"):
|
|
||||||
os.remove("feedback_words.json")
|
|
||||||
if os.path.exists("feedback_historic.json"):
|
|
||||||
os.remove("feedback_historic.json")
|
|
||||||
|
|
||||||
print("\n" + "="*70)
|
|
||||||
print("SUMMARY:")
|
|
||||||
print("="*70)
|
|
||||||
print("✓ feedback_historic.json stores previous feedback words (no weights)")
|
|
||||||
print("✓ Maximum of 30 items (feedback00-feedback29)")
|
|
||||||
print("✓ When new feedback is generated (6 words):")
|
|
||||||
print(" - They become feedback00-feedback05 in the historic buffer")
|
|
||||||
print(" - All existing items shift down by 6 positions")
|
|
||||||
print(" - Items beyond feedback29 are discarded")
|
|
||||||
print("✓ Historic feedback words are included in AI prompts for")
|
|
||||||
print(" generate_theme_feedback_words() to avoid repetition")
|
|
||||||
print("="*70)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
demonstrate_system()
|
|
||||||
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
backend:
|
|
||||||
build: ./backend
|
|
||||||
container_name: daily-journal-prompt-backend
|
|
||||||
ports:
|
|
||||||
- "8000:8000"
|
|
||||||
volumes:
|
|
||||||
- ./backend:/app
|
|
||||||
- ./data:/app/data
|
|
||||||
environment:
|
|
||||||
- DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY:-}
|
|
||||||
- OPENAI_API_KEY=${OPENAI_API_KEY:-}
|
|
||||||
- API_BASE_URL=${API_BASE_URL:-https://api.deepseek.com}
|
|
||||||
- MODEL=${MODEL:-deepseek-chat}
|
|
||||||
- DEBUG=${DEBUG:-false}
|
|
||||||
- ENVIRONMENT=${ENVIRONMENT:-development}
|
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
develop:
|
|
||||||
watch:
|
|
||||||
- action: sync
|
|
||||||
path: ./backend
|
|
||||||
target: /app
|
|
||||||
ignore:
|
|
||||||
- __pycache__/
|
|
||||||
- .pytest_cache/
|
|
||||||
- .coverage
|
|
||||||
- action: rebuild
|
|
||||||
path: ./backend/requirements.txt
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 3
|
|
||||||
start_period: 40s
|
|
||||||
restart: unless-stopped
|
|
||||||
networks:
|
|
||||||
- journal-network
|
|
||||||
|
|
||||||
frontend:
|
|
||||||
build: ./frontend
|
|
||||||
container_name: daily-journal-prompt-frontend
|
|
||||||
ports:
|
|
||||||
- "3000:80" # Production frontend on nginx
|
|
||||||
volumes:
|
|
||||||
- ./frontend:/app
|
|
||||||
- /app/node_modules
|
|
||||||
environment:
|
|
||||||
- NODE_ENV=${NODE_ENV:-production}
|
|
||||||
depends_on:
|
|
||||||
backend:
|
|
||||||
condition: service_healthy
|
|
||||||
restart: unless-stopped
|
|
||||||
networks:
|
|
||||||
- journal-network
|
|
||||||
|
|
||||||
# Development frontend (hot reload)
|
|
||||||
frontend-dev:
|
|
||||||
build:
|
|
||||||
context: ./frontend
|
|
||||||
target: builder
|
|
||||||
container_name: daily-journal-prompt-frontend-dev
|
|
||||||
ports:
|
|
||||||
- "3001:3000" # Development server on different port
|
|
||||||
volumes:
|
|
||||||
- ./frontend:/app
|
|
||||||
- /app/node_modules
|
|
||||||
environment:
|
|
||||||
- NODE_ENV=development
|
|
||||||
command: npm run dev
|
|
||||||
develop:
|
|
||||||
watch:
|
|
||||||
- action: sync
|
|
||||||
path: ./frontend/src
|
|
||||||
target: /app/src
|
|
||||||
- action: rebuild
|
|
||||||
path: ./frontend/package.json
|
|
||||||
depends_on:
|
|
||||||
backend:
|
|
||||||
condition: service_healthy
|
|
||||||
restart: unless-stopped
|
|
||||||
networks:
|
|
||||||
- journal-network
|
|
||||||
|
|
||||||
networks:
|
|
||||||
journal-network:
|
|
||||||
driver: bridge
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
data:
|
|
||||||
driver: local
|
|
||||||
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
Request for generation of writing prompts for journaling
|
|
||||||
|
|
||||||
Payload:
|
|
||||||
The previous 60 prompts have been provided as a JSON array for reference.
|
|
||||||
The current 6 feedback themes have been provided. You will not re-use any of these most-recently used words here.
|
|
||||||
The previous 30 feedback themes are also provided. You should try to avoid re-using these unless it really makes sense to.
|
|
||||||
|
|
||||||
Guidelines:
|
|
||||||
Using the attached JSON of writing prompts, you should try to pick out 4 unique and intentionally vague single-word themes that apply to some portion of the list. They can range from common to uncommon words.
|
|
||||||
Then add 2 more single word divergent themes that are less related to the historic prompts and are somewhat different from the other 4 for a total of 6 words.
|
|
||||||
These 2 divergent themes give the user the option to steer away from existing themes.
|
|
||||||
Examples for the divergent themes could be the option to add a theme like technology when the other themes are related to beauty, or mortality when the other themes are very positive.
|
|
||||||
Be creative, don't just use my example.
|
|
||||||
A very high temperature AI response is warranted here to generate a large vocabulary.
|
|
||||||
|
|
||||||
Expected Output:
|
|
||||||
Output as a JSON list with just the six words, in lowercase.
|
|
||||||
Despite the provided history being a keyed list or dictionary, the expected return JSON will be a simple list with no keys.
|
|
||||||
Respond ONLY with valid JSON. No explanations, no markdown, no backticks.
|
|
||||||
|
|
||||||
@@ -2,7 +2,6 @@ Request for generation of writing prompts for journaling
|
|||||||
|
|
||||||
Payload:
|
Payload:
|
||||||
The previous 60 prompts have been provided as a JSON array for reference.
|
The previous 60 prompts have been provided as a JSON array for reference.
|
||||||
Some vague feedback themes have been provided, each having a weight value from 0 to 6.
|
|
||||||
|
|
||||||
Guidelines:
|
Guidelines:
|
||||||
Please generate some number of individual writing prompts in English following these guidelines.
|
Please generate some number of individual writing prompts in English following these guidelines.
|
||||||
@@ -14,11 +13,6 @@ The provided history brackets two mechanisms.
|
|||||||
The history will allow for reducing repetition, however some thematic overlap is acceptable. Try harder to avoid overlap with lower indices in the array.
|
The history will allow for reducing repetition, however some thematic overlap is acceptable. Try harder to avoid overlap with lower indices in the array.
|
||||||
As the user discards prompts, the themes will be very slowly steered, so it's okay to take some inspiration from the history.
|
As the user discards prompts, the themes will be very slowly steered, so it's okay to take some inspiration from the history.
|
||||||
|
|
||||||
Feedback Themes:
|
|
||||||
A JSON of single-word feedback themes is provided with each having a weight value from 0 to 6.
|
|
||||||
Consider these weighted themes only rarely when creating a new writing prompt. Most prompts should be created with full creative freedom.
|
|
||||||
Only gently influence writing prompts with these. It is better to have all generated prompts ignore a theme than have many reference a theme overtly.
|
|
||||||
|
|
||||||
Expected Output:
|
Expected Output:
|
||||||
Output as a JSON list with the requested number of elements.
|
Output as a JSON list with the requested number of elements.
|
||||||
Despite the provided history being a keyed list or dictionary, the expected return JSON will be a simple list with no keys.
|
Despite the provided history being a keyed list or dictionary, the expected return JSON will be a simple list with no keys.
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"feedback00": "labyrinth"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback01": "residue"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback02": "tremor"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback03": "effigy"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback04": "quasar"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback05": "gossamer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback06": "resonance"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback07": "erosion"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback08": "surrender"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback09": "excess"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback10": "chaos"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback11": "fabric"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback12": "palimpsest"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback13": "lacuna"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback14": "efflorescence"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback15": "tessellation"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback16": "sublimation"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback17": "vertigo"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback18": "artifact"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback19": "mycelium"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback20": "threshold"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback21": "cartography"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback22": "spectacle"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback23": "friction"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback24": "mutation"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback25": "echo"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback26": "repair"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback27": "velocity"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback28": "syntax"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback29": "divergence"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"feedback00": "labyrinth",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback01": "residue",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback02": "tremor",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback03": "effigy",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback04": "quasar",
|
|
||||||
"weight": 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"feedback05": "gossamer",
|
|
||||||
"weight": 3
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"_variables": {
|
|
||||||
"lastUpdateCheck": 1767467593775
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
frontend/.astro/types.d.ts
vendored
1
frontend/.astro/types.d.ts
vendored
@@ -1 +0,0 @@
|
|||||||
/// <reference types="astro/client" />
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
FROM node:18-alpine AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy package files
|
|
||||||
COPY package*.json ./
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
# Use npm install for development (npm ci requires package-lock.json)
|
|
||||||
RUN npm install
|
|
||||||
|
|
||||||
# Copy source code
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Build the application
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
# Production stage
|
|
||||||
FROM nginx:alpine
|
|
||||||
|
|
||||||
# Copy built files from builder stage
|
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
|
||||||
|
|
||||||
# Copy nginx configuration
|
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
||||||
|
|
||||||
# Expose port
|
|
||||||
EXPOSE 80
|
|
||||||
|
|
||||||
# Health check
|
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
||||||
CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1
|
|
||||||
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
|
||||||
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import { defineConfig } from 'astro/config';
|
|
||||||
import react from '@astrojs/react';
|
|
||||||
|
|
||||||
// https://astro.build/config
|
|
||||||
export default defineConfig({
|
|
||||||
integrations: [react()],
|
|
||||||
server: {
|
|
||||||
port: 3000,
|
|
||||||
host: true
|
|
||||||
},
|
|
||||||
vite: {
|
|
||||||
server: {
|
|
||||||
proxy: {
|
|
||||||
'/api': {
|
|
||||||
target: 'http://localhost:8000',
|
|
||||||
changeOrigin: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name localhost;
|
|
||||||
root /usr/share/nginx/html;
|
|
||||||
index index.html;
|
|
||||||
|
|
||||||
# Gzip compression
|
|
||||||
gzip on;
|
|
||||||
gzip_vary on;
|
|
||||||
gzip_min_length 1024;
|
|
||||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
|
|
||||||
|
|
||||||
# Security headers
|
|
||||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
||||||
add_header X-Content-Type-Options "nosniff" always;
|
|
||||||
add_header X-XSS-Protection "1; mode=block" always;
|
|
||||||
|
|
||||||
# Cache static assets
|
|
||||||
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
|
|
||||||
expires 1y;
|
|
||||||
add_header Cache-Control "public, immutable";
|
|
||||||
}
|
|
||||||
|
|
||||||
# Handle SPA routing
|
|
||||||
location / {
|
|
||||||
try_files $uri $uri/ /index.html;
|
|
||||||
}
|
|
||||||
|
|
||||||
# API proxy for development (in production, this would be handled separately)
|
|
||||||
location /api/ {
|
|
||||||
proxy_pass http://backend:8000/api/;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection 'upgrade';
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
proxy_cache_bypass $http_upgrade;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Error pages
|
|
||||||
error_page 404 /index.html;
|
|
||||||
error_page 500 502 503 504 /50x.html;
|
|
||||||
location = /50x.html {
|
|
||||||
root /usr/share/nginx/html;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "daily-journal-prompt-frontend",
|
|
||||||
"type": "module",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "Frontend for Daily Journal Prompt Generator",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "astro dev",
|
|
||||||
"build": "astro build",
|
|
||||||
"preview": "astro preview",
|
|
||||||
"astro": "astro"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"astro": "^4.0.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@astrojs/react": "^3.0.0",
|
|
||||||
"react": "^18.0.0",
|
|
||||||
"react-dom": "^18.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,253 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
|
|
||||||
const PromptDisplay = () => {
|
|
||||||
const [prompts, setPrompts] = useState([]); // Changed to array to handle multiple prompts
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [error, setError] = useState(null);
|
|
||||||
const [selectedIndex, setSelectedIndex] = useState(null);
|
|
||||||
const [viewMode, setViewMode] = useState('history'); // 'history' or 'drawn'
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchMostRecentPrompt();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const fetchMostRecentPrompt = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Try to fetch from actual API first
|
|
||||||
const response = await fetch('/api/v1/prompts/history');
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
// API returns array directly, not object with 'prompts' key
|
|
||||||
if (Array.isArray(data) && data.length > 0) {
|
|
||||||
// Get the most recent prompt (first in array, position 0)
|
|
||||||
// Show only one prompt from history
|
|
||||||
setPrompts([{ text: data[0].text, position: data[0].position }]);
|
|
||||||
setViewMode('history');
|
|
||||||
} else {
|
|
||||||
// No history yet, show placeholder
|
|
||||||
setPrompts([{ text: "No recent prompts in history. Draw some prompts to get started!", position: 0 }]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// API not available, use mock data
|
|
||||||
setPrompts([{ text: "Write about a time when you felt completely at peace with yourself and the world around you. What were the circumstances that led to this feeling, and how did it change your perspective on life?", position: 0 }]);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching prompt:', err);
|
|
||||||
// Fallback to mock data
|
|
||||||
setPrompts([{ text: "Imagine you could have a conversation with your future self 10 years from now. What questions would you ask, and what advice do you think your future self would give you?", position: 0 }]);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDrawPrompts = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
setError(null);
|
|
||||||
setSelectedIndex(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Draw 3 prompts from pool (Task 4)
|
|
||||||
const response = await fetch('/api/v1/prompts/draw?count=3');
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
// Draw API returns object with 'prompts' array
|
|
||||||
if (data.prompts && data.prompts.length > 0) {
|
|
||||||
// Show all drawn prompts
|
|
||||||
const drawnPrompts = data.prompts.map((text, index) => ({
|
|
||||||
text,
|
|
||||||
position: index
|
|
||||||
}));
|
|
||||||
setPrompts(drawnPrompts);
|
|
||||||
setViewMode('drawn');
|
|
||||||
} else {
|
|
||||||
setError('No prompts available in pool. Please fill the pool first.');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setError('Failed to draw prompts. Please try again.');
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
setError('Failed to draw prompts. Please try again.');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleAddToHistory = async (index) => {
|
|
||||||
if (index < 0 || index >= prompts.length) {
|
|
||||||
setError('Invalid prompt index');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const promptText = prompts[index].text;
|
|
||||||
|
|
||||||
// Send the prompt to the API to add to history
|
|
||||||
const response = await fetch('/api/v1/prompts/select', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ prompt_text: promptText }),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
// Mark as selected and show success
|
|
||||||
setSelectedIndex(index);
|
|
||||||
|
|
||||||
// Instead of showing an alert, refresh the page to show the updated history
|
|
||||||
// The default view shows the most recent prompt from history
|
|
||||||
alert(`Prompt added to history as ${data.position_in_history}! Refreshing to show updated history...`);
|
|
||||||
|
|
||||||
// Refresh the page to show the updated history
|
|
||||||
// The default view shows the most recent prompt from history (position 0)
|
|
||||||
fetchMostRecentPrompt();
|
|
||||||
} else {
|
|
||||||
const errorData = await response.json();
|
|
||||||
setError(`Failed to add prompt to history: ${errorData.detail || 'Unknown error'}`);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
setError('Failed to add prompt to history');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFillPool = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const response = await fetch('/api/v1/prompts/fill-pool', { method: 'POST' });
|
|
||||||
if (response.ok) {
|
|
||||||
alert('Prompt pool filled successfully!');
|
|
||||||
// Refresh the prompt
|
|
||||||
fetchMostRecentPrompt();
|
|
||||||
} else {
|
|
||||||
setError('Failed to fill prompt pool');
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
setError('Failed to fill prompt pool');
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (loading) {
|
|
||||||
return (
|
|
||||||
<div className="text-center p-8">
|
|
||||||
<div className="spinner mx-auto"></div>
|
|
||||||
<p className="mt-4">Loading prompt...</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return (
|
|
||||||
<div className="alert alert-error">
|
|
||||||
<i className="fas fa-exclamation-circle mr-2"></i>
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{prompts.length > 0 ? (
|
|
||||||
<>
|
|
||||||
<div className="mb-6">
|
|
||||||
<div className="grid grid-cols-1 gap-4">
|
|
||||||
{prompts.map((promptObj, index) => (
|
|
||||||
<div
|
|
||||||
key={index}
|
|
||||||
className={`prompt-card cursor-pointer ${selectedIndex === index ? 'selected' : ''}`}
|
|
||||||
onClick={() => setSelectedIndex(index)}
|
|
||||||
>
|
|
||||||
<div className="flex items-start gap-3">
|
|
||||||
<div className={`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center ${selectedIndex === index ? 'bg-green-100 text-green-600' : 'bg-blue-100 text-blue-600'}`}>
|
|
||||||
{selectedIndex === index ? (
|
|
||||||
<i className="fas fa-check"></i>
|
|
||||||
) : (
|
|
||||||
<span>{index + 1}</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="flex-grow">
|
|
||||||
<p className="prompt-text">{promptObj.text}</p>
|
|
||||||
<div className="prompt-meta">
|
|
||||||
<span>
|
|
||||||
<i className="fas fa-ruler-combined mr-1"></i>
|
|
||||||
{promptObj.text.length} characters
|
|
||||||
</span>
|
|
||||||
<span>
|
|
||||||
{selectedIndex === index ? (
|
|
||||||
<span className="text-green-600">
|
|
||||||
<i className="fas fa-check-circle mr-1"></i>
|
|
||||||
Selected
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span className="text-gray-500">
|
|
||||||
Click to select
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex flex-col gap-4">
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<button
|
|
||||||
className="btn btn-success flex-1"
|
|
||||||
onClick={() => handleAddToHistory(selectedIndex !== null ? selectedIndex : 0)}
|
|
||||||
disabled={selectedIndex === null}
|
|
||||||
>
|
|
||||||
<i className="fas fa-history"></i>
|
|
||||||
{selectedIndex !== null ? 'Use Selected Prompt' : 'Select a Prompt First'}
|
|
||||||
</button>
|
|
||||||
<button className="btn btn-primary flex-1" onClick={handleDrawPrompts}>
|
|
||||||
<i className="fas fa-dice"></i>
|
|
||||||
{viewMode === 'history' ? 'Draw 3 New Prompts' : 'Draw 3 More Prompts'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button className="btn btn-secondary" onClick={handleFillPool}>
|
|
||||||
<i className="fas fa-sync"></i> Fill Prompt Pool
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="mt-6 text-sm text-gray-600">
|
|
||||||
<p>
|
|
||||||
<i className="fas fa-info-circle mr-1"></i>
|
|
||||||
<strong>
|
|
||||||
{viewMode === 'history' ? 'Most Recent Prompt from History' : `${prompts.length} Drawn Prompts`}:
|
|
||||||
</strong>
|
|
||||||
{viewMode === 'history'
|
|
||||||
? ' This is the latest prompt from your history. Using it helps the AI learn your preferences.'
|
|
||||||
: ' Select a prompt to use for journaling. The AI will learn from your selection.'}
|
|
||||||
</p>
|
|
||||||
<p className="mt-2">
|
|
||||||
<i className="fas fa-lightbulb mr-1"></i>
|
|
||||||
<strong>Tip:</strong> The prompt pool needs regular refilling. Check the stats panel
|
|
||||||
to see how full it is.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<div className="text-center p-8">
|
|
||||||
<i className="fas fa-inbox fa-3x mb-4" style={{ color: 'var(--gray-color)' }}></i>
|
|
||||||
<h3>No Prompts Available</h3>
|
|
||||||
<p className="mb-4">There are no prompts in history or pool. Get started by filling the pool.</p>
|
|
||||||
<button className="btn btn-primary" onClick={handleFillPool}>
|
|
||||||
<i className="fas fa-plus"></i> Fill Prompt Pool
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PromptDisplay;
|
|
||||||
|
|
||||||
@@ -1,213 +0,0 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
|
|
||||||
const StatsDashboard = () => {
|
|
||||||
const [stats, setStats] = useState({
|
|
||||||
pool: {
|
|
||||||
total: 0,
|
|
||||||
target: 20,
|
|
||||||
sessions: 0,
|
|
||||||
needsRefill: true
|
|
||||||
},
|
|
||||||
history: {
|
|
||||||
total: 0,
|
|
||||||
capacity: 60,
|
|
||||||
available: 60,
|
|
||||||
isFull: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchStats();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const fetchStats = async () => {
|
|
||||||
try {
|
|
||||||
// Fetch pool stats
|
|
||||||
const poolResponse = await fetch('/api/v1/prompts/stats');
|
|
||||||
const poolData = poolResponse.ok ? await poolResponse.json() : {
|
|
||||||
total_prompts: 0,
|
|
||||||
target_pool_size: 20,
|
|
||||||
available_sessions: 0,
|
|
||||||
needs_refill: true
|
|
||||||
};
|
|
||||||
|
|
||||||
// Fetch history stats
|
|
||||||
const historyResponse = await fetch('/api/v1/prompts/history/stats');
|
|
||||||
const historyData = historyResponse.ok ? await historyResponse.json() : {
|
|
||||||
total_prompts: 0,
|
|
||||||
history_capacity: 60,
|
|
||||||
available_slots: 60,
|
|
||||||
is_full: false
|
|
||||||
};
|
|
||||||
|
|
||||||
setStats({
|
|
||||||
pool: {
|
|
||||||
total: poolData.total_prompts || 0,
|
|
||||||
target: poolData.target_pool_size || 20,
|
|
||||||
sessions: poolData.available_sessions || 0,
|
|
||||||
needsRefill: poolData.needs_refill || true
|
|
||||||
},
|
|
||||||
history: {
|
|
||||||
total: historyData.total_prompts || 0,
|
|
||||||
capacity: historyData.history_capacity || 60,
|
|
||||||
available: historyData.available_slots || 60,
|
|
||||||
isFull: historyData.is_full || false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching stats:', error);
|
|
||||||
// Use default values on error
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleFillPool = async () => {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/api/v1/prompts/fill-pool', { method: 'POST' });
|
|
||||||
if (response.ok) {
|
|
||||||
alert('Prompt pool filled successfully!');
|
|
||||||
// Refresh stats
|
|
||||||
fetchStats();
|
|
||||||
} else {
|
|
||||||
alert('Failed to fill prompt pool');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
alert('Failed to fill prompt pool');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (loading) {
|
|
||||||
return (
|
|
||||||
<div className="text-center p-4">
|
|
||||||
<div className="spinner mx-auto"></div>
|
|
||||||
<p className="mt-2 text-sm">Loading stats...</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<div className="grid grid-cols-2 gap-4 mb-6">
|
|
||||||
<div className="stats-card">
|
|
||||||
<div className="p-3">
|
|
||||||
<i className="fas fa-database fa-2x mb-2" style={{ color: 'var(--primary-color)' }}></i>
|
|
||||||
<div className="stats-value">{stats.pool.total}</div>
|
|
||||||
<div className="stats-label">Prompts in Pool</div>
|
|
||||||
<div className="mt-2 text-sm">
|
|
||||||
Target: {stats.pool.target}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="stats-card">
|
|
||||||
<div className="p-3">
|
|
||||||
<i className="fas fa-history fa-2x mb-2" style={{ color: 'var(--secondary-color)' }}></i>
|
|
||||||
<div className="stats-value">{stats.history.total}</div>
|
|
||||||
<div className="stats-label">History Items</div>
|
|
||||||
<div className="mt-2 text-sm">
|
|
||||||
Capacity: {stats.history.capacity}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<div className="flex justify-between items-center mb-1">
|
|
||||||
<span className="text-sm font-medium">Prompt Pool</span>
|
|
||||||
<span className="text-sm">{stats.pool.total}/{stats.pool.target}</span>
|
|
||||||
</div>
|
|
||||||
<div className="w-full bg-gray-200 rounded-full h-2">
|
|
||||||
<div
|
|
||||||
className="bg-blue-600 h-2 rounded-full transition-all duration-300"
|
|
||||||
style={{ width: `${Math.min((stats.pool.total / stats.pool.target) * 100, 100)}%` }}
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
<div className="text-xs text-gray-600 mt-1">
|
|
||||||
{stats.pool.needsRefill ? (
|
|
||||||
<span className="text-orange-600">
|
|
||||||
<i className="fas fa-exclamation-triangle mr-1"></i>
|
|
||||||
Needs refill ({stats.pool.target - stats.pool.total} prompts needed)
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span className="text-green-600">
|
|
||||||
<i className="fas fa-check-circle mr-1"></i>
|
|
||||||
Pool is full
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<div className="flex justify-between items-center mb-1">
|
|
||||||
<span className="text-sm font-medium">Prompt History</span>
|
|
||||||
<span className="text-sm">{stats.history.total}/{stats.history.capacity}</span>
|
|
||||||
</div>
|
|
||||||
<div className="w-full bg-gray-200 rounded-full h-2">
|
|
||||||
<div
|
|
||||||
className="bg-purple-600 h-2 rounded-full transition-all duration-300"
|
|
||||||
style={{ width: `${Math.min((stats.history.total / stats.history.capacity) * 100, 100)}%` }}
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
<div className="text-xs text-gray-600 mt-1">
|
|
||||||
{stats.history.available} slots available
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="mt-6">
|
|
||||||
<h4 className="font-medium mb-3">Quick Insights</h4>
|
|
||||||
<ul className="space-y-2 text-sm">
|
|
||||||
<li className="flex items-start">
|
|
||||||
<i className="fas fa-calendar-day text-blue-600 mt-1 mr-2"></i>
|
|
||||||
<span>
|
|
||||||
<strong>{stats.pool.sessions} sessions</strong> available in pool
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
<li className="flex items-start">
|
|
||||||
<i className="fas fa-bolt text-yellow-600 mt-1 mr-2"></i>
|
|
||||||
<span>
|
|
||||||
{stats.pool.needsRefill ? (
|
|
||||||
<span className="text-orange-600">Pool needs refilling</span>
|
|
||||||
) : (
|
|
||||||
<span className="text-green-600">Pool is ready for use</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
<li className="flex items-start">
|
|
||||||
<i className="fas fa-brain text-purple-600 mt-1 mr-2"></i>
|
|
||||||
<span>
|
|
||||||
AI has learned from <strong>{stats.history.total} prompts</strong> in history
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
<li className="flex items-start">
|
|
||||||
<i className="fas fa-chart-line text-green-600 mt-1 mr-2"></i>
|
|
||||||
<span>
|
|
||||||
History is <strong>{Math.round((stats.history.total / stats.history.capacity) * 100)}% full</strong>
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{stats.pool.needsRefill && (
|
|
||||||
<div className="mt-6">
|
|
||||||
<button
|
|
||||||
className="btn btn-primary w-full"
|
|
||||||
onClick={handleFillPool}
|
|
||||||
>
|
|
||||||
<i className="fas fa-sync mr-2"></i>
|
|
||||||
Fill Prompt Pool ({stats.pool.target - stats.pool.total} prompts)
|
|
||||||
</button>
|
|
||||||
<p className="text-xs text-gray-600 mt-2 text-center">
|
|
||||||
This will use AI to generate new prompts and fill the pool to target capacity
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default StatsDashboard;
|
|
||||||
|
|
||||||
1
frontend/src/env.d.ts
vendored
1
frontend/src/env.d.ts
vendored
@@ -1 +0,0 @@
|
|||||||
/// <reference path="../.astro/types.d.ts" />
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
---
|
|
||||||
import '../styles/global.css';
|
|
||||||
---
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Daily Journal Prompt Generator</title>
|
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<header>
|
|
||||||
<nav>
|
|
||||||
<div class="logo">
|
|
||||||
<i class="fas fa-book-open"></i>
|
|
||||||
<h1>Daily Journal Prompt Generator</h1>
|
|
||||||
</div>
|
|
||||||
<div class="nav-links">
|
|
||||||
<a href="/"><i class="fas fa-home"></i> Home</a>
|
|
||||||
<a href="/history"><i class="fas fa-history"></i> History</a>
|
|
||||||
<a href="/stats"><i class="fas fa-chart-bar"></i> Stats</a>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main>
|
|
||||||
<slot />
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<footer>
|
|
||||||
<p>Daily Journal Prompt Generator © 2024</p>
|
|
||||||
<p>Powered by AI creativity</p>
|
|
||||||
</footer>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
* {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
|
||||||
line-height: 1.6;
|
|
||||||
color: #333;
|
|
||||||
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
header {
|
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
||||||
color: white;
|
|
||||||
padding: 1rem 2rem;
|
|
||||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
nav {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
max-width: 1200px;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo i {
|
|
||||||
font-size: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo h1 {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-links {
|
|
||||||
display: flex;
|
|
||||||
gap: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-links a {
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
padding: 0.5rem 1rem;
|
|
||||||
border-radius: 4px;
|
|
||||||
transition: background-color 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-links a:hover {
|
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
max-width: 1200px;
|
|
||||||
margin: 2rem auto;
|
|
||||||
padding: 0 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer {
|
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
||||||
color: white;
|
|
||||||
text-align: center;
|
|
||||||
padding: 2rem;
|
|
||||||
margin-top: 3rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer p {
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
nav {
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-links {
|
|
||||||
width: 100%;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
padding: 0 1rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
---
|
|
||||||
import Layout from '../layouts/Layout.astro';
|
|
||||||
import PromptDisplay from '../components/PromptDisplay.jsx';
|
|
||||||
import StatsDashboard from '../components/StatsDashboard.jsx';
|
|
||||||
---
|
|
||||||
|
|
||||||
<Layout>
|
|
||||||
<div class="container">
|
|
||||||
<div class="text-center mb-4">
|
|
||||||
<h1><i class="fas fa-magic"></i> Welcome to Daily Journal Prompt Generator</h1>
|
|
||||||
<p class="mt-2">Get inspired with AI-generated writing prompts for your daily journal practice</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
|
||||||
<div class="lg:col-span-2">
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-header">
|
|
||||||
<h2><i class="fas fa-scroll"></i> Today's Writing Prompt</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<PromptDisplay client:load />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-header">
|
|
||||||
<h2><i class="fas fa-chart-bar"></i> Quick Stats</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<StatsDashboard client:load />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card mt-4">
|
|
||||||
<div class="card-header">
|
|
||||||
<h2><i class="fas fa-lightbulb"></i> Quick Actions</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex flex-col gap-2">
|
|
||||||
<button class="btn btn-primary" onclick="document.querySelector('button[onclick*=\"handleDrawPrompts\"]')?.click()">
|
|
||||||
<i class="fas fa-dice"></i> Draw 3 Prompts
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-secondary" onclick="document.querySelector('button[onclick*=\"handleFillPool\"]')?.click()">
|
|
||||||
<i class="fas fa-sync"></i> Fill Pool
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-warning" onclick="window.location.href='/api/v1/prompts/history'">
|
|
||||||
<i class="fas fa-history"></i> View History (API)
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card mt-4">
|
|
||||||
<div class="card-header">
|
|
||||||
<h2><i class="fas fa-info-circle"></i> How It Works</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
||||||
<div class="text-center">
|
|
||||||
<div class="p-4">
|
|
||||||
<i class="fas fa-robot fa-3x mb-3" style="color: var(--primary-color);"></i>
|
|
||||||
<h3>AI-Powered</h3>
|
|
||||||
<p>Prompts are generated using advanced AI models trained on creative writing</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="text-center">
|
|
||||||
<div class="p-4">
|
|
||||||
<i class="fas fa-brain fa-3x mb-3" style="color: var(--secondary-color);"></i>
|
|
||||||
<h3>Smart History</h3>
|
|
||||||
<p>The AI learns from your previous prompts to avoid repetition and improve relevance</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="text-center">
|
|
||||||
<div class="p-4">
|
|
||||||
<i class="fas fa-battery-full fa-3x mb-3" style="color: var(--success-color);"></i>
|
|
||||||
<h3>Prompt Pool</h3>
|
|
||||||
<p>Always have prompts ready with our caching system that maintains a pool of generated prompts</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Layout>
|
|
||||||
|
|
||||||
@@ -1,361 +0,0 @@
|
|||||||
/* Global styles for Daily Journal Prompt Generator */
|
|
||||||
|
|
||||||
:root {
|
|
||||||
--primary-color: #667eea;
|
|
||||||
--secondary-color: #764ba2;
|
|
||||||
--accent-color: #f56565;
|
|
||||||
--success-color: #48bb78;
|
|
||||||
--warning-color: #ed8936;
|
|
||||||
--info-color: #4299e1;
|
|
||||||
--light-color: #f7fafc;
|
|
||||||
--dark-color: #2d3748;
|
|
||||||
--gray-color: #a0aec0;
|
|
||||||
--border-radius: 8px;
|
|
||||||
--box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
||||||
--transition: all 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reset and base styles */
|
|
||||||
* {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
|
||||||
line-height: 1.6;
|
|
||||||
color: var(--dark-color);
|
|
||||||
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Typography */
|
|
||||||
h1, h2, h3, h4, h5, h6 {
|
|
||||||
font-weight: 600;
|
|
||||||
line-height: 1.2;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
color: var(--dark-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 2.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h3 {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: var(--primary-color);
|
|
||||||
text-decoration: none;
|
|
||||||
transition: var(--transition);
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover {
|
|
||||||
color: var(--secondary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Buttons */
|
|
||||||
.btn {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
padding: 0.75rem 1.5rem;
|
|
||||||
border: none;
|
|
||||||
border-radius: var(--border-radius);
|
|
||||||
font-size: 1rem;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: var(--transition);
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-primary {
|
|
||||||
background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-primary:hover {
|
|
||||||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
|
||||||
opacity: 0.95;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-secondary {
|
|
||||||
background-color: white;
|
|
||||||
color: var(--primary-color);
|
|
||||||
border: 2px solid var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-secondary:hover {
|
|
||||||
background-color: var(--primary-color);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-success {
|
|
||||||
background-color: var(--success-color);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-warning {
|
|
||||||
background-color: var(--warning-color);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-danger {
|
|
||||||
background-color: var(--accent-color);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn:disabled {
|
|
||||||
opacity: 0.6;
|
|
||||||
cursor: not-allowed;
|
|
||||||
transform: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Cards */
|
|
||||||
.card {
|
|
||||||
background: white;
|
|
||||||
border-radius: var(--border-radius);
|
|
||||||
box-shadow: var(--box-shadow);
|
|
||||||
padding: 1.5rem;
|
|
||||||
margin-bottom: 1.5rem;
|
|
||||||
transition: var(--transition);
|
|
||||||
}
|
|
||||||
|
|
||||||
.card:hover {
|
|
||||||
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.card-header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
padding-bottom: 0.5rem;
|
|
||||||
border-bottom: 2px solid var(--light-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Forms */
|
|
||||||
.form-group {
|
|
||||||
margin-bottom: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-label {
|
|
||||||
display: block;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--dark-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-control {
|
|
||||||
width: 100%;
|
|
||||||
padding: 0.75rem;
|
|
||||||
border: 2px solid var(--gray-color);
|
|
||||||
border-radius: var(--border-radius);
|
|
||||||
font-size: 1rem;
|
|
||||||
transition: var(--transition);
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-control:focus {
|
|
||||||
outline: none;
|
|
||||||
border-color: var(--primary-color);
|
|
||||||
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-control.error {
|
|
||||||
border-color: var(--accent-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-error {
|
|
||||||
color: var(--accent-color);
|
|
||||||
font-size: 0.875rem;
|
|
||||||
margin-top: 0.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Alerts */
|
|
||||||
.alert {
|
|
||||||
padding: 1rem;
|
|
||||||
border-radius: var(--border-radius);
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
border-left: 4px solid;
|
|
||||||
}
|
|
||||||
|
|
||||||
.alert-success {
|
|
||||||
background-color: rgba(72, 187, 120, 0.1);
|
|
||||||
border-left-color: var(--success-color);
|
|
||||||
color: #22543d;
|
|
||||||
}
|
|
||||||
|
|
||||||
.alert-warning {
|
|
||||||
background-color: rgba(237, 137, 54, 0.1);
|
|
||||||
border-left-color: var(--warning-color);
|
|
||||||
color: #744210;
|
|
||||||
}
|
|
||||||
|
|
||||||
.alert-error {
|
|
||||||
background-color: rgba(245, 101, 101, 0.1);
|
|
||||||
border-left-color: var(--accent-color);
|
|
||||||
color: #742a2a;
|
|
||||||
}
|
|
||||||
|
|
||||||
.alert-info {
|
|
||||||
background-color: rgba(66, 153, 225, 0.1);
|
|
||||||
border-left-color: var(--info-color);
|
|
||||||
color: #2a4365;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Loading spinner */
|
|
||||||
.spinner {
|
|
||||||
display: inline-block;
|
|
||||||
width: 2rem;
|
|
||||||
height: 2rem;
|
|
||||||
border: 3px solid rgba(0, 0, 0, 0.1);
|
|
||||||
border-radius: 50%;
|
|
||||||
border-top-color: var(--primary-color);
|
|
||||||
animation: spin 1s ease-in-out infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes spin {
|
|
||||||
to {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Utility classes */
|
|
||||||
.container {
|
|
||||||
max-width: 1200px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 0 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.text-center {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mt-1 { margin-top: 0.5rem; }
|
|
||||||
.mt-2 { margin-top: 1rem; }
|
|
||||||
.mt-3 { margin-top: 1.5rem; }
|
|
||||||
.mt-4 { margin-top: 2rem; }
|
|
||||||
|
|
||||||
.mb-1 { margin-bottom: 0.5rem; }
|
|
||||||
.mb-2 { margin-bottom: 1rem; }
|
|
||||||
.mb-3 { margin-bottom: 1.5rem; }
|
|
||||||
.mb-4 { margin-bottom: 2rem; }
|
|
||||||
|
|
||||||
.p-1 { padding: 0.5rem; }
|
|
||||||
.p-2 { padding: 1rem; }
|
|
||||||
.p-3 { padding: 1.5rem; }
|
|
||||||
.p-4 { padding: 2rem; }
|
|
||||||
|
|
||||||
.flex {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.flex-col {
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.items-center {
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.justify-between {
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
|
|
||||||
.justify-center {
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gap-1 { gap: 0.5rem; }
|
|
||||||
.gap-2 { gap: 1rem; }
|
|
||||||
.gap-3 { gap: 1.5rem; }
|
|
||||||
.gap-4 { gap: 2rem; }
|
|
||||||
|
|
||||||
.grid {
|
|
||||||
display: grid;
|
|
||||||
gap: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.grid-cols-1 { grid-template-columns: 1fr; }
|
|
||||||
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
|
|
||||||
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
|
|
||||||
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.grid-cols-2,
|
|
||||||
.grid-cols-3,
|
|
||||||
.grid-cols-4 {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn {
|
|
||||||
padding: 0.5rem 1rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Prompt card specific styles */
|
|
||||||
.prompt-card {
|
|
||||||
background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
|
|
||||||
border-left: 4px solid var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.prompt-card.selected {
|
|
||||||
border-left-color: var(--success-color);
|
|
||||||
background: linear-gradient(135deg, #f0fff4 0%, #e6fffa 100%);
|
|
||||||
}
|
|
||||||
|
|
||||||
.prompt-text {
|
|
||||||
font-size: 1.1rem;
|
|
||||||
line-height: 1.8;
|
|
||||||
color: var(--dark-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.prompt-meta {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-top: 1rem;
|
|
||||||
padding-top: 1rem;
|
|
||||||
border-top: 1px solid var(--light-color);
|
|
||||||
font-size: 0.875rem;
|
|
||||||
color: var(--gray-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Stats cards */
|
|
||||||
.stats-card {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stats-value {
|
|
||||||
font-size: 2.5rem;
|
|
||||||
font-weight: 700;
|
|
||||||
color: var(--primary-color);
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stats-label {
|
|
||||||
font-size: 0.875rem;
|
|
||||||
color: var(--gray-color);
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.05em;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -30,8 +30,6 @@ class JournalPromptGenerator:
|
|||||||
self.client = None
|
self.client = None
|
||||||
self.historic_prompts = []
|
self.historic_prompts = []
|
||||||
self.pool_prompts = []
|
self.pool_prompts = []
|
||||||
self.feedback_words = []
|
|
||||||
self.feedback_historic = []
|
|
||||||
self.prompt_template = ""
|
self.prompt_template = ""
|
||||||
self.settings = {}
|
self.settings = {}
|
||||||
|
|
||||||
@@ -43,8 +41,6 @@ class JournalPromptGenerator:
|
|||||||
self._load_prompt_template()
|
self._load_prompt_template()
|
||||||
self._load_historic_prompts()
|
self._load_historic_prompts()
|
||||||
self._load_pool_prompts()
|
self._load_pool_prompts()
|
||||||
self._load_feedback_words()
|
|
||||||
self._load_feedback_historic()
|
|
||||||
|
|
||||||
def _load_config(self):
|
def _load_config(self):
|
||||||
"""Load configuration from environment file."""
|
"""Load configuration from environment file."""
|
||||||
@@ -124,13 +120,13 @@ class JournalPromptGenerator:
|
|||||||
def _load_historic_prompts(self):
|
def _load_historic_prompts(self):
|
||||||
"""Load historic prompts from JSON file."""
|
"""Load historic prompts from JSON file."""
|
||||||
try:
|
try:
|
||||||
with open("prompts_historic.json", "r") as f:
|
with open("historic_prompts.json", "r") as f:
|
||||||
self.historic_prompts = json.load(f)
|
self.historic_prompts = json.load(f)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.console.print("[yellow]Warning: prompts_historic.json not found, starting with empty history[/yellow]")
|
self.console.print("[yellow]Warning: historic_prompts.json not found, starting with empty history[/yellow]")
|
||||||
self.historic_prompts = []
|
self.historic_prompts = []
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
self.console.print("[yellow]Warning: prompts_historic.json is corrupted, starting with empty history[/yellow]")
|
self.console.print("[yellow]Warning: historic_prompts.json is corrupted, starting with empty history[/yellow]")
|
||||||
self.historic_prompts = []
|
self.historic_prompts = []
|
||||||
|
|
||||||
def _save_historic_prompts(self):
|
def _save_historic_prompts(self):
|
||||||
@@ -139,62 +135,24 @@ class JournalPromptGenerator:
|
|||||||
if len(self.historic_prompts) > 60:
|
if len(self.historic_prompts) > 60:
|
||||||
self.historic_prompts = self.historic_prompts[:60]
|
self.historic_prompts = self.historic_prompts[:60]
|
||||||
|
|
||||||
with open("prompts_historic.json", "w") as f:
|
with open("historic_prompts.json", "w") as f:
|
||||||
json.dump(self.historic_prompts, f, indent=2)
|
json.dump(self.historic_prompts, f, indent=2)
|
||||||
|
|
||||||
def _load_pool_prompts(self):
|
def _load_pool_prompts(self):
|
||||||
"""Load pool prompts from JSON file."""
|
"""Load pool prompts from JSON file."""
|
||||||
try:
|
try:
|
||||||
with open("prompts_pool.json", "r") as f:
|
with open("pool_prompts.json", "r") as f:
|
||||||
self.pool_prompts = json.load(f)
|
self.pool_prompts = json.load(f)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.console.print("[yellow]Warning: prompts_pool.json not found, starting with empty pool[/yellow]")
|
self.console.print("[yellow]Warning: pool_prompts.json not found, starting with empty pool[/yellow]")
|
||||||
self.pool_prompts = []
|
self.pool_prompts = []
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
self.console.print("[yellow]Warning: prompts_pool.json is corrupted, starting with empty pool[/yellow]")
|
self.console.print("[yellow]Warning: pool_prompts.json is corrupted, starting with empty pool[/yellow]")
|
||||||
self.pool_prompts = []
|
self.pool_prompts = []
|
||||||
|
|
||||||
def _load_feedback_words(self):
|
|
||||||
"""Load feedback words from JSON file."""
|
|
||||||
try:
|
|
||||||
with open("feedback_words.json", "r") as f:
|
|
||||||
self.feedback_words = json.load(f)
|
|
||||||
except FileNotFoundError:
|
|
||||||
self.console.print("[yellow]Warning: feedback_words.json not found, starting with empty feedback words[/yellow]")
|
|
||||||
self.feedback_words = []
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
self.console.print("[yellow]Warning: feedback_words.json is corrupted, starting with empty feedback words[/yellow]")
|
|
||||||
self.feedback_words = []
|
|
||||||
|
|
||||||
def _load_feedback_historic(self):
|
|
||||||
"""Load historic feedback words from JSON file."""
|
|
||||||
try:
|
|
||||||
with open("feedback_historic.json", "r") as f:
|
|
||||||
self.feedback_historic = json.load(f)
|
|
||||||
except FileNotFoundError:
|
|
||||||
self.console.print("[yellow]Warning: feedback_historic.json not found, starting with empty feedback history[/yellow]")
|
|
||||||
self.feedback_historic = []
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
self.console.print("[yellow]Warning: feedback_historic.json is corrupted, starting with empty feedback history[/yellow]")
|
|
||||||
self.feedback_historic = []
|
|
||||||
|
|
||||||
def _save_feedback_words(self):
|
|
||||||
"""Save feedback words to JSON file."""
|
|
||||||
with open("feedback_words.json", "w") as f:
|
|
||||||
json.dump(self.feedback_words, f, indent=2)
|
|
||||||
|
|
||||||
def _save_feedback_historic(self):
|
|
||||||
"""Save historic feedback words to JSON file (keeping only first 30)."""
|
|
||||||
# Keep only the first 30 feedback words (newest are at the beginning)
|
|
||||||
if len(self.feedback_historic) > 30:
|
|
||||||
self.feedback_historic = self.feedback_historic[:30]
|
|
||||||
|
|
||||||
with open("feedback_historic.json", "w") as f:
|
|
||||||
json.dump(self.feedback_historic, f, indent=2)
|
|
||||||
|
|
||||||
def _save_pool_prompts(self):
|
def _save_pool_prompts(self):
|
||||||
"""Save pool prompts to JSON file."""
|
"""Save pool prompts to JSON file."""
|
||||||
with open("prompts_pool.json", "w") as f:
|
with open("pool_prompts.json", "w") as f:
|
||||||
json.dump(self.pool_prompts, f, indent=2)
|
json.dump(self.pool_prompts, f, indent=2)
|
||||||
|
|
||||||
def add_prompts_to_pool(self, prompts: List[str]):
|
def add_prompts_to_pool(self, prompts: List[str]):
|
||||||
@@ -228,6 +186,22 @@ class JournalPromptGenerator:
|
|||||||
return drawn_prompts
|
return drawn_prompts
|
||||||
|
|
||||||
|
|
||||||
|
def show_pool_stats(self):
|
||||||
|
"""Show statistics about the prompt pool."""
|
||||||
|
total_prompts = len(self.pool_prompts)
|
||||||
|
|
||||||
|
table = Table(title="Prompt Pool Statistics")
|
||||||
|
table.add_column("Metric", style="cyan")
|
||||||
|
table.add_column("Value", style="green")
|
||||||
|
|
||||||
|
table.add_row("Prompts in pool", str(total_prompts))
|
||||||
|
table.add_row("Prompts per session", str(self.settings['num_prompts']))
|
||||||
|
table.add_row("Target pool size", str(self.settings['cached_pool_volume']))
|
||||||
|
table.add_row("Available sessions", str(total_prompts // self.settings['num_prompts']))
|
||||||
|
|
||||||
|
self.console.print(table)
|
||||||
|
|
||||||
|
|
||||||
def add_prompt_to_history(self, prompt_text: str):
|
def add_prompt_to_history(self, prompt_text: str):
|
||||||
"""
|
"""
|
||||||
Add a single prompt to the historic prompts cyclic buffer.
|
Add a single prompt to the historic prompts cyclic buffer.
|
||||||
@@ -260,53 +234,6 @@ class JournalPromptGenerator:
|
|||||||
self.historic_prompts = updated_prompts
|
self.historic_prompts = updated_prompts
|
||||||
self._save_historic_prompts()
|
self._save_historic_prompts()
|
||||||
|
|
||||||
def add_feedback_words_to_history(self):
|
|
||||||
"""
|
|
||||||
Add current feedback words to the historic feedback words cyclic buffer.
|
|
||||||
The 6 new feedback words become feedback00-feedback05, all others shift down,
|
|
||||||
and feedback29 is discarded (keeping only 30 items total).
|
|
||||||
"""
|
|
||||||
# Extract just the words from the current feedback words
|
|
||||||
# Current feedback_words structure: [{"feedback00": "word", "weight": 3}, ...]
|
|
||||||
new_feedback_words = []
|
|
||||||
|
|
||||||
for i, feedback_item in enumerate(self.feedback_words):
|
|
||||||
# Get the word from the feedback item (key is feedback00, feedback01, etc.)
|
|
||||||
feedback_key = f"feedback{i:02d}"
|
|
||||||
if feedback_key in feedback_item:
|
|
||||||
word = feedback_item[feedback_key]
|
|
||||||
# Create new feedback word object with just the word (no weight)
|
|
||||||
new_feedback_words.append({
|
|
||||||
feedback_key: word
|
|
||||||
})
|
|
||||||
|
|
||||||
# If we don't have 6 feedback words, we can't add them to history
|
|
||||||
if len(new_feedback_words) != 6:
|
|
||||||
self.console.print(f"[yellow]Warning: Expected 6 feedback words, got {len(new_feedback_words)}. Not adding to history.[/yellow]")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Shift all existing feedback words down by 6 positions
|
|
||||||
# We'll create a new list starting with the 6 new feedback words
|
|
||||||
updated_feedback_historic = new_feedback_words
|
|
||||||
|
|
||||||
# Add all existing feedback words, shifting their numbers down by 6
|
|
||||||
for i, feedback_dict in enumerate(self.feedback_historic):
|
|
||||||
if i >= 24: # We only keep 30 feedback words total (00-29), and we've already added 6
|
|
||||||
break
|
|
||||||
|
|
||||||
# Get the feedback word
|
|
||||||
feedback_key = list(feedback_dict.keys())[0]
|
|
||||||
word = feedback_dict[feedback_key]
|
|
||||||
|
|
||||||
# Create feedback word with new number (shifted down by 6)
|
|
||||||
new_feedback_key = f"feedback{i+6:02d}"
|
|
||||||
updated_feedback_historic.append({
|
|
||||||
new_feedback_key: word
|
|
||||||
})
|
|
||||||
|
|
||||||
self.feedback_historic = updated_feedback_historic
|
|
||||||
self._save_feedback_historic()
|
|
||||||
self.console.print("[green]Added 6 feedback words to history[/green]")
|
|
||||||
|
|
||||||
def _parse_ai_response(self, response_content: str) -> List[str]:
|
def _parse_ai_response(self, response_content: str) -> List[str]:
|
||||||
"""
|
"""
|
||||||
@@ -502,11 +429,6 @@ class JournalPromptGenerator:
|
|||||||
else:
|
else:
|
||||||
full_prompt = f"{template}\n\n{prompt_instruction}"
|
full_prompt = f"{template}\n\n{prompt_instruction}"
|
||||||
|
|
||||||
# Add feedback words if available
|
|
||||||
if self.feedback_words:
|
|
||||||
feedback_context = json.dumps(self.feedback_words, indent=2)
|
|
||||||
full_prompt = f"{full_prompt}\n\nFeedback words:\n{feedback_context}"
|
|
||||||
|
|
||||||
return full_prompt
|
return full_prompt
|
||||||
|
|
||||||
def _parse_ai_response_with_count(self, response_content: str, expected_count: int) -> List[str]:
|
def _parse_ai_response_with_count(self, response_content: str, expected_count: int) -> List[str]:
|
||||||
@@ -588,162 +510,6 @@ class JournalPromptGenerator:
|
|||||||
self.console.print("[red]Failed to generate prompts[/red]")
|
self.console.print("[red]Failed to generate prompts[/red]")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def generate_theme_feedback_words(self) -> List[str]:
|
|
||||||
"""Generate 6 theme feedback words using AI based on historic prompts."""
|
|
||||||
self.console.print("\n[cyan]Generating theme feedback words based on historic prompts...[/cyan]")
|
|
||||||
|
|
||||||
# Load the feedback prompt template
|
|
||||||
try:
|
|
||||||
with open("ds_feedback.txt", "r") as f:
|
|
||||||
feedback_template = f.read()
|
|
||||||
except FileNotFoundError:
|
|
||||||
self.console.print("[red]Error: ds_feedback.txt not found[/red]")
|
|
||||||
return []
|
|
||||||
|
|
||||||
# Prepare the full prompt with historic context and feedback words
|
|
||||||
if self.historic_prompts:
|
|
||||||
historic_context = json.dumps(self.historic_prompts, indent=2)
|
|
||||||
full_prompt = f"{feedback_template}\n\nPrevious prompts:\n{historic_context}"
|
|
||||||
|
|
||||||
# Add current feedback words if available (with weights)
|
|
||||||
if self.feedback_words:
|
|
||||||
feedback_context = json.dumps(self.feedback_words, indent=2)
|
|
||||||
full_prompt = f"{full_prompt}\n\nCurrent feedback themes (with weights):\n{feedback_context}"
|
|
||||||
|
|
||||||
# Add historic feedback words if available (just words, no weights)
|
|
||||||
if self.feedback_historic:
|
|
||||||
feedback_historic_context = json.dumps(self.feedback_historic, indent=2)
|
|
||||||
full_prompt = f"{full_prompt}\n\nHistoric feedback themes (just words):\n{feedback_historic_context}"
|
|
||||||
else:
|
|
||||||
self.console.print("[yellow]Warning: No historic prompts available for feedback analysis[/yellow]")
|
|
||||||
return []
|
|
||||||
|
|
||||||
# Show progress
|
|
||||||
with Progress(
|
|
||||||
SpinnerColumn(),
|
|
||||||
TextColumn("[progress.description]{task.description}"),
|
|
||||||
transient=True,
|
|
||||||
) as progress:
|
|
||||||
task = progress.add_task("Calling AI API for theme analysis...", total=None)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Call the AI API
|
|
||||||
response = self.client.chat.completions.create(
|
|
||||||
model=self.model,
|
|
||||||
messages=[
|
|
||||||
{"role": "system", "content": "You are a creative writing assistant that analyzes writing prompts. Always respond with valid JSON."},
|
|
||||||
{"role": "user", "content": full_prompt}
|
|
||||||
],
|
|
||||||
temperature=0.7,
|
|
||||||
max_tokens=1000
|
|
||||||
)
|
|
||||||
|
|
||||||
response_content = response.choices[0].message.content
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
self.console.print(f"[red]Error calling AI API: {e}[/red]")
|
|
||||||
self.console.print(f"[yellow]Full prompt sent to API (first 500 chars):[/yellow]")
|
|
||||||
self.console.print(f"[yellow]{full_prompt[:500]}...[/yellow]")
|
|
||||||
return []
|
|
||||||
|
|
||||||
# Parse the response to get 6 theme words
|
|
||||||
theme_words = self._parse_theme_words_response(response_content)
|
|
||||||
|
|
||||||
if not theme_words or len(theme_words) != 6:
|
|
||||||
self.console.print(f"[red]Error: Expected 6 theme words, got {len(theme_words) if theme_words else 0}[/red]")
|
|
||||||
return []
|
|
||||||
|
|
||||||
return theme_words
|
|
||||||
|
|
||||||
def _parse_theme_words_response(self, response_content: str) -> List[str]:
|
|
||||||
"""
|
|
||||||
Parse the AI response to extract 6 theme words.
|
|
||||||
Expected format: JSON list of 6 lowercase words.
|
|
||||||
"""
|
|
||||||
# First, try to clean up the response content
|
|
||||||
cleaned_content = self._clean_ai_response(response_content)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Try to parse as JSON
|
|
||||||
data = json.loads(cleaned_content)
|
|
||||||
|
|
||||||
# Check if data is a list
|
|
||||||
if isinstance(data, list):
|
|
||||||
# Ensure all items are strings and lowercase them
|
|
||||||
theme_words = []
|
|
||||||
for word in data:
|
|
||||||
if isinstance(word, str):
|
|
||||||
theme_words.append(word.lower().strip())
|
|
||||||
else:
|
|
||||||
theme_words.append(str(word).lower().strip())
|
|
||||||
|
|
||||||
return theme_words
|
|
||||||
else:
|
|
||||||
self.console.print(f"[yellow]Warning: AI returned unexpected data type: {type(data)}[/yellow]")
|
|
||||||
return []
|
|
||||||
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
# If not valid JSON, try to extract words from text
|
|
||||||
self.console.print("[yellow]Warning: AI response is not valid JSON, attempting to extract theme words...[/yellow]")
|
|
||||||
|
|
||||||
# Look for patterns in the text
|
|
||||||
lines = response_content.strip().split('\n')
|
|
||||||
theme_words = []
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
line = line.strip()
|
|
||||||
if line and len(line) < 50: # Theme words should be short
|
|
||||||
# Try to extract words (lowercase, no punctuation)
|
|
||||||
words = [w.lower().strip('.,;:!?()[]{}"\'') for w in line.split()]
|
|
||||||
theme_words.extend(words)
|
|
||||||
|
|
||||||
if len(theme_words) >= 6:
|
|
||||||
break
|
|
||||||
|
|
||||||
return theme_words[:6]
|
|
||||||
|
|
||||||
def collect_feedback_ratings(self, theme_words: List[str]) -> List[Dict[str, Any]]:
|
|
||||||
"""Collect user ratings (0-6) for each theme word and return structured feedback."""
|
|
||||||
self.console.print("\n[bold]Please rate each theme word from 0 to 6:[/bold]")
|
|
||||||
self.console.print("[dim]0 = Not relevant, 6 = Very relevant[/dim]\n")
|
|
||||||
|
|
||||||
feedback_items = []
|
|
||||||
|
|
||||||
for i, word in enumerate(theme_words):
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
rating = Prompt.ask(
|
|
||||||
f"[bold]Word {i+1}: {word}[/bold]",
|
|
||||||
choices=[str(x) for x in range(0, 7)], # 0-6 inclusive
|
|
||||||
default="3"
|
|
||||||
)
|
|
||||||
rating_int = int(rating)
|
|
||||||
|
|
||||||
if 0 <= rating_int <= 6:
|
|
||||||
# Create feedback item with key (feedback00, feedback01, etc.)
|
|
||||||
feedback_key = f"feedback{i:02d}"
|
|
||||||
feedback_items.append({
|
|
||||||
feedback_key: word,
|
|
||||||
"weight": rating_int
|
|
||||||
})
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
self.console.print("[yellow]Please enter a number between 0 and 6[/yellow]")
|
|
||||||
except ValueError:
|
|
||||||
self.console.print("[yellow]Please enter a valid number[/yellow]")
|
|
||||||
|
|
||||||
return feedback_items
|
|
||||||
|
|
||||||
def update_feedback_words(self, new_feedback_items: List[Dict[str, Any]]):
|
|
||||||
"""Update feedback words with new ratings."""
|
|
||||||
# Replace existing feedback words with new ones
|
|
||||||
self.feedback_words = new_feedback_items
|
|
||||||
self._save_feedback_words()
|
|
||||||
self.console.print(f"[green]Updated feedback words with {len(new_feedback_items)} items[/green]")
|
|
||||||
|
|
||||||
# Also add the new feedback words to the historic buffer
|
|
||||||
self.add_feedback_words_to_history()
|
|
||||||
|
|
||||||
def display_prompts(self, prompts: List[str]):
|
def display_prompts(self, prompts: List[str]):
|
||||||
"""Display generated prompts in a nice format."""
|
"""Display generated prompts in a nice format."""
|
||||||
self.console.print("\n" + "="*60)
|
self.console.print("\n" + "="*60)
|
||||||
@@ -761,33 +527,19 @@ class JournalPromptGenerator:
|
|||||||
self.console.print(panel)
|
self.console.print(panel)
|
||||||
self.console.print() # Empty line between prompts
|
self.console.print() # Empty line between prompts
|
||||||
|
|
||||||
def show_combined_stats(self):
|
def show_history_stats(self):
|
||||||
"""Show combined statistics about both prompt pool and history."""
|
"""Show statistics about prompt history."""
|
||||||
# Pool statistics
|
total_prompts = len(self.historic_prompts)
|
||||||
total_pool_prompts = len(self.pool_prompts)
|
|
||||||
pool_table = Table(title="Prompt Pool Statistics")
|
|
||||||
pool_table.add_column("Metric", style="cyan")
|
|
||||||
pool_table.add_column("Value", style="green")
|
|
||||||
|
|
||||||
pool_table.add_row("Prompts in pool", str(total_pool_prompts))
|
table = Table(title="Prompt History Statistics")
|
||||||
pool_table.add_row("Prompts per session", str(self.settings['num_prompts']))
|
table.add_column("Metric", style="cyan")
|
||||||
pool_table.add_row("Target pool size", str(self.settings['cached_pool_volume']))
|
table.add_column("Value", style="green")
|
||||||
pool_table.add_row("Available sessions", str(total_pool_prompts // self.settings['num_prompts']))
|
|
||||||
|
|
||||||
# History statistics
|
table.add_row("Total prompts in history", str(total_prompts))
|
||||||
total_history_prompts = len(self.historic_prompts)
|
table.add_row("History capacity", "60 prompts")
|
||||||
history_table = Table(title="Prompt History Statistics")
|
table.add_row("Available slots", str(max(0, 60 - total_prompts)))
|
||||||
history_table.add_column("Metric", style="cyan")
|
|
||||||
history_table.add_column("Value", style="green")
|
|
||||||
|
|
||||||
history_table.add_row("Total prompts in history", str(total_history_prompts))
|
self.console.print(table)
|
||||||
history_table.add_row("History capacity", "60 prompts")
|
|
||||||
history_table.add_row("Available slots", str(max(0, 60 - total_history_prompts)))
|
|
||||||
|
|
||||||
# Display both tables
|
|
||||||
self.console.print(pool_table)
|
|
||||||
self.console.print() # Empty line between tables
|
|
||||||
self.console.print(history_table)
|
|
||||||
|
|
||||||
def interactive_mode(self):
|
def interactive_mode(self):
|
||||||
"""Run in interactive mode with user prompts."""
|
"""Run in interactive mode with user prompts."""
|
||||||
@@ -813,8 +565,8 @@ class JournalPromptGenerator:
|
|||||||
self.console.print("\n[bold]Options:[/bold]")
|
self.console.print("\n[bold]Options:[/bold]")
|
||||||
self.console.print("1. Draw prompts from pool (no API call)")
|
self.console.print("1. Draw prompts from pool (no API call)")
|
||||||
self.console.print("2. Fill prompt pool using API")
|
self.console.print("2. Fill prompt pool using API")
|
||||||
self.console.print("3. View combined statistics")
|
self.console.print("3. View pool statistics")
|
||||||
self.console.print("4. Generate and rate theme feedback words")
|
self.console.print("4. View history statistics")
|
||||||
self.console.print("5. Exit")
|
self.console.print("5. Exit")
|
||||||
|
|
||||||
choice = Prompt.ask("\nEnter your choice", choices=["1", "2", "3", "4", "5"], default="1")
|
choice = Prompt.ask("\nEnter your choice", choices=["1", "2", "3", "4", "5"], default="1")
|
||||||
@@ -848,16 +600,10 @@ class JournalPromptGenerator:
|
|||||||
self.console.print("[yellow]No prompts were added to pool[/yellow]")
|
self.console.print("[yellow]No prompts were added to pool[/yellow]")
|
||||||
|
|
||||||
elif choice == "3":
|
elif choice == "3":
|
||||||
self.show_combined_stats()
|
self.show_pool_stats()
|
||||||
|
|
||||||
elif choice == "4":
|
elif choice == "4":
|
||||||
# Generate and rate theme feedback words
|
self.show_history_stats()
|
||||||
theme_words = self.generate_theme_feedback_words()
|
|
||||||
if theme_words:
|
|
||||||
feedback_items = self.collect_feedback_ratings(theme_words)
|
|
||||||
self.update_feedback_words(feedback_items)
|
|
||||||
else:
|
|
||||||
self.console.print("[yellow]No theme words were generated[/yellow]")
|
|
||||||
|
|
||||||
elif choice == "5":
|
elif choice == "5":
|
||||||
self.console.print("[green]Goodbye! Happy journaling! 📓[/green]")
|
self.console.print("[green]Goodbye! Happy journaling! 📓[/green]")
|
||||||
@@ -880,7 +626,12 @@ def main():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--stats", "-s",
|
"--stats", "-s",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Show combined statistics (pool and history)"
|
help="Show history statistics"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--pool-stats", "-p",
|
||||||
|
action="store_true",
|
||||||
|
help="Show pool statistics"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--fill-pool", "-f",
|
"--fill-pool", "-f",
|
||||||
@@ -894,7 +645,9 @@ def main():
|
|||||||
generator = JournalPromptGenerator(config_path=args.config)
|
generator = JournalPromptGenerator(config_path=args.config)
|
||||||
|
|
||||||
if args.stats:
|
if args.stats:
|
||||||
generator.show_combined_stats()
|
generator.show_history_stats()
|
||||||
|
elif args.pool_stats:
|
||||||
|
generator.show_pool_stats()
|
||||||
elif args.fill_pool:
|
elif args.fill_pool:
|
||||||
# Fill prompt pool to target volume using API
|
# Fill prompt pool to target volume using API
|
||||||
total_added = generator.fill_pool_to_target()
|
total_added = generator.fill_pool_to_target()
|
||||||
|
|||||||
182
historic_prompts.json
Normal file
182
historic_prompts.json
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"prompt00": "Choose a street you walk down often. Today, walk it with the mission of noticing five things you've never seen before. They can be tiny: a crack in the pavement shaped like a continent, a particular stain on a wall, a hidden doorbell. Document each discovery in detail. Then, reflect on the phenomenon of selective attention. What had you been filtering out, and why? How does this exercise change your sense of the familiar path?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt01": "Imagine you could host a dinner party for three fictional characters from different books, films, or myths. Who would you invite and why? Don't just list them. Set the scene: the table setting, the menu, the lighting. Write the conversation that unfolds. What would they argue about? What surprising common ground might they find? How would their presence challenge or affirm your own worldview? Let the dialogue reveal their core natures."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt02": "Describe a taste you loved as a child but have since grown indifferent to or now dislike. Recreate the sensory memory of that taste with precision. What was its context? Who was with you? Now, analyze the shift. Did your palate change, or did the associations sour? Is there a way to reclaim the innocent pleasure of that taste, or is its loss a necessary marker of growing up? Explore the nostalgia and slight grief in outgrowing a flavor."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt03": "Contemplate the concept of 'waste' in your daily life. Choose one item destined for the trash or recycling. Trace its journey backwards from your hand to its origins as raw material. Then, project its journey forward after it leaves your custody. What systems does it touch? What hands might process it? Write a biography of this discarded object, granting it dignity and narrative. How does this perspective alter your sense of responsibility and connection?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt04": "Invent a small, personal ritual you could perform to mark the transition from one part of your day to another (e.g., work to home, waking to activity). Describe each step with deliberate, sensory care. What object is involved? What words, if any, are said? How does your posture change? The goal isn't superstition, but mindfulness. Write about performing this ritual for a week. What subtle shifts in your awareness might it create? How does deliberately carving out a threshold affect your experience of time?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt05": "Consider a piece of music that feels like a physical space to you\u2014a song you can walk into. Describe the architecture of this auditory landscape. What is the floor made of? How high is the ceiling? What color is the light? Where are the shadows? What happens to your body and breath as you move through its sections\u2014the verses, the chorus, the bridge? Is it a place of refuge, confrontation, or memory? Explore how sound can build an environment you inhabit, not just hear."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt06": "Describe your ideal sanctuary\u2014not a grand fantasy, but a realistically attainable space you could create. Detail its location, size, lighting, furnishings, and most importantly, its rules (e.g., 'no devices,' 'only music without words,' 'must contain something living'). What specific activities would you do there? What state of mind does this space architecturally encourage? How would visiting it regularly change the rhythm of your weeks?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt07": "Describe a skill or piece of knowledge you possess that you learned in an unconventional, self-taught, or accidental way. Detail the messy, non-linear process of that learning. Who or what were your unlikely teachers? Celebrate the inefficiency and personal quirks of your method. How does this 'uncurated' knowledge differ in feel and application from something you were formally taught?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt08": "Think of a skill or piece of knowledge you possess that feels almost instinctual, something you can do without conscious thought (like riding a bike, typing, or a native language's grammar). Deconstruct this automatic competence. Describe the first clumsy attempts to learn it, the plateau of frustration, the moment it 'clicked' into muscle memory. Explore the duality of this knowledge: how it is both a part of you and a separate tool. What does this ingrained ability allow you to forget, and what freedom does that forgetfulness grant?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt09": "Choose a natural element you feel a kinship with\u2014fire, stone, water, wind, or earth. Personify it deeply: give it desires, memories, a voice. Write a monologue from its perspective about its ancient, slow existence and its observations of human brevity and frenzy. Then, write about a moment in your life when you felt most aligned with this element's essence. How does connecting with this primal force alter your sense of time and scale?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt10": "Imagine you could preserve one hour from your recent memory in a vial, to be re-experienced fully at a future date. Which hour would you choose? Describe it not just as events, but as a full sensory immersion: the light, the sounds, the emotional texture, the quality of the air. Why is this particular slice of time worth encapsulating? What fears or hopes do you have about opening that vial years from now? Write about the desire to hold onto a fleeting feeling, and the wisdom or melancholy that might come from revisiting it."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt11": "Contemplate the concept of 'enough.' In our culture of more, what does sufficiency feel like in your body and mind? Describe a recent moment when you felt truly, deeply 'enough'\u2014not in lack, not in excess. It could be related to time, accomplishment, possessions, or love. What were the conditions? How did it settle in your posture or breath? Then, contrast this with a sphere of your life where the feeling of 'not enough' persistently hums. Explore the tension between these two states. What would it take to cultivate more of the former?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt12": "Recall a piece of bad advice you once received and followed. Who gave it and why did you trust them? Walk through the consequences, large or small. Now, reframe that experience not as a mistake, but as a necessary detour. What did you learn about yourself, about advice, or about the gap between theory and practice that you couldn't have learned any other way? Write the thank-you note you would send to that advisor today, acknowledging the unexpected gift of their misguidance."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt13": "You are tasked with composing a guided audio meditation for a stranger experiencing intense anxiety. Write the script. Use your voice to lead them through a physical space\u2014a forest path, a quiet beach, a cozy room. Describe not just visuals, but textures, sounds, temperatures, and the rhythm of breathing. What reassurance would you offer without being trite? What simple, grounding observations would you point out? Craft a verbal sanctuary meant to hold someone's fragile attention."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt14": "Recall a piece of clothing you once owned and loved, but have since lost, given away, or worn out. Recreate it stitch by stitch in words\u2014its fabric, its fit, its smell, the way it moved with you. Narrate its life with you: the occasions it witnessed, the stains it earned, the comfort it provided. What did wearing it allow you to feel or project? Write an ode to this second skin, and explore what its absence represents."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt15": "Test prompt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt16": "Observe the sky right now, in this exact moment. Describe its color, cloud formations, light quality, and movement with meticulous attention. Then, let this observation launch you into a reflection on scale and perspective. Consider the atmospheric phenomena occurring beyond your sight\u2014jet streams, weather systems, celestial motions. How does contemplating the vast, impersonal sky make you feel about your current concerns, joys, or plans? Write about the tension between the immediacy of your personal world and the silent, ongoing spectacle above."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt17": "Choose a machine or appliance in your home that has a distinct sound\u2014a refrigerator hum, a heater's click, a fan's whir. Close your eyes and listen to it for a full minute. Describe its rhythm, pitch, and constancy. Now, personify this sound. What is its personality? Is it a loyal guardian, a complaining old friend, a distant observer? Write a monologue from its perspective about the life it monitors within these walls. What has it learned about you from its unchanging post?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt18": "Recall a public space you frequented often in the past but have not visited in years (a library, a park, a diner, a store). Reconstruct it from memory in vivid detail. Then, imagine returning to it today. Describe the inevitable changes\u2014the renovations, the new faces, the faded paint. But also, hunt for the one thing that remains exactly, miraculously the same. How does the coexistence of change and permanence in this space make you feel about the passage of your own time?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt19": "\"newprompt3\": \"Recall a teacher, mentor, or elder who said something to you in passing that you have never forgotten. It might have been a compliment, a criticism, or an offhand observation. Reconstruct the scene. Why did their words carry such weight? How have you turned them over in your mind since? Explore the power of brief, seemingly casual utterances to shape a person's self-concept.\","
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt20": "\"newprompt0\": \"Write a detailed portrait of a tree you know well\u2014not just its appearance, but its history in that spot, the way its branches move in different winds, the creatures that inhabit it, the shadows it casts at various hours. Imagine its perspective across seasons and years. What has it witnessed? What would it say about change, resilience, or stillness if it could speak? Let the tree become a mirror for your own sense of place and time.\","
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt21": "Describe a memory you have that is tied to a specific smell. Don't just tell the story of the event; focus on describing the scent itself in as much detail as possible\u2014its texture, its weight in the air, its nuances. How does conjuring that smell now make you feel in your body? Let the description of the aroma lead you back into the memory's landscape."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt22": "Write a letter to your 15-year-old self. Be kind, be blunt, be humorous, or be stern. What do you know now that you desperately needed to hear then? What mystery about your future life could you tantalizingly hint at without giving it all away? Don't just give advice; try to capture the voice and tone you wish an older, wiser person had used with you."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt23": "You find a forgotten door in a place you know well\u2014your home, your workplace, your daily park. It wasn't there yesterday. You open it. Describe what is on the other side using only sensory details: sight, sound, temperature, smell. Do not explain its purpose or origin. Simply document the experience of crossing that threshold."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt24": "Make a list of ten tiny, perfect moments from the past month that no one else probably noticed or would remember. The way light fell on a spoon, a stranger's half-smile, the sound of rain stopping. Elaborate on at least three of them, expanding them into full vignettes. Why did these micro-moments stick with you?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt25": "Invent a mythological creature for a modern urban setting. What does it look like? What is its behavior and habitat (e.g., subway tunnels, server farms, air vents)? What folklore do people whisper about it? What does it symbolize\u2014anxiety, forgotten connections, hope? Describe a recent 'sighting' of this creature in vivid detail."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt26": "Choose an object in your immediate line of sight that is not electronic. Write its biography. Where was it made? Who owned it before you? What conversations has it overheard? What secrets does it hold? What small damages or wear marks does it have, and what story does each tell? Give this ordinary item an epic history."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt27": "Describe your current emotional state as a weather system. Is it a still, high-pressure fog? A sudden, sharp hailstorm? A lingering, humid drizzle? Map its boundaries, its intensity, its forecast. What terrain does it move over\u2014the mountains of your responsibilities, the plains of your routine? How does it affect your internal climate?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt28": "Recall a time you were deeply embarrassed. Write about it from the perspective of a sympathetic observer who was there\u2014or invent one. How might they have perceived the event? What context or kindness might they have seen that you, in your self-focused shame, completely missed? Reframe the memory through their eyes."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt29": "What skill or craft have you always wanted to learn but haven't? Immerse yourself in a detailed fantasy of mastering it. Describe the feel of the tools in your hands, the initial frustrations, the first small success, the growing muscle memory. What does the final, perfected product of your labor look or feel like? Live in that imagined\u6210\u5c31\u611f."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt30": "Write a dialogue between two aspects of yourself (e.g., Your Ambitious Self and Your Tired Self; Your Cynical Self and Your Hopeful Self). Give them distinct voices. What are they arguing about, negotiating, or planning? Don't just state positions; let them bicker, persuade, or sit in silence together. See where the conversation goes."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt31": "Describe your childhood home from the perspective of a small animal (a mouse, a squirrel, a bird) that lived there concurrently with you. What did this creature notice about your family's rhythms, the layout, the dangers, and the treasures (crumbs, cozy materials)? How did it perceive you, the giant human child?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt32": "List five paths your life could have taken if you'd made one different choice. Briefly outline each alternate reality. Then, choose one and dive deep: write a journal entry from that version of you today. What are their worries, joys, and regrets? How is their voice similar to or different from your own?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt33": "Think of a person you see regularly but do not know (a barista, a neighbor, a commuter). Invent a rich, secret inner life for them. What profound private mission are they on? What hidden talent do they possess? What great sorrow or hope are they carrying today as they serve your coffee or stand on the platform? Write from their perspective."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt34": "What is a belief you held strongly five or ten years ago that you have since questioned or abandoned? Trace the evolution of that change. Was it a sudden shattering or a slow erosion? What person, experience, or piece of information was the catalyst? Describe the feeling of the ground shifting under that particular piece of your worldview."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt35": "Describe a common, mundane process (making tea, tying your shoes, doing laundry) in extreme, almost absurdly epic detail, as if you were writing a sacred manual or a scientific treatise for an alien civilization. Break down every micro-action, every sensation, every potential variable. Find the profound in the procedural."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt36": "You are given a suitcase and told you must leave your home in one hour, not knowing if or when you'll return. You can only take what fits in the case. Describe, in real-time, the frantic and deliberate process of choosing. What practical items make the cut? What irreplaceable tokens? What do you leave behind, and what does that feel like?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt37": "Write about water in three different forms: as a memory involving a body of water (ocean, river, bath), as a description of drinking a glass of water right now, and as a metaphor for an emotion. Move seamlessly between these three aspects. Let the fluidity of the theme connect them."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt38": "What does silence sound like in your current environment? Don't just say 'quiet.' Describe the layers of sound that actually constitute the silence\u2014the hums, ticks, distant rumbles, the sound of your own body. Now, project what this same space sounded like 100 years ago, and what it might sound like 100 years from now."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt39": "Create a recipe for a dish that represents your current life phase. List ingredients (e.g., \"two cups of transition,\" \"a pinch of anxiety,\" \"a steady base of routine\"). Write the instructions, including the method, cooking time, and necessary equipment. Describe the final product's taste, texture, and who it should be shared with."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt40": "Recall a dream from the past week, however fragmentary. Don't interpret it. Instead, expand it. Continue the narrative from where it left off. Describe the dream logic, the landscape, the characters. Let it become a story. Where does your dreaming mind take you when given free rein on the page?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt41": "Make a list of everything that is blue in your immediate environment. Describe each shade specifically (slate, cobalt, robin's egg, faded denim). Then, choose one blue object and write about its journey to being here, in this blue state, in front of you. How did it get its color? What has it reflected?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt42": "Write a eulogy for something you've lost that isn't a person\u2014a habit, a version of a city, a relationship dynamic, a part of your identity. Acknowledge its virtues and its flaws. Say goodbye properly, with humor, regret, and gratitude. What did it give you? What space has its departure created?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt43": "Describe your hands. Not just their appearance, but their capabilities, their scars, their memories. What have they held, built, comforted, or torn down? What do their specific aches and strengths tell you about the life you've lived so far? If your hands could speak, what would they say they want to do next?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt44": "Imagine you can overhear the conversation of the people at the table next to you in a caf\u00e9, but they are speaking in a language you don't understand. Based on their tone, gestures, pauses, and expressions, invent the dialogue. What crucial, funny, or tragic misunderstanding are they having? What are they *really* talking about?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt45": "What is a piece of art (a song, painting, film, book) that fundamentally moved you? Describe the first time you encountered it. Don't just analyze why it's good; describe the physical and emotional reaction it provoked. Has its meaning changed for you over time? How does it live inside you now?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt46": "You have one day completely alone, with no obligations and no possibility of communication. The power and internet are out. How do you spend the hours from waking to sleeping? Detail the rituals, the wanderings, the thoughts, the meals. Do you enjoy the solitude or chafe against it? What arises in the quiet?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt47": "Personify a negative emotion you've been feeling lately (e.g., anxiety, envy, restlessness). Give it a name, a form, a voice. Write a character profile of it. What does it want? What does it fear? What flawed logic does it operate under? Then, write a short scene of you having a cup of tea with it, listening to its perspective."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt48": "Describe a city you've never been to, based solely on the stories, images, and snippets you've absorbed about it. Build it from imagination and second-hand clues. Then, contrast that with a description of your own street, seen with the hyper-attentive eyes of a first-time visitor. Make the familiar alien, and the alien familiar."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt49": "Think of a crossroads in your past. Now, imagine you see a ghost of your former self standing there, frozen in that moment of decision. What would you want to say to that ghost? Would you offer comfort, a warning, or just silent companionship? Write the encounter. Does the ghost speak back?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt50": "What is a tradition in your family or community\u2014big or small\u2014that you find meaningful? Describe its sensory details, its rhythms, its players. Now, trace its origin. How did it start? Has it mutated over time? What does its continued practice say about what your family values, fears, or hopes for?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt51": "Choose a year from your past. Catalog the soundtrack of that year: songs on the radio, albums you loved, jingles, background music. For each, describe a specific memory or feeling it evokes. How does the music of that time period color your memory of the entire era? What does it sound like to you now?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt52": "Write instructions for a stranger on how to be you for a day. Include the essential routines, the internal dialogues to expect, the things to avoid, the small comforts to lean on, and the passwords to your various anxieties. Be brutally honest and surprisingly practical. What would they find hardest to mimic?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt53": "Describe a moment of unexpected kindness, either given or received. Don't frame it as a grand gesture. Focus on a small, almost invisible act. What were the circumstances? Why was it so potent? How did it ripple out, changing the temperature of your day or your perception of someone?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt54": "You discover you have a superpower, but it is frustratingly mundane and specific (e.g., the ability to always know exactly what time it is without a clock, to perfectly fold fitted sheets, to find lost buttons). Explore the practical uses, the minor heroics, the unexpected downsides, and the peculiar loneliness of this unique gift."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt55": "Go to a window. Describe the view in extreme detail, as if painting it with words, for five minutes. Then, close your eyes and describe the view from a window that was significant to you in the past (your childhood bedroom, a previous office, a grandparent's house). Juxtapose the two landscapes on the page."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt56": "What is a question you are tired of being asked? Write a rant about why it's so irritating, reductive, or painful. Then, flip it: write the question you wish people would ask you instead. Answer that new question fully and generously."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt57": "Describe a hobby or interest you have from the perspective of someone who finds it utterly baffling and boring. Then, defend it with the passionate zeal of a true devotee. Try to convey its magic and depth to this imagined skeptic. What is the core beauty you see that they miss?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt58": "List ten things you would do if you were not afraid. They can be grand (quit my job) or small (sing karaoke). Choose one and vividly imagine doing it. Walk through every step, from decision to action to aftermath. How does the air feel different on the other side of that fear?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"prompt59": "Write about a time you got exactly what you wanted\u2014and it was not what you expected. Describe the desire, the anticipation, the moment of attainment, and the subtle (or not-so-subtle) disappointment or confusion that followed. What did that experience teach you about wanting?"
|
||||||
|
}
|
||||||
|
]
|
||||||
3
pool_prompts.json
Normal file
3
pool_prompts.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[
|
||||||
|
"What is something you've been putting off and why?"
|
||||||
|
]
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"prompt00": "Choose a common phrase you use often (e.g., \"I'm fine,\" \"Just a minute,\" \"Don't worry about it\"). Dissect it. What does it truly mean when you say it? What does it conceal? What convenience does it provide? Now, for one day, vow not to use it. Chronicle the conversations that become longer, more awkward, or more honest as a result."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt01": "Recall a time you received a gift that was perfectly, inexplicably right for you. Describe the gift and the giver. What made it so resonant? Was it an understanding of a secret wish, a reflection of an unseen part of you, or a tool you didn't know you needed? Explore the magic of being seen and understood through the medium of an object."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt02": "Map a friendship as a shared garden. What did each of you plant in the initial soil? What has grown wild? What requires regular tending? Have there been seasons of drought or frost? Are there any beautiful, stubborn weeds? Write a gardener's diary entry about the current state of this plot, reflecting on its history and future."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt03": "Describe a skill you have that is entirely non-verbal\u2014perhaps riding a bike, kneading dough, tuning an instrument by ear. Attempt to write a manual for this skill using only metaphors and physical sensations. Avoid technical terms. Can you translate embodied knowledge into prose? What is lost, and what is poetically gained?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt04": "Recall a scent that acts as a master key, unlocking a flood of specific, detailed memories. Describe the scent in non-scent words: is it sharp, round, velvety, brittle? Now, follow the key into the memory palace it opens. Don't just describe the memory; describe the architecture of the connection itself. How is scent wired so directly to the past?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt05": "Imagine you are a translator for a species that communicates through subtle shifts in temperature. Describe a recent emotional experience as a thermal map. Where in your body did the warmth of joy concentrate? Where did the cold front of anxiety settle? How would you translate this silent, somatic language into words for someone who only understands degrees and gradients?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt06": "Find a surface covered in a fine layer of dust\u2014a windowsill, an old book, a forgotten picture frame. Describe this 'residue' of time and neglect. What stories does the pattern of settlement tell? Write about the act of wiping it away. Is it an erasure of history or a renewal? What clean surface is revealed, and does it feel like a loss or a gain?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt07": "Build a 'gossamer' bridge in your mind between two seemingly disconnected concepts: for example, baking bread and forgiveness, or traffic patterns and anxiety. Describe the fragile, translucent strands of logic or metaphor you use to connect them. Walk across this bridge. What new landscape do you find on the other side? Does the bridge hold, or dissolve after use?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt08": "Map a personal 'labyrinth' of procrastination or avoidance. What are its enticing entryways (\"I'll just check...\")? Its circular corridors of rationalization? Its terrifying center (the task itself)? Describe one recent journey into this maze. What finally provided the thread to lead you out, or what made you decide to sit in the center and confront the Minotaur?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt09": "Craft a mental 'effigy' of a piece of advice you were given that you've chosen to ignore. Give it form and substance. Do you keep it on a shelf, bury it, or ritually dismantle it? Write about the act of holding this representation of rejected wisdom. Does making it concrete help you understand your refusal, or simply honor the intention of the giver?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt10": "Recall a decision point that felt like standing at the mouth of a 'labyrinth,' with multiple winding paths ahead. Describe the initial confusion and the method you used to choose an entrance (logic, intuition, chance). Now, with hindsight, map the path you actually took. Were there dead ends or unexpected centers? Did the labyrinth lead you out, or deeper into understanding?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt11": "Contemplate a 'quasar'\u2014an immensely luminous, distant celestial object. Use it as a metaphor for a source of guidance or inspiration in your life that feels both incredibly powerful and remote. Who or what is this distant beacon? Describe the 'light' it emits and the long journey it takes to reach you. How do you navigate by this ancient, brilliant, but fundamentally untouchable signal?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt12": "Describe a piece of music that left a 'residue' in your mind\u2014a melody that loops unbidden, a lyric that sticks, a rhythm that syncs with your heartbeat. How does this auditory artifact resurface during quiet moments? What emotional or memory-laden dust has it collected? Write about the process of this mental replay, and whether you seek to amplify it or gently brush it away."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt13": "Recall a 'failed' experiment from your past\u2014a recipe that flopped, a project abandoned, a relationship that didn't work. Instead of framing it as a mistake, analyze it as a valuable trial that produced data. What did you learn about the materials, the process, or yourself? How did the outcome diverge from your hypothesis? Write a lab report for this experiment, focusing on the insights gained rather than the desired product. How does this reframe 'failure'?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt14": "Chronicle the life cycle of a rumor or piece of gossip that reached you. Where did you first hear it? How did it mutate as it passed to you? What was your role\u2014conduit, amplifier, skeptic, terminator? Analyze the social algorithm that governs such information transfer. What need did this rumor feed in its listeners? Write about the velocity and distortion of unverified stories through a community."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt15": "Recall a time you had to translate\u2014not between languages, but between contexts: explaining a job to family, describing an emotion to someone who doesn't share it, making a technical concept accessible. Describe the words that failed you and the metaphors you crafted to bridge the gap. What was lost in translation? What was surprisingly clarified? Explore the act of building temporary, fragile bridges of understanding between internal and external worlds."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt16": "You discover a forgotten corner of a digital space you own\u2014an old blog draft, a buried folder of photos, an abandoned social media profile. Explore this digital artifact as an archaeologist would a physical site. What does the layout, the language, the imagery tell you about a past self? Reconstruct the mindset of the person who created it. How does this digital echo compare to your current identity? Is it a charming relic or an unsettling ghost?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt17": "You are tasked with archiving a sound that is becoming obsolete\u2014the click of a rotary phone, the chirp of a specific bird whose habitat is shrinking, the particular hum of an old appliance. Record a detailed description of this sound as if for a future museum. What are its frequencies, its rhythms, its emotional connotations? Now, imagine the silence that will exist in its place. What other, newer sounds will fill that auditory niche? Write an elegy for a vanishing sonic fingerprint."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt18": "Craft a mental effigy of a habit, fear, or desire you wish to understand better. Describe this symbolic representation in detail\u2014its materials, its posture, its expression. Now, perform a symbolic action upon it: you might place it in a drawer, bury it in the garden of your mind, or set it adrift on an imaginary river. Chronicle this ritual. Does the act of creating and addressing the effigy change your relationship to the thing it represents, or does it merely make its presence more tangible?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt19": "Describe a labyrinth you have constructed in your own mind\u2014not a physical maze, but a complex, recurring thought pattern or emotional state you find yourself navigating. What are its winding corridors (rationalizations), its dead ends (frustrations), and its potential center (understanding or acceptance)? Map one recent journey through this internal labyrinth. What subtle tremor of insight or fear guided your turns? How do you find your way out, or do you choose to remain within, exploring its familiar, intricate paths?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt20": "Examine a family tradition or ritual as if it were an ancient artifact. Break down its syntax: the required steps, the symbolic objects, the spoken phrases. Who are the keepers of this tradition? How has it mutated or diverged over generations? Participate in or recall this ritual with fresh eyes. What unspoken values and histories are encoded within its performance? What would be lost if it faded into oblivion?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt21": "Observe a plant growing in an unexpected place\u2014a crack in the sidewalk, a gutter, a wall. Chronicle its struggle and persistence. Imagine the velocity of its growth against all odds. Write from the plant's perspective about its daily existence: the foot traffic, the weather, the search for sustenance. What can this resilient life form teach you about finding footholds and thriving in inhospitable environments?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt22": "Imagine your creative process as a room with many thresholds. Describe the room where you generate raw ideas\u2014its mess, its energy. Then, describe the act of crossing the threshold into the room where you refine and edit. What changes in the atmosphere? What do you leave behind at the door, and what must you carry with you? Write about the architecture of your own creativity."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt23": "You are given a seed. It is not a magical seed, but an ordinary one from a fruit you ate. Instead of planting it, you decide to carry it with you for a week as a silent companion. Describe its presence in your pocket or bag. How does knowing it is there, a compact potential for an entire mycelial network of roots and a tree, subtly influence your days? Write about the weight of unactivated futures."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt24": "Recall a time you had to learn a new system or language quickly\u2014a job, a software, a social circle. Describe the initial phase of feeling like an outsider, decoding the basic algorithms of behavior. Then, focus on the precise moment you felt you crossed the threshold from outsider to competent insider. What was the catalyst? A piece of understood jargon? A successfully completed task? Explore the subtle architecture of belonging."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt25": "You find an old, annotated map\u2014perhaps in a book, or a tourist pamphlet from a trip long ago. Study the marks: circled sites, crossed-out routes, notes in the margin. Reconstruct the journey of the person who held this map. Where did they plan to go? Where did they actually go, based on the evidence? Write the travelogue of that forgotten expedition, blending the cartographic intention with the likely reality."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt26": "You encounter a door that is usually locked, but today it is slightly ajar. This is not a grand, mysterious portal, but an ordinary door\u2014to a storage closet, a rooftop, a neighbor's garden gate. Write about the potent allure of this minor threshold. Do you push it open? What mundane or profound discovery lies on the other side? Explore the magnetism of accessible secrets in a world of usual boundaries."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt27": "Recall a piece of practical advice you received that functioned like a simple life algorithm: 'When X happens, do Y.' Examine a recent situation where you deliberately chose not to follow that algorithm. What prompted the deviation? What was the outcome? Describe the feeling of operating outside of a previously trusted internal program. Did the mutation feel like a mistake or an evolution?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt28": "Describe a piece of clothing you own that has been altered or mended multiple times. Trace the history of each repair. Who performed them, and under what circumstances? How does the garment's story of damage and restoration mirror larger cycles of wear and renewal in your own life? What does its continued use, despite its patched state, say about your relationship with impermanence and care?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt29": "You find an old, hand-drawn map that leads to a place in your neighborhood. Follow it. Does it lead you to a spot that still exists, or to a location now utterly changed? Describe the journey of reconciling the cartography of the past with the terrain of the present. What has been erased? What endures? What ghosts of previous journeys do you feel along the way?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt30": "Consider a skill you are learning. Break down its initial algorithm\u2014the basic, rigid steps you must follow. Now, describe the moment when practice leads to mutation: the algorithm begins to dissolve into intuition, muscle memory, or personal style. Where are you in this process? Can you feel the old, clunky code still running beneath the new, fluid performance? Write about the uncomfortable, fruitful space between competence and mastery."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt31": "Analyze the unspoken social algorithm of a group you belong to\u2014your family, your friend circle, your coworkers. What are the input rules (jokes that are allowed, topics to avoid)? What are the output expectations (laughter, support, problem-solving)? Now, imagine introducing a mutation: you break a minor, unwritten rule. Chronicle the system's response. Does it self-correct, reject the input, or adapt?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt32": "Imagine your daily routine is a genetic sequence. Identify a habitual behavior that feels like a dominant gene. Now, imagine a spontaneous mutation occurring in this sequence\u2014one small, random change in the order or execution of your day. Follow the consequences. Does this mutation prove beneficial, harmful, or neutral? Does it replicate and become part of your new code? Write about the evolution of a personal habit through chance."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt33": "Your memory is a vast, dark archive. Choose a specific memory and imagine you are its archivist. Describe the process of retrieving it: locating the correct catalog number, the feel of the storage medium, the quality of the playback. Now, describe the process of conservation\u2014what elements are fragile and in need of repair? Do you restore it to its original clarity, or preserve its current, faded state? What is the ethical duty of a self-archivist?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt34": "Examine a mended object in your possession\u2014a book with tape, a garment with a patch, a glued-together mug. Describe the repair not as a flaw, but as a new feature, a record of care and continuity. Write the history of its breaking and its fixing. Who performed the repair, and what was their state of mind? How does the object's value now reside in its visible history of damage and healing?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt35": "Imagine you are a cartographer of sound. Map the auditory landscape of your current environment. Label the persistent drones, the intermittent rhythms, the sudden percussive events. What are the quiet zones? Where do sounds overlap to create new harmonies or dissonances? Now, imagine mutating one sound source\u2014silencing a hum, amplifying a whisper, changing a rhythm. How does this single alteration redraw the entire sonic map and your emotional response to the space?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt36": "Contemplate the concept of a 'watershed'\u2014a geographical dividing line. Now, identify a watershed moment in your own life: a decision, an event, or a realization that divided your experience into 'before' and 'after.' Describe the landscape of the 'before.' Then, detail the moment of the divide itself. Finally, look out over the 'after' territory. How did the paths available to you fundamentally diverge at that ridge line? What rivers of consequence began to flow in new directions?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt37": "Observe a spiderweb, a bird's nest, or another intricate natural construction. Describe it not as a static object, but as the recorded evidence of a process\u2014a series of deliberate actions repeated to create a functional whole. Imagine you are an archaeologist from another planet discovering this artifact. What hypotheses would you form about the builder's intelligence, needs, and methods? Write your field report."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt38": "Walk through a familiar indoor space (your home, your office) in complete darkness, or with your eyes closed if safe. Navigate by touch, memory, and sound alone. Describe the experience. Which objects and spaces feel different? What details do you notice that vision usually overrides? Write about the knowledge held in your hands and feet, and the temporary oblivion of the visual world. How does this shift in primary sense redefine your understanding of the space?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt39": "You discover a single, worn-out glove lying on a park bench. Describe it in detail\u2014its color, material, signs of wear. Write a speculative history for this artifact. Who owned it? How was it lost? From the glove's perspective, narrate its journey from a department store shelf to this moment of abandonment. What human warmth did it hold, and what does its solitary state signify about loss and separation?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt40": "Find a body of water\u2014a puddle after rain, a pond, a riverbank. Look at your reflection, then disturb the surface with a touch or a thrown pebble. Watch the image shatter and slowly reform. Use this as a metaphor for a period of personal disruption in your life. Describe the 'shattering' event, the chaotic ripple period, and the gradual, never-quite-identical reformation of your sense of self. What was lost in the distortion, and what new facets were revealed?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt41": "You are handed a map of a city you know well, but it is from a century ago. Compare it to the modern layout. Which streets have vanished into oblivion, paved over or renamed? Which buildings are ghosts on the page? Choose one lost place and imagine walking its forgotten route today. What echoes of its past life\u2014sounds, smells, activities\u2014can you almost perceive beneath the contemporary surface? Write about the layers of history that coexist in a single geographic space."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt42": "What is something you've been putting off and why?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt43": "Recall a piece of art\u2014a painting, song, film\u2014that initially confused or repelled you, but that you later came to appreciate or love. Describe your first, negative reaction in detail. Then, trace the journey to understanding. What changed in you or your context that allowed a new interpretation? Write about the value of sitting with discomfort and the rewards of having your internal syntax for beauty challenged and expanded."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt44": "Imagine your life as a vast, intricate tapestry. Describe the overall scene it depicts. Now, find a single, loose thread\u2014a small regret, an unresolved question, a path not taken. Write about gently pulling on that thread. What part of the tapestry begins to unravel? What new pattern or image is revealed\u2014or destroyed\u2014by following this divergence? Is the act one of repair or deconstruction?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt45": "Recall a dream that felt more real than waking life. Describe its internal logic, its emotional palette, and its lingering aftertaste. Now, write a 'practical guide' for navigating that specific dreamscape, as if for a tourist. What are the rules? What should one avoid? What treasures might be found? By treating the dream as a tangible place, what insights do you gain about the concerns of your subconscious?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt46": "Describe a public space you frequent (a library, a cafe, a park) at the exact moment it opens or closes. Capture the transition from emptiness to potential, or from activity to stillness. Focus on the staff or custodians who facilitate this transition\u2014the unseen architects of these daily cycles. Write from the perspective of the space itself as it breathes in or out its human occupants. What residue of the day does it hold in the quiet?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt47": "Listen to a piece of music you know well, but focus exclusively on a single instrument or voice that usually resides in the background. Follow its thread through the entire composition. Describe its journey: when does it lead, when does it harmonize, when does it fall silent? Now, write a short story where this supporting element is the main character. How does shifting your auditory focus create a new narrative from familiar material?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt48": "Describe your reflection in a window at night, with the interior light creating a double exposure of your face and the dark world outside. What two versions of yourself are superimposed? Write a conversation between the 'inside' self, defined by your private space, and the 'outside' self, defined by the anonymous night. What do they want from each other? How does this liminal artifact\u2014the glass\u2014both separate and connect these identities?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt49": "Imagine you are a diver exploring the deep ocean of your own memory. Choose a specific, vivid memory and describe it as a submerged landscape. What creatures (emotions) swim there? What is the water pressure (emotional weight) like? Now, imagine a small, deliberate act of forgetting\u2014letting a single detail of that memory dissolve into the murk. How does this selective oblivion change the entire ecosystem of that recollection? Does it create space for new growth, or does it feel like a loss of truth?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt50": "Recall a conversation that ended in a misunderstanding that was never resolved. Re-write the exchange, but introduce a single point of divergence\u2014one person says something slightly different, or pauses a moment longer. How does this tiny change alter the entire trajectory of the conversation and potentially the relationship? Explore the butterfly effect in human dialogue."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt51": "Spend 15 minutes in complete silence, actively listening for the absence of a specific sound that is usually present (e.g., traffic, refrigerator hum, birds). Describe the quality of this crafted silence. What smaller sounds emerge in the void? How does your mind and body react to the deliberate removal of this sonic artifact? Explore the concept of oblivion as an active, perceptible state rather than a mere lack."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt52": "Describe a skill or talent you possess that feels like it's fading from lack of use\u2014a language getting rusty, a sport you no longer play, an instrument gathering dust. Perform or practice it now, even if clumsily. Chronicle the physical and mental sensations of re-engagement. What echoes of proficiency remain? Is the knowledge truly gone, or merely dormant? Write about the relationship between mastery and oblivion."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt53": "Choose a common word (e.g., 'home,' 'work,' 'friend') and dissect its personal syntax. What rules, associations, and exceptions have you built around its meaning? Now, deliberately break one of those rules. Use the word in a context or with a definition that feels wrong to you. Write a paragraph that forces this new usage. How does corrupting your own internal language create space for new understanding?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt54": "Contemplate a personal habit or pattern you wish to change. Instead of focusing on breaking it, imagine it diverging\u2014mutating into a new, slightly different pattern. Describe the old habit in detail, then design its evolved form. What small, intentional twist could redirect its energy? Write about a day living with this divergent habit. How does a shift in perspective, rather than eradication, alter your relationship to it?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt55": "Describe a routine journey you make (a commute, a walk to the store) but narrate it as if you are a traveler in a foreign, slightly surreal land. Give fantastical names to ordinary landmarks. Interpret mundane events as portents or rituals. What hidden narrative or mythic structure can you impose on this familiar path? How does this reframing reveal the magic latent in the everyday?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt56": "Imagine a place from your childhood that no longer exists in its original form\u2014a demolished building, a paved-over field, a renovated room. Reconstruct it from memory with all its sensory details. Now, write about the process of its erasure. Who decided it should change? What was lost in the transition, and what, if anything, was gained? How does the ghost of that place still influence the geography of your memory?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt57": "You find an old, functional algorithm\u2014a recipe card, a knitting pattern, a set of instructions for assembling furniture. Follow it to the letter, but with a new, meditative attention to each step. Describe the process not as a means to an end, but as a ritual in itself. What resonance does this deliberate, prescribed action have? Does the final product matter, or has the value been in the structured journey?"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt58": "Imagine knowledge and ideas spread through a community not like a virus, but like a mycelium\u2014subterranean, cooperative, nutrient-sharing. Recall a time you learned something profound from an unexpected or unofficial source. Trace the hidden network that brought that wisdom to you. How many people and experiences were unknowingly part of that fruiting? Write a thank you to this invisible web."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"prompt59": "Imagine your creative or problem-solving process is a mycelial network. A question or idea is dropped like a spore onto this vast, hidden web. Describe the journey of this spore as it sends out filaments, connects with distant nodes of memory and knowledge, and eventually fruits as an 'aha' moment or a new creation. How does this model differ from a linear, step-by-step algorithm? What does it teach you about patience and indirect growth?"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
[
|
|
||||||
"Describe preparing and eating a meal alone with the attention of a sacred ritual. Focus on each step: selecting ingredients, the sound of chopping, the aromas, the arrangement on the plate, the first bite. Write about the difference between eating for fuel and eating as an act of communion with yourself. What thoughts arise in the space of this deliberate solitude?",
|
|
||||||
"Recall a rule you were taught as a child\u2014a practical safety rule, a social manner, a household edict. Examine its original purpose. Now, trace how your relationship to that rule has evolved. Do you follow it rigidly, have you modified it, or do you ignore it entirely? Write about the journey from external imposition to internalized (or rejected) law."
|
|
||||||
]
|
|
||||||
16
run.sh
16
run.sh
@@ -36,6 +36,7 @@ fi
|
|||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
INTERACTIVE=false
|
INTERACTIVE=false
|
||||||
STATS=false
|
STATS=false
|
||||||
|
POOL_STATS=false
|
||||||
FILL_POOL=false
|
FILL_POOL=false
|
||||||
HELP=false
|
HELP=false
|
||||||
|
|
||||||
@@ -49,6 +50,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
STATS=true
|
STATS=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--pool-stats)
|
||||||
|
POOL_STATS=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--fill-pool)
|
--fill-pool)
|
||||||
FILL_POOL=true
|
FILL_POOL=true
|
||||||
shift
|
shift
|
||||||
@@ -70,21 +75,26 @@ if [ "$HELP" = true ]; then
|
|||||||
echo ""
|
echo ""
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -i, --interactive Run in interactive mode (with rich interface)"
|
echo " -i, --interactive Run in interactive mode (with rich interface)"
|
||||||
echo " --stats Show combined statistics (pool and history)"
|
echo " --stats Show prompt history statistics"
|
||||||
|
echo " --pool-stats Show prompt pool statistics"
|
||||||
echo " --fill-pool Fill prompt pool using AI (makes API call)"
|
echo " --fill-pool Fill prompt pool using AI (makes API call)"
|
||||||
echo " -h, --help Show this help message"
|
echo " -h, --help Show this help message"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Examples:"
|
echo "Examples:"
|
||||||
echo " ./run.sh # Draw prompts from pool (default)"
|
echo " ./run.sh # Draw prompts from pool (default)"
|
||||||
echo " ./run.sh -i # Interactive mode"
|
echo " ./run.sh -i # Interactive mode"
|
||||||
echo " ./run.sh --stats # Show combined statistics"
|
echo " ./run.sh --stats # Show history statistics"
|
||||||
|
echo " ./run.sh --pool-stats # Show pool statistics"
|
||||||
echo " ./run.sh --fill-pool # Fill prompt pool using AI"
|
echo " ./run.sh --fill-pool # Fill prompt pool using AI"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$STATS" = true ]; then
|
if [ "$STATS" = true ]; then
|
||||||
echo "📊 Showing combined statistics..."
|
echo "📊 Showing history statistics..."
|
||||||
python3 generate_prompts.py --stats
|
python3 generate_prompts.py --stats
|
||||||
|
elif [ "$POOL_STATS" = true ]; then
|
||||||
|
echo "📊 Showing pool statistics..."
|
||||||
|
python3 generate_prompts.py --pool-stats
|
||||||
elif [ "$FILL_POOL" = true ]; then
|
elif [ "$FILL_POOL" = true ]; then
|
||||||
echo "🔄 Filling prompt pool using AI..."
|
echo "🔄 Filling prompt pool using AI..."
|
||||||
python3 generate_prompts.py --fill-pool
|
python3 generate_prompts.py --fill-pool
|
||||||
|
|||||||
253
run_webapp.sh
253
run_webapp.sh
@@ -1,253 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Daily Journal Prompt Generator - Web Application Runner
|
|
||||||
# This script helps you run the web application with various options
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Colors for output
|
|
||||||
RED='\033[0;31m'
|
|
||||||
GREEN='\033[0;32m'
|
|
||||||
YELLOW='\033[1;33m'
|
|
||||||
BLUE='\033[0;34m'
|
|
||||||
NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
print_header() {
|
|
||||||
echo -e "${BLUE}"
|
|
||||||
echo "=========================================="
|
|
||||||
echo "Daily Journal Prompt Generator - Web App"
|
|
||||||
echo "=========================================="
|
|
||||||
echo -e "${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_success() {
|
|
||||||
echo -e "${GREEN}✓ $1${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_warning() {
|
|
||||||
echo -e "${YELLOW}⚠ $1${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
print_error() {
|
|
||||||
echo -e "${RED}✗ $1${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
check_dependencies() {
|
|
||||||
print_header
|
|
||||||
echo "Checking dependencies..."
|
|
||||||
|
|
||||||
# Check Docker
|
|
||||||
if command -v docker &> /dev/null; then
|
|
||||||
print_success "Docker is installed"
|
|
||||||
else
|
|
||||||
print_warning "Docker is not installed. Docker is recommended for easiest setup."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check Docker Compose
|
|
||||||
if command -v docker-compose &> /dev/null || docker compose version &> /dev/null; then
|
|
||||||
print_success "Docker Compose is available"
|
|
||||||
else
|
|
||||||
print_warning "Docker Compose is not available"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check Python
|
|
||||||
if command -v python3 &> /dev/null; then
|
|
||||||
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
|
|
||||||
print_success "Python $PYTHON_VERSION is installed"
|
|
||||||
else
|
|
||||||
print_error "Python 3 is not installed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check Node.js
|
|
||||||
if command -v node &> /dev/null; then
|
|
||||||
NODE_VERSION=$(node --version)
|
|
||||||
print_success "Node.js $NODE_VERSION is installed"
|
|
||||||
else
|
|
||||||
print_warning "Node.js is not installed (needed for frontend development)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_environment() {
|
|
||||||
echo "Setting up environment..."
|
|
||||||
|
|
||||||
if [ ! -f ".env" ]; then
|
|
||||||
if [ -f ".env.example" ]; then
|
|
||||||
cp .env.example .env
|
|
||||||
print_success "Created .env file from template"
|
|
||||||
print_warning "Please edit .env file and add your API keys"
|
|
||||||
else
|
|
||||||
print_error ".env.example not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print_success ".env file already exists"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check data directory
|
|
||||||
if [ ! -d "data" ]; then
|
|
||||||
mkdir -p data
|
|
||||||
print_success "Created data directory"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
}
|
|
||||||
|
|
||||||
run_docker() {
|
|
||||||
print_header
|
|
||||||
echo "Starting with Docker Compose..."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
if command -v docker-compose &> /dev/null; then
|
|
||||||
docker-compose up --build
|
|
||||||
elif docker compose version &> /dev/null; then
|
|
||||||
docker compose up --build
|
|
||||||
else
|
|
||||||
print_error "Docker Compose is not available"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
run_backend() {
|
|
||||||
print_header
|
|
||||||
echo "Starting Backend API..."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
cd backend
|
|
||||||
|
|
||||||
# Check virtual environment
|
|
||||||
if [ ! -d "venv" ]; then
|
|
||||||
print_warning "Creating Python virtual environment..."
|
|
||||||
python3 -m venv venv
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Activate virtual environment
|
|
||||||
if [ -f "venv/bin/activate" ]; then
|
|
||||||
source venv/bin/activate
|
|
||||||
elif [ -f "venv/Scripts/activate" ]; then
|
|
||||||
source venv/Scripts/activate
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
if [ ! -f "venv/bin/uvicorn" ]; then
|
|
||||||
print_warning "Installing Python dependencies..."
|
|
||||||
pip install -r requirements.txt
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run backend
|
|
||||||
print_success "Starting FastAPI backend on http://localhost:8000"
|
|
||||||
echo "API Documentation: http://localhost:8000/docs"
|
|
||||||
echo ""
|
|
||||||
uvicorn main:app --reload --host 0.0.0.0 --port 8000
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
run_frontend() {
|
|
||||||
print_header
|
|
||||||
echo "Starting Frontend..."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
cd frontend
|
|
||||||
|
|
||||||
# Check node_modules
|
|
||||||
if [ ! -d "node_modules" ]; then
|
|
||||||
print_warning "Installing Node.js dependencies..."
|
|
||||||
npm install
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run frontend
|
|
||||||
print_success "Starting Astro frontend on http://localhost:3000"
|
|
||||||
echo ""
|
|
||||||
npm run dev
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
}
|
|
||||||
|
|
||||||
run_tests() {
|
|
||||||
print_header
|
|
||||||
echo "Running Backend Tests..."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
if [ -f "test_backend.py" ]; then
|
|
||||||
python test_backend.py
|
|
||||||
else
|
|
||||||
print_error "test_backend.py not found"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
show_help() {
|
|
||||||
print_header
|
|
||||||
echo "Usage: $0 [OPTION]"
|
|
||||||
echo ""
|
|
||||||
echo "Options:"
|
|
||||||
echo " docker Run with Docker Compose (recommended)"
|
|
||||||
echo " backend Run only the backend API"
|
|
||||||
echo " frontend Run only the frontend"
|
|
||||||
echo " all Run both backend and frontend separately"
|
|
||||||
echo " test Run backend tests"
|
|
||||||
echo " setup Check dependencies and setup environment"
|
|
||||||
echo " help Show this help message"
|
|
||||||
echo ""
|
|
||||||
echo "Examples:"
|
|
||||||
echo " $0 docker # Run full stack with Docker"
|
|
||||||
echo " $0 all # Run backend and frontend separately"
|
|
||||||
echo " $0 setup # Setup environment and check dependencies"
|
|
||||||
echo ""
|
|
||||||
}
|
|
||||||
|
|
||||||
case "${1:-help}" in
|
|
||||||
docker)
|
|
||||||
check_dependencies
|
|
||||||
setup_environment
|
|
||||||
run_docker
|
|
||||||
;;
|
|
||||||
backend)
|
|
||||||
check_dependencies
|
|
||||||
setup_environment
|
|
||||||
run_backend
|
|
||||||
;;
|
|
||||||
frontend)
|
|
||||||
check_dependencies
|
|
||||||
setup_environment
|
|
||||||
run_frontend
|
|
||||||
;;
|
|
||||||
all)
|
|
||||||
check_dependencies
|
|
||||||
setup_environment
|
|
||||||
print_header
|
|
||||||
echo "Starting both backend and frontend..."
|
|
||||||
echo "Backend: http://localhost:8000"
|
|
||||||
echo "Frontend: http://localhost:3000"
|
|
||||||
echo ""
|
|
||||||
echo "Open two terminal windows and run:"
|
|
||||||
echo "1. $0 backend"
|
|
||||||
echo "2. $0 frontend"
|
|
||||||
echo ""
|
|
||||||
;;
|
|
||||||
test)
|
|
||||||
check_dependencies
|
|
||||||
run_tests
|
|
||||||
;;
|
|
||||||
setup)
|
|
||||||
check_dependencies
|
|
||||||
setup_environment
|
|
||||||
print_success "Setup complete!"
|
|
||||||
echo ""
|
|
||||||
echo "Next steps:"
|
|
||||||
echo "1. Edit .env file and add your API keys"
|
|
||||||
echo "2. Run with: $0 docker (recommended)"
|
|
||||||
echo "3. Or run with: $0 all"
|
|
||||||
;;
|
|
||||||
help|--help|-h)
|
|
||||||
show_help
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
print_error "Unknown option: $1"
|
|
||||||
show_help
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
257
test_backend.py
257
test_backend.py
@@ -1,257 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
Test script to verify the backend API structure.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
# Add backend to path
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
|
|
||||||
|
|
||||||
def test_imports():
|
|
||||||
"""Test that all required modules can be imported."""
|
|
||||||
print("Testing imports...")
|
|
||||||
|
|
||||||
try:
|
|
||||||
from app.core.config import settings
|
|
||||||
print("✓ Config module imported successfully")
|
|
||||||
|
|
||||||
from app.core.logging import setup_logging
|
|
||||||
print("✓ Logging module imported successfully")
|
|
||||||
|
|
||||||
from app.services.data_service import DataService
|
|
||||||
print("✓ DataService imported successfully")
|
|
||||||
|
|
||||||
from app.services.ai_service import AIService
|
|
||||||
print("✓ AIService imported successfully")
|
|
||||||
|
|
||||||
from app.services.prompt_service import PromptService
|
|
||||||
print("✓ PromptService imported successfully")
|
|
||||||
|
|
||||||
from app.models.prompt import PromptResponse, PoolStatsResponse
|
|
||||||
print("✓ Models imported successfully")
|
|
||||||
|
|
||||||
from app.api.v1.api import api_router
|
|
||||||
print("✓ API router imported successfully")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
except ImportError as e:
|
|
||||||
print(f"✗ Import error: {e}")
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Error: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def test_config():
|
|
||||||
"""Test configuration loading."""
|
|
||||||
print("\nTesting configuration...")
|
|
||||||
|
|
||||||
try:
|
|
||||||
from app.core.config import settings
|
|
||||||
|
|
||||||
print(f"✓ Project name: {settings.PROJECT_NAME}")
|
|
||||||
print(f"✓ Version: {settings.VERSION}")
|
|
||||||
print(f"✓ Debug mode: {settings.DEBUG}")
|
|
||||||
print(f"✓ Environment: {settings.ENVIRONMENT}")
|
|
||||||
print(f"✓ Host: {settings.HOST}")
|
|
||||||
print(f"✓ Port: {settings.PORT}")
|
|
||||||
print(f"✓ Min prompt length: {settings.MIN_PROMPT_LENGTH}")
|
|
||||||
print(f"✓ Max prompt length: {settings.MAX_PROMPT_LENGTH}")
|
|
||||||
print(f"✓ Prompts per session: {settings.NUM_PROMPTS_PER_SESSION}")
|
|
||||||
print(f"✓ Cached pool volume: {settings.CACHED_POOL_VOLUME}")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Configuration error: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def test_data_service():
|
|
||||||
"""Test DataService initialization."""
|
|
||||||
print("\nTesting DataService...")
|
|
||||||
|
|
||||||
try:
|
|
||||||
from app.services.data_service import DataService
|
|
||||||
|
|
||||||
data_service = DataService()
|
|
||||||
print("✓ DataService initialized successfully")
|
|
||||||
|
|
||||||
# Check data directory
|
|
||||||
import os
|
|
||||||
data_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data")
|
|
||||||
if os.path.exists(data_dir):
|
|
||||||
print(f"✓ Data directory exists: {data_dir}")
|
|
||||||
|
|
||||||
# Check for required files
|
|
||||||
required_files = [
|
|
||||||
'prompts_historic.json',
|
|
||||||
'prompts_pool.json',
|
|
||||||
'feedback_words.json',
|
|
||||||
'feedback_historic.json',
|
|
||||||
'ds_prompt.txt',
|
|
||||||
'ds_feedback.txt',
|
|
||||||
'settings.cfg'
|
|
||||||
]
|
|
||||||
|
|
||||||
for file in required_files:
|
|
||||||
file_path = os.path.join(data_dir, file)
|
|
||||||
if os.path.exists(file_path):
|
|
||||||
print(f"✓ {file} exists")
|
|
||||||
else:
|
|
||||||
print(f"⚠ {file} not found (this may be OK for new installations)")
|
|
||||||
else:
|
|
||||||
print(f"⚠ Data directory not found: {data_dir}")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ DataService error: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def test_models():
|
|
||||||
"""Test Pydantic models."""
|
|
||||||
print("\nTesting Pydantic models...")
|
|
||||||
|
|
||||||
try:
|
|
||||||
from app.models.prompt import (
|
|
||||||
PromptResponse,
|
|
||||||
PoolStatsResponse,
|
|
||||||
HistoryStatsResponse,
|
|
||||||
FeedbackWord
|
|
||||||
)
|
|
||||||
|
|
||||||
# Test PromptResponse
|
|
||||||
prompt = PromptResponse(
|
|
||||||
key="prompt00",
|
|
||||||
text="Test prompt text",
|
|
||||||
position=0
|
|
||||||
)
|
|
||||||
print("✓ PromptResponse model works")
|
|
||||||
|
|
||||||
# Test PoolStatsResponse
|
|
||||||
pool_stats = PoolStatsResponse(
|
|
||||||
total_prompts=10,
|
|
||||||
prompts_per_session=6,
|
|
||||||
target_pool_size=20,
|
|
||||||
available_sessions=1,
|
|
||||||
needs_refill=True
|
|
||||||
)
|
|
||||||
print("✓ PoolStatsResponse model works")
|
|
||||||
|
|
||||||
# Test HistoryStatsResponse
|
|
||||||
history_stats = HistoryStatsResponse(
|
|
||||||
total_prompts=5,
|
|
||||||
history_capacity=60,
|
|
||||||
available_slots=55,
|
|
||||||
is_full=False
|
|
||||||
)
|
|
||||||
print("✓ HistoryStatsResponse model works")
|
|
||||||
|
|
||||||
# Test FeedbackWord
|
|
||||||
feedback_word = FeedbackWord(
|
|
||||||
key="feedback00",
|
|
||||||
word="creativity",
|
|
||||||
weight=5
|
|
||||||
)
|
|
||||||
print("✓ FeedbackWord model works")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ Models error: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def test_api_structure():
|
|
||||||
"""Test API endpoint structure."""
|
|
||||||
print("\nTesting API structure...")
|
|
||||||
|
|
||||||
try:
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from app.api.v1.api import api_router
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
app.include_router(api_router, prefix="/api/v1")
|
|
||||||
|
|
||||||
# Check routes
|
|
||||||
routes = []
|
|
||||||
for route in app.routes:
|
|
||||||
if hasattr(route, 'path'):
|
|
||||||
routes.append(route.path)
|
|
||||||
|
|
||||||
expected_routes = [
|
|
||||||
'/api/v1/prompts/draw',
|
|
||||||
'/api/v1/prompts/fill-pool',
|
|
||||||
'/api/v1/prompts/stats',
|
|
||||||
'/api/v1/prompts/history/stats',
|
|
||||||
'/api/v1/prompts/history',
|
|
||||||
'/api/v1/prompts/select/{prompt_index}',
|
|
||||||
'/api/v1/feedback/generate',
|
|
||||||
'/api/v1/feedback/rate',
|
|
||||||
'/api/v1/feedback/current',
|
|
||||||
'/api/v1/feedback/history'
|
|
||||||
]
|
|
||||||
|
|
||||||
print("✓ API router integrated successfully")
|
|
||||||
print(f"✓ Found {len(routes)} routes")
|
|
||||||
|
|
||||||
# Check for key routes
|
|
||||||
for expected_route in expected_routes:
|
|
||||||
if any(expected_route in route for route in routes):
|
|
||||||
print(f"✓ Route found: {expected_route}")
|
|
||||||
else:
|
|
||||||
print(f"⚠ Route not found: {expected_route}")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"✗ API structure error: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""Run all tests."""
|
|
||||||
print("=" * 60)
|
|
||||||
print("Daily Journal Prompt Generator - Backend API Test")
|
|
||||||
print("=" * 60)
|
|
||||||
|
|
||||||
tests = [
|
|
||||||
("Imports", test_imports),
|
|
||||||
("Configuration", test_config),
|
|
||||||
("Data Service", test_data_service),
|
|
||||||
("Models", test_models),
|
|
||||||
("API Structure", test_api_structure),
|
|
||||||
]
|
|
||||||
|
|
||||||
results = []
|
|
||||||
|
|
||||||
for test_name, test_func in tests:
|
|
||||||
print(f"\n{test_name}:")
|
|
||||||
print("-" * 40)
|
|
||||||
success = test_func()
|
|
||||||
results.append((test_name, success))
|
|
||||||
|
|
||||||
print("\n" + "=" * 60)
|
|
||||||
print("Test Summary:")
|
|
||||||
print("=" * 60)
|
|
||||||
|
|
||||||
all_passed = True
|
|
||||||
for test_name, success in results:
|
|
||||||
status = "✓ PASS" if success else "✗ FAIL"
|
|
||||||
print(f"{test_name:20} {status}")
|
|
||||||
if not success:
|
|
||||||
all_passed = False
|
|
||||||
|
|
||||||
print("\n" + "=" * 60)
|
|
||||||
if all_passed:
|
|
||||||
print("All tests passed! 🎉")
|
|
||||||
print("Backend API structure is ready.")
|
|
||||||
else:
|
|
||||||
print("Some tests failed. Please check the errors above.")
|
|
||||||
|
|
||||||
return all_passed
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
success = main()
|
|
||||||
sys.exit(0 if success else 1)
|
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Test Docker build for the backend
|
|
||||||
echo "Testing backend Docker build..."
|
|
||||||
docker build -t daily-journal-prompt-backend-test ./backend
|
|
||||||
|
|
||||||
# Test Docker build for the frontend
|
|
||||||
echo -e "\nTesting frontend Docker build..."
|
|
||||||
docker build -t daily-journal-prompt-frontend-test ./frontend
|
|
||||||
|
|
||||||
echo -e "\nDocker build tests completed."
|
|
||||||
|
|
||||||
@@ -7,8 +7,8 @@ import json
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Add the parent directory to the Python path
|
# Add the current directory to the Python path
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
from generate_prompts import JournalPromptGenerator
|
from generate_prompts import JournalPromptGenerator
|
||||||
|
|
||||||
230
test_parsing.py
Normal file
230
test_parsing.py
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Consolidated test file for parsing AI responses and format handling.
|
||||||
|
Combines tests from:
|
||||||
|
- test_final_fix.py (AttributeError fix for list responses)
|
||||||
|
- test_new_format.py (new list format with locally generated keys)
|
||||||
|
- test_valid_response.py (valid JSON response handling)
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Add the current directory to the Python path
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
from generate_prompts import JournalPromptGenerator
|
||||||
|
|
||||||
|
|
||||||
|
def test_attribute_error_fix():
|
||||||
|
"""Test the fix for AttributeError when API returns list instead of dict."""
|
||||||
|
print("\n=== Test: AttributeError fix for list responses ===")
|
||||||
|
|
||||||
|
# Create a mock generator
|
||||||
|
generator = JournalPromptGenerator()
|
||||||
|
|
||||||
|
# Test with empty list []
|
||||||
|
list_response = json.dumps([]) # Empty list
|
||||||
|
print("\n1. Testing with empty list []:")
|
||||||
|
try:
|
||||||
|
result = generator._parse_ai_response(list_response)
|
||||||
|
print(f" Result: Successfully parsed {len(result)} prompts (no AttributeError)")
|
||||||
|
except AttributeError as e:
|
||||||
|
print(f" ERROR: AttributeError occurred: {e}")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f" Other error: {type(e).__name__}: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Test with list containing dictionaries
|
||||||
|
list_with_dicts = json.dumps([
|
||||||
|
{"some_key": "some value"},
|
||||||
|
{"another_key": "another value"}
|
||||||
|
])
|
||||||
|
|
||||||
|
print("\n2. Testing with list of dictionaries:")
|
||||||
|
try:
|
||||||
|
result = generator._parse_ai_response(list_with_dicts)
|
||||||
|
print(f" Result: Successfully parsed {len(result)} prompts (no AttributeError)")
|
||||||
|
except AttributeError as e:
|
||||||
|
print(f" ERROR: AttributeError occurred: {e}")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f" Other error: {type(e).__name__}: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
print("\n✅ AttributeError fix tests passed!")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def test_new_list_format():
|
||||||
|
"""Test the new format where AI returns a list and keys are generated locally."""
|
||||||
|
print("\n=== Test: New list format with locally generated keys ===")
|
||||||
|
|
||||||
|
# Create a mock generator
|
||||||
|
generator = JournalPromptGenerator()
|
||||||
|
|
||||||
|
# Create a mock AI response in the new list format
|
||||||
|
mock_ai_response = [
|
||||||
|
"Write about a childhood memory that still makes you smile.",
|
||||||
|
"Describe your perfect day from start to finish.",
|
||||||
|
"What is something you've been putting off and why?",
|
||||||
|
"Imagine you could have a conversation with any historical figure.",
|
||||||
|
"Write a letter to your future self one year from now.",
|
||||||
|
"Describe a place that feels like home to you."
|
||||||
|
]
|
||||||
|
|
||||||
|
# Convert to JSON string
|
||||||
|
json_response = json.dumps(mock_ai_response)
|
||||||
|
|
||||||
|
print("\n1. Testing _parse_ai_response with list format:")
|
||||||
|
result = generator._parse_ai_response(json_response)
|
||||||
|
print(f" Result type: {type(result)}")
|
||||||
|
print(f" Number of prompts: {len(result)}")
|
||||||
|
print(f" First prompt: {result[0][:50]}...")
|
||||||
|
|
||||||
|
# Verify it's a list of strings
|
||||||
|
assert isinstance(result, list), "Result should be a list"
|
||||||
|
assert all(isinstance(prompt, str) for prompt in result), "All items should be strings"
|
||||||
|
|
||||||
|
print("\n2. Testing add_prompts_to_pool with list of strings:")
|
||||||
|
|
||||||
|
# Get initial pool size
|
||||||
|
initial_pool_size = len(generator.pool_prompts)
|
||||||
|
print(f" Initial pool size: {initial_pool_size}")
|
||||||
|
|
||||||
|
# Add prompts to pool
|
||||||
|
generator.add_prompts_to_pool(result)
|
||||||
|
|
||||||
|
# Check new pool size
|
||||||
|
new_pool_size = len(generator.pool_prompts)
|
||||||
|
print(f" New pool size: {new_pool_size}")
|
||||||
|
print(f" Added {new_pool_size - initial_pool_size} prompts")
|
||||||
|
|
||||||
|
print("\n✅ New list format tests passed!")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def test_valid_json_responses():
|
||||||
|
"""Test with valid JSON responses in various formats."""
|
||||||
|
print("\n=== Test: Valid JSON response handling ===")
|
||||||
|
|
||||||
|
# Create a mock generator
|
||||||
|
generator = JournalPromptGenerator()
|
||||||
|
|
||||||
|
# Create a valid response with 4 prompts as a list (new format)
|
||||||
|
valid_response = [
|
||||||
|
"Write about a time when you felt truly at peace.",
|
||||||
|
"Describe your ideal morning routine in detail.",
|
||||||
|
"What are three things you're grateful for today?",
|
||||||
|
"Reflect on a recent challenge and what you learned from it."
|
||||||
|
]
|
||||||
|
|
||||||
|
# Convert to JSON string
|
||||||
|
json_response = json.dumps(valid_response)
|
||||||
|
|
||||||
|
print("\n1. Testing with valid JSON response (list format):")
|
||||||
|
result = generator._parse_ai_response(json_response)
|
||||||
|
print(f" Number of prompts extracted: {len(result)}")
|
||||||
|
print(f" Type of result: {type(result)}")
|
||||||
|
|
||||||
|
for i, prompt_text in enumerate(result):
|
||||||
|
print(f" Prompt {i+1}: {prompt_text[:50]}...")
|
||||||
|
|
||||||
|
# Test with backticks
|
||||||
|
print("\n2. Testing with valid JSON response with backticks:")
|
||||||
|
backticks_response = f"```json\n{json_response}\n```"
|
||||||
|
result = generator._parse_ai_response(backticks_response)
|
||||||
|
print(f" Number of prompts extracted: {len(result)}")
|
||||||
|
|
||||||
|
# Test with "json" prefix
|
||||||
|
print("\n3. Testing with valid JSON response with 'json' prefix:")
|
||||||
|
json_prefix_response = f"json\n{json_response}"
|
||||||
|
result = generator._parse_ai_response(json_prefix_response)
|
||||||
|
print(f" Number of prompts extracted: {len(result)}")
|
||||||
|
|
||||||
|
# Test fallback for old dictionary format
|
||||||
|
print("\n4. Testing fallback for old dictionary format:")
|
||||||
|
old_format_response = {
|
||||||
|
"newprompt0": "Write about a time when you felt truly at peace.",
|
||||||
|
"newprompt1": "Describe your ideal morning routine in detail.",
|
||||||
|
"newprompt2": "What are three things you're grateful for today?",
|
||||||
|
"newprompt3": "Reflect on a recent challenge and what you learned from it."
|
||||||
|
}
|
||||||
|
json_old_response = json.dumps(old_format_response)
|
||||||
|
result = generator._parse_ai_response(json_old_response)
|
||||||
|
print(f" Number of prompts extracted: {len(result)}")
|
||||||
|
|
||||||
|
print("\n✅ Valid JSON response tests passed!")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def test_clean_ai_response():
|
||||||
|
"""Test the _clean_ai_response method."""
|
||||||
|
print("\n=== Test: _clean_ai_response method ===")
|
||||||
|
|
||||||
|
generator = JournalPromptGenerator()
|
||||||
|
|
||||||
|
# Test cases
|
||||||
|
test_cases = [
|
||||||
|
("```json\n[1, 2, 3]\n```", "[1, 2, 3]"),
|
||||||
|
("```\n[1, 2, 3]\n```", "[1, 2, 3]"),
|
||||||
|
("json\n[1, 2, 3]", "[1, 2, 3]"),
|
||||||
|
("JSON\n[1, 2, 3]", "[1, 2, 3]"),
|
||||||
|
(" [1, 2, 3] ", "[1, 2, 3]"),
|
||||||
|
("```json\n{\"a\": 1}\n```", "{\"a\": 1}"),
|
||||||
|
]
|
||||||
|
|
||||||
|
all_passed = True
|
||||||
|
for i, (input_text, expected) in enumerate(test_cases):
|
||||||
|
cleaned = generator._clean_ai_response(input_text)
|
||||||
|
if cleaned == expected:
|
||||||
|
print(f" Test {i+1} passed: '{input_text[:20]}...' -> '{cleaned}'")
|
||||||
|
else:
|
||||||
|
print(f" Test {i+1} FAILED: '{input_text[:20]}...' -> '{cleaned}' (expected: '{expected}')")
|
||||||
|
all_passed = False
|
||||||
|
|
||||||
|
if all_passed:
|
||||||
|
print("\n✅ _clean_ai_response tests passed!")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("\n❌ _clean_ai_response tests failed!")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Run all parsing tests."""
|
||||||
|
print("=" * 60)
|
||||||
|
print("Running Consolidated Parsing Tests")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
all_passed = True
|
||||||
|
|
||||||
|
# Run all tests
|
||||||
|
if not test_attribute_error_fix():
|
||||||
|
all_passed = False
|
||||||
|
|
||||||
|
if not test_new_list_format():
|
||||||
|
all_passed = False
|
||||||
|
|
||||||
|
if not test_valid_json_responses():
|
||||||
|
all_passed = False
|
||||||
|
|
||||||
|
if not test_clean_ai_response():
|
||||||
|
all_passed = False
|
||||||
|
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
if all_passed:
|
||||||
|
print("✅ ALL PARSING TESTS PASSED!")
|
||||||
|
else:
|
||||||
|
print("❌ SOME TESTS FAILED!")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
return all_passed
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
success = main()
|
||||||
|
sys.exit(0 if success else 1)
|
||||||
|
|
||||||
98
test_prompt_logic.py
Normal file
98
test_prompt_logic.py
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Test script to verify the prompt numbering logic.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
def get_num_prompts():
|
||||||
|
"""Get the number of prompts from settings.cfg or default."""
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
num_prompts = 6 # Default value
|
||||||
|
|
||||||
|
try:
|
||||||
|
config.read('settings.cfg')
|
||||||
|
if 'prompts' in config and 'num_prompts' in config['prompts']:
|
||||||
|
num_prompts = int(config['prompts']['num_prompts'])
|
||||||
|
except (FileNotFoundError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return num_prompts
|
||||||
|
|
||||||
|
def test_renumbering():
|
||||||
|
"""Test the renumbering logic."""
|
||||||
|
|
||||||
|
# Get number of prompts from config
|
||||||
|
num_prompts = get_num_prompts()
|
||||||
|
|
||||||
|
# Create a sample historic prompts list
|
||||||
|
historic_prompts = []
|
||||||
|
for i in range(60):
|
||||||
|
historic_prompts.append({
|
||||||
|
f"prompt{i:02d}": f"Old prompt {i}"
|
||||||
|
})
|
||||||
|
|
||||||
|
print(f"Original prompts: {len(historic_prompts)}")
|
||||||
|
print(f"First prompt key: {list(historic_prompts[0].keys())[0]}")
|
||||||
|
print(f"Last prompt key: {list(historic_prompts[-1].keys())[0]}")
|
||||||
|
print(f"Number of prompts from config: {num_prompts}")
|
||||||
|
|
||||||
|
# Simulate adding new prompts (as the current code would create them)
|
||||||
|
new_prompts = []
|
||||||
|
for i in range(num_prompts):
|
||||||
|
new_prompts.append({
|
||||||
|
f"prompt{len(historic_prompts) + i:02d}": f"New prompt {i}"
|
||||||
|
})
|
||||||
|
|
||||||
|
print(f"\nNew prompts to add: {len(new_prompts)}")
|
||||||
|
for i, prompt in enumerate(new_prompts):
|
||||||
|
print(f" New prompt {i}: {list(prompt.keys())[0]}")
|
||||||
|
|
||||||
|
# Prepend new prompts (reverse to maintain order)
|
||||||
|
for prompt in reversed(new_prompts):
|
||||||
|
historic_prompts.insert(0, prompt)
|
||||||
|
|
||||||
|
print(f"\nAfter prepending: {len(historic_prompts)} prompts")
|
||||||
|
print(f"First 3 prompts keys:")
|
||||||
|
for i in range(3):
|
||||||
|
print(f" {i}: {list(historic_prompts[i].keys())[0]}")
|
||||||
|
|
||||||
|
# Renumber all prompts
|
||||||
|
renumbered_prompts = []
|
||||||
|
for i, prompt_dict in enumerate(historic_prompts):
|
||||||
|
prompt_key = list(prompt_dict.keys())[0]
|
||||||
|
prompt_text = prompt_dict[prompt_key]
|
||||||
|
|
||||||
|
new_prompt_key = f"prompt{i:02d}"
|
||||||
|
renumbered_prompts.append({
|
||||||
|
new_prompt_key: prompt_text
|
||||||
|
})
|
||||||
|
|
||||||
|
print(f"\nAfter renumbering: {len(renumbered_prompts)} prompts")
|
||||||
|
print(f"First 10 prompts keys:")
|
||||||
|
for i in range(10):
|
||||||
|
print(f" prompt{i:02d}: {list(renumbered_prompts[i].keys())[0]} = {renumbered_prompts[i][f'prompt{i:02d}'][:30]}...")
|
||||||
|
|
||||||
|
# Keep only first 60
|
||||||
|
if len(renumbered_prompts) > 60:
|
||||||
|
renumbered_prompts = renumbered_prompts[:60]
|
||||||
|
|
||||||
|
print(f"\nAfter keeping only first 60: {len(renumbered_prompts)} prompts")
|
||||||
|
print(f"First prompt: {list(renumbered_prompts[0].keys())[0]} = {renumbered_prompts[0]['prompt00'][:30]}...")
|
||||||
|
print(f"Last prompt: {list(renumbered_prompts[-1].keys())[0]} = {renumbered_prompts[-1]['prompt59'][:30]}...")
|
||||||
|
|
||||||
|
# Verify the range
|
||||||
|
for i in range(60):
|
||||||
|
expected_key = f"prompt{i:02d}"
|
||||||
|
actual_key = list(renumbered_prompts[i].keys())[0]
|
||||||
|
if expected_key != actual_key:
|
||||||
|
print(f"ERROR: Expected {expected_key}, got {actual_key}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
print("\n✅ All tests passed! Prompt numbering is correct.")
|
||||||
|
return True
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test_renumbering()
|
||||||
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
Test script to verify feedback_words integration
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
# Add the parent directory to the Python path
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
||||||
|
|
||||||
from generate_prompts import JournalPromptGenerator
|
|
||||||
|
|
||||||
def test_feedback_words_loading():
|
|
||||||
"""Test that feedback_words are loaded correctly."""
|
|
||||||
print("Testing feedback_words integration...")
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Initialize the generator
|
|
||||||
generator = JournalPromptGenerator()
|
|
||||||
|
|
||||||
# Check if feedback_words were loaded
|
|
||||||
print(f"Number of feedback words loaded: {len(generator.feedback_words)}")
|
|
||||||
|
|
||||||
if generator.feedback_words:
|
|
||||||
print("Feedback words loaded successfully:")
|
|
||||||
for i, feedback in enumerate(generator.feedback_words):
|
|
||||||
print(f" {i+1}. {feedback}")
|
|
||||||
else:
|
|
||||||
print("No feedback words loaded (this might be expected if file is empty)")
|
|
||||||
|
|
||||||
# Test _prepare_prompt_with_count method
|
|
||||||
print("\nTesting _prepare_prompt_with_count method...")
|
|
||||||
prompt_with_count = generator._prepare_prompt_with_count(3)
|
|
||||||
print(f"Prompt with count length: {len(prompt_with_count)} characters")
|
|
||||||
|
|
||||||
# Check if feedback words are included in the prompt with count
|
|
||||||
if generator.feedback_words and "Feedback words:" in prompt_with_count:
|
|
||||||
print("✓ Feedback words are included in the prompt with count")
|
|
||||||
else:
|
|
||||||
print("✗ Feedback words are NOT included in the prompt with count")
|
|
||||||
|
|
||||||
print("\n✅ All tests passed!")
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"\n❌ Error during testing: {e}")
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
return False
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
success = test_feedback_words_loading()
|
|
||||||
sys.exit(0 if success else 1)
|
|
||||||
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
Test the error handling with a valid response.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
|
|
||||||
# Add the parent directory to the Python path
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
||||||
|
|
||||||
from generate_prompts import JournalPromptGenerator
|
|
||||||
|
|
||||||
def test_valid_response():
|
|
||||||
"""Test with a valid JSON response."""
|
|
||||||
|
|
||||||
# Create a mock generator
|
|
||||||
generator = JournalPromptGenerator(config_path=".env")
|
|
||||||
|
|
||||||
# Create a valid response with 4 prompts as a list (new format)
|
|
||||||
valid_response = [
|
|
||||||
"Write about a time when you felt truly at peace.",
|
|
||||||
"Describe your ideal morning routine in detail.",
|
|
||||||
"What are three things you're grateful for today?",
|
|
||||||
"Reflect on a recent challenge and what you learned from it."
|
|
||||||
]
|
|
||||||
|
|
||||||
# Convert to JSON string
|
|
||||||
json_response = json.dumps(valid_response)
|
|
||||||
|
|
||||||
print("\n=== Test: Valid JSON response (list format) ===")
|
|
||||||
result = generator._parse_ai_response(json_response)
|
|
||||||
print(f"Number of prompts extracted: {len(result)}")
|
|
||||||
print(f"Type of result: {type(result)}")
|
|
||||||
|
|
||||||
for i, prompt_text in enumerate(result):
|
|
||||||
print(f"Prompt {i+1}: {prompt_text[:50]}...")
|
|
||||||
|
|
||||||
# Test with backticks
|
|
||||||
print("\n=== Test: Valid JSON response with backticks ===")
|
|
||||||
backticks_response = f"```json\n{json_response}\n```"
|
|
||||||
result = generator._parse_ai_response(backticks_response)
|
|
||||||
print(f"Number of prompts extracted: {len(result)}")
|
|
||||||
|
|
||||||
# Test with "json" prefix
|
|
||||||
print("\n=== Test: Valid JSON response with 'json' prefix ===")
|
|
||||||
json_prefix_response = f"json\n{json_response}"
|
|
||||||
result = generator._parse_ai_response(json_prefix_response)
|
|
||||||
print(f"Number of prompts extracted: {len(result)}")
|
|
||||||
|
|
||||||
# Test fallback for old dictionary format
|
|
||||||
print("\n=== Test: Fallback for old dictionary format ===")
|
|
||||||
old_format_response = {
|
|
||||||
"newprompt0": "Write about a time when you felt truly at peace.",
|
|
||||||
"newprompt1": "Describe your ideal morning routine in detail.",
|
|
||||||
"newprompt2": "What are three things you're grateful for today?",
|
|
||||||
"newprompt3": "Reflect on a recent challenge and what you learned from it."
|
|
||||||
}
|
|
||||||
json_old_response = json.dumps(old_format_response)
|
|
||||||
result = generator._parse_ai_response(json_old_response)
|
|
||||||
print(f"Number of prompts extracted: {len(result)}")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
test_valid_response()
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user