feat(feedback): Add content improvement feedback system

Frontend (frontend/app.js):

- Add textarea for improvement feedback

- Add submit button with loading state

- Handle API response and display improved content

Backend (backend/copywriter.py):

- Add improve_copy() method using Cohere API

- Integrate retry mechanism for API calls

Backend (backend/main.py):

- Add /improve-content POST endpoint

- Implement error handling and return improved content with metadata

Testing:

- Verified feedback submission flow

- Confirmed improved content generation

- Tested error scenarios and loading states
This commit is contained in:
Michael Ikehi
2025-04-18 19:19:10 +01:00
parent 12e0830ba6
commit 71ad7b4d26
8 changed files with 790 additions and 91 deletions
+20 -12
View File
@@ -382,28 +382,36 @@ async def list_user_queries(
page: int = Query(1, ge=1, description="Page number"),
limit: int = Query(10, ge=1, le=100, description="Items per page")
):
"""Retrieve a list of user queries."""
"""List user queries with pagination."""
try:
# Get all query files
query_files = glob.glob(str(Path(config.DATA_DIR) / "user_queries" / "*.json"))
query_files.sort(reverse=True) # Sort by filename (timestamp) descending
# Calculate offset
offset = (page - 1) * limit
# Get files from user_queries directory
query_dir = Path(config.DATA_DIR) / "user_queries"
query_dir.mkdir(exist_ok=True)
# List all JSON files and sort by name (timestamp) in descending order
files = sorted(query_dir.glob("*.json"), reverse=True)
total = len(files)
# Apply pagination
start_idx = (page - 1) * limit
end_idx = start_idx + limit
page_files = query_files[start_idx:end_idx]
files = files[offset:offset + limit]
items = []
for file_path in page_files:
with open(file_path, 'r') as f:
for file in files:
with open(file, 'r') as f:
query_data = json.load(f)
items.append(query_data)
return {
"items": items,
"total": len(query_files),
"page": page,
"limit": limit
"pagination": {
"total": total,
"page": page,
"limit": limit,
"pages": (total + limit - 1) // limit
}
}
except Exception as e:
logger.error(f"Error listing user queries: {str(e)}")