Download backend/app/conversations/conversation_controller.py from modventures/character-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/spaces/modventures/character-studio/resolve/main/backend/app/conversations/conversation_controller.py
- Command line
-
hf download hf://spaces/modventures/character-studio/backend/app/conversations/conversation_controller.py
-
curl -L -o conversation_controller.py https://huggingface.co/spaces/modventures/character-studio/resolve/main/backend/app/conversations/conversation_controller.py
2.09 kB
| from fastapi import APIRouter, Depends, HTTPException | |
| from sqlalchemy.orm import Session | |
| from app.database import get_session | |
| from app.conversations.conversation_repository import ConversationRepository | |
| from app.conversations.conversation_service import ConversationService | |
| from app.conversations.conversation_schema import ConversationCreate, ConversationRead | |
| from app.conversations.conversation_schema import DraftRequest | |
| from app.characters.character_repository import CharacterRepository | |
| from app.ai.qwen_provider import QwenProvider | |
| from app.config import settings | |
| router = APIRouter(prefix="/conversations", tags=["conversations"]) | |
| def list_records(db: Session = Depends(get_session)): | |
| return ConversationRepository(db).list() | |
| def create(data: ConversationCreate, db: Session = Depends(get_session)): | |
| return ConversationService(ConversationRepository(db)).save(data) | |
| def draft(data: DraftRequest, db: Session = Depends(get_session)): | |
| if not settings.enable_ai_drafts: | |
| raise HTTPException( | |
| 503, "AI dialogue drafting is not functional at the moment for this MVP" | |
| ) | |
| characters = [CharacterRepository(db).get(i) for i in data.character_ids] | |
| if len(set(data.character_ids)) != 2 or any(c.archived for c in characters): | |
| raise HTTPException(422, "Choose two distinct active characters") | |
| profiles = [{"id": c.id, "name": c.name, "profile": c.profile} for c in characters] | |
| return {"turns": QwenProvider().generate(data.topic, profiles), "approved": False} | |
| def get(record_id: str, db: Session = Depends(get_session)): | |
| return ConversationRepository(db).get(record_id) | |
| def update( | |
| record_id: str, data: ConversationCreate, db: Session = Depends(get_session) | |
| ): | |
| return ConversationService(ConversationRepository(db)).save(data, record_id) | |