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 04:39:06 +01:00
parent 6fd7213076
commit af8f99dea3
13 changed files with 550 additions and 167 deletions
-24
View File
@@ -43,7 +43,6 @@ app.add_middleware(
class GenerateCopyRequest(BaseModel):
prompt: str = Field(..., description="The main instruction for generating content")
content_type: Optional[str] = Field(None, description="Type of content to generate")
tone: Optional[str] = Field(None, description="Desired tone of the content")
length: Optional[str] = Field(None, description="Desired length of the content")
include_cta: Optional[bool] = Field(False, description="Whether to include a call to action")
reference_similar_content: Optional[bool] = Field(True, description="Whether to reference similar content")
@@ -88,31 +87,10 @@ async def generate_copy(request: GenerateCopyRequest):
}
)
# Validate tone if provided
if request.tone and request.tone not in config.TONE_OPTIONS:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content={
"status": "error",
"message": f"Invalid tone. Must be one of: {', '.join(config.TONE_OPTIONS)}"
}
)
# Validate length if provided
if request.length and request.length not in config.LENGTH_OPTIONS:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content={
"status": "error",
"message": f"Invalid length. Must be one of: {', '.join(config.LENGTH_OPTIONS)}"
}
)
# Generate copy
result = await copywriter.generate_copy(
prompt=request.prompt,
content_type=request.content_type,
tone=request.tone,
length=request.length,
include_cta=request.include_cta,
reference_similar_content=request.reference_similar_content,
@@ -126,7 +104,6 @@ async def generate_copy(request: GenerateCopyRequest):
if result["content"]:
metadata = {
"content_type": request.content_type,
"tone": request.tone,
"prompt": request.prompt,
"generated": True
}
@@ -139,7 +116,6 @@ async def generate_copy(request: GenerateCopyRequest):
"prompt": request.prompt,
"parameters": {
"content_type": request.content_type,
"tone": request.tone,
"length": request.length,
"include_cta": request.include_cta
},