non-building checkpoint 1

This commit is contained in:
2026-01-03 11:18:56 -07:00
parent 9c64cb0c2f
commit 81ea22eae9
37 changed files with 4804 additions and 275 deletions

15
backend/app/api/v1/api.py Normal file
View File

@@ -0,0 +1,15 @@
"""
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"])

View File

@@ -0,0 +1,131 @@
"""
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)}"
)

View File

@@ -0,0 +1,186 @@
"""
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 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/{prompt_index}")
async def select_prompt(
prompt_index: int,
prompt_service: PromptService = Depends(get_prompt_service)
):
"""
Select a prompt from drawn prompts to add to history.
Args:
prompt_index: Index of the prompt to select (0-based)
Returns:
Confirmation of prompt selection
"""
try:
# This endpoint would need to track drawn prompts in session
# For now, we'll implement a simplified version
raise HTTPException(
status_code=status.HTTP_501_NOT_IMPLEMENTED,
detail="Prompt selection not yet implemented"
)
except HTTPException:
raise
except Exception as e:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Error selecting prompt: {str(e)}"
)