File size: 2,505 Bytes
676582c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Conversation response schemas."""
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, Field


class MessageResponse(BaseModel):
    """Response schema for a single message."""

    id: int
    role: str = Field(..., description="Role of the message sender (user or assistant)")
    content: str = Field(..., description="Content of the message")
    timestamp: datetime = Field(..., description="When the message was created")
    token_count: Optional[int] = Field(None, description="Estimated token count")

    class Config:
        from_attributes = True


class ConversationSummary(BaseModel):
    """Summary of a conversation for list view."""

    id: int
    title: Optional[str] = Field(None, description="Title of the conversation")
    created_at: datetime = Field(..., description="When the conversation was created")
    updated_at: datetime = Field(..., description="When the conversation was last updated")
    message_count: int = Field(0, description="Number of messages in the conversation")
    last_message_preview: Optional[str] = Field(None, description="Preview of the last message (first 100 chars)")

    class Config:
        from_attributes = True


class ConversationListResponse(BaseModel):
    """Response schema for listing conversations."""

    conversations: List[ConversationSummary]
    total: int = Field(..., description="Total number of conversations")


class ConversationDetail(BaseModel):
    """Detailed conversation information."""

    id: int
    user_id: int
    title: Optional[str] = Field(None, description="Title of the conversation")
    created_at: datetime = Field(..., description="When the conversation was created")
    updated_at: datetime = Field(..., description="When the conversation was last updated")

    class Config:
        from_attributes = True


class MessageListResponse(BaseModel):
    """Response schema for conversation messages."""

    conversation_id: int
    messages: List[MessageResponse]
    total: int = Field(..., description="Total number of messages")


class UpdateConversationRequest(BaseModel):
    """Request schema for updating a conversation."""

    title: str = Field(..., min_length=1, max_length=255, description="New title for the conversation")


class UpdateConversationResponse(BaseModel):
    """Response schema for updating a conversation."""

    id: int
    title: Optional[str]
    updated_at: datetime

    class Config:
        from_attributes = True