first pass async feedback complete, regressions added
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
Feedback-related API endpoints.
|
||||
"""
|
||||
|
||||
from typing import List, Dict
|
||||
from typing import List, Dict, Any
|
||||
from fastapi import APIRouter, HTTPException, Depends, status
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -18,11 +18,90 @@ class GenerateFeedbackWordsResponse(BaseModel):
|
||||
theme_words: List[str]
|
||||
count: int = 6
|
||||
|
||||
class FeedbackQueuedWordsResponse(BaseModel):
|
||||
"""Response model for queued feedback words."""
|
||||
queued_words: List[FeedbackWord]
|
||||
count: int
|
||||
|
||||
class FeedbackActiveWordsResponse(BaseModel):
|
||||
"""Response model for active feedback words."""
|
||||
active_words: List[FeedbackWord]
|
||||
count: int
|
||||
|
||||
class FeedbackHistoricResponse(BaseModel):
|
||||
"""Response model for full feedback history."""
|
||||
feedback_history: List[Dict[str, Any]]
|
||||
count: int
|
||||
|
||||
# Service dependency
|
||||
async def get_prompt_service() -> PromptService:
|
||||
"""Dependency to get PromptService instance."""
|
||||
return PromptService()
|
||||
|
||||
@router.get("/queued", response_model=FeedbackQueuedWordsResponse)
|
||||
async def get_queued_feedback_words(
|
||||
prompt_service: PromptService = Depends(get_prompt_service)
|
||||
):
|
||||
"""
|
||||
Get queued feedback words (positions 0-5) for user weighting.
|
||||
|
||||
Returns:
|
||||
List of queued feedback words with weights
|
||||
"""
|
||||
try:
|
||||
# Get queued feedback words from PromptService
|
||||
queued_feedback_items = await prompt_service.get_feedback_queued_words()
|
||||
|
||||
# Convert to FeedbackWord models
|
||||
queued_words = []
|
||||
for i, item in enumerate(queued_feedback_items):
|
||||
key = list(item.keys())[0]
|
||||
word = item[key]
|
||||
weight = item.get("weight", 3) # Default weight is 3
|
||||
queued_words.append(FeedbackWord(key=key, word=word, weight=weight))
|
||||
|
||||
return FeedbackQueuedWordsResponse(
|
||||
queued_words=queued_words,
|
||||
count=len(queued_words)
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Error getting queued feedback words: {str(e)}"
|
||||
)
|
||||
|
||||
@router.get("/active", response_model=FeedbackActiveWordsResponse)
|
||||
async def get_active_feedback_words(
|
||||
prompt_service: PromptService = Depends(get_prompt_service)
|
||||
):
|
||||
"""
|
||||
Get active feedback words (positions 6-11) for prompt generation.
|
||||
|
||||
Returns:
|
||||
List of active feedback words with weights
|
||||
"""
|
||||
try:
|
||||
# Get active feedback words from PromptService
|
||||
active_feedback_items = await prompt_service.get_feedback_active_words()
|
||||
|
||||
# Convert to FeedbackWord models
|
||||
active_words = []
|
||||
for i, item in enumerate(active_feedback_items):
|
||||
key = list(item.keys())[0]
|
||||
word = item[key]
|
||||
weight = item.get("weight", 3) # Default weight is 3
|
||||
active_words.append(FeedbackWord(key=key, word=word, weight=weight))
|
||||
|
||||
return FeedbackActiveWordsResponse(
|
||||
active_words=active_words,
|
||||
count=len(active_words)
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Error getting active feedback words: {str(e)}"
|
||||
)
|
||||
|
||||
@router.get("/generate", response_model=GenerateFeedbackWordsResponse)
|
||||
async def generate_feedback_words(
|
||||
prompt_service: PromptService = Depends(get_prompt_service)
|
||||
@@ -89,40 +168,23 @@ async def rate_feedback_words(
|
||||
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")
|
||||
@router.get("/history", response_model=FeedbackHistoricResponse)
|
||||
async def get_feedback_history(
|
||||
prompt_service: PromptService = Depends(get_prompt_service)
|
||||
):
|
||||
"""
|
||||
Get feedback word history.
|
||||
Get full feedback word history.
|
||||
|
||||
Returns:
|
||||
List of historic feedback words
|
||||
Full feedback history with weights
|
||||
"""
|
||||
try:
|
||||
# This would need to be implemented in PromptService
|
||||
# For now, return empty list
|
||||
return []
|
||||
feedback_historic = await prompt_service.get_feedback_historic()
|
||||
|
||||
return FeedbackHistoricResponse(
|
||||
feedback_history=feedback_historic,
|
||||
count=len(feedback_historic)
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user