File size: 3,292 Bytes
d57efd6
0743bb0
 
d57efd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9002555
 
 
d57efd6
9002555
 
 
d57efd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9002555
d57efd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9002555
 
d57efd6
 
 
 
 
9002555
 
d57efd6
 
 
 
 
 
 
9002555
d57efd6
 
 
 
0743bb0
 
 
 
 
d57efd6
 
 
0743bb0
 
d57efd6
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from pydantic import BaseModel, Field, field_validator
from typing import List, Optional, Dict, Any
from llama_index.core.llms import MessageRole
from datetime import datetime
import re


class PasswordValidator:
    @staticmethod
    def validate(password: str) -> str:
        if len(password) < 8 or len(password) > 32:
            raise ValueError("Password must be between 8 and 32 characters long")
        if not re.search(r"[A-Z]", password):
            raise ValueError("Password must contain at least one uppercase letter")
        if not re.search(r"[a-z]", password):
            raise ValueError("Password must contain at least one lowercase letter")
        if not re.search(r"\d", password):
            raise ValueError("Password must contain at least one digit")
        if not re.search(r'[!@#$%^&*(),.?":{}|<>]', password):
            raise ValueError("Password must contain at least one special character")
        return password


class CreateUserRequest(BaseModel):
    name: str
    username: str
    email: str
    password: str
    role_id: int = 2

    @field_validator("password")
    def validate_password(cls, password):
        return PasswordValidator.validate(password)


class RoleCreate(BaseModel):
    name: str


class RoleUpdate(BaseModel):
    name: str


class LoginRequest(BaseModel):
    email: str
    password: str


class UserVerification(BaseModel):
    password: str
    new_password: str = Field(min_length=6)

    @field_validator("new_password")
    def validate_new_password(cls, new_password):
        return PasswordValidator.validate(new_password)


class Token(BaseModel):
    access_token: str
    token_type: str


class MetadataRequest(BaseModel):
    title: str
    category_id: int
    author: str
    year: int
    publisher: str


class MetadataResponse(BaseModel):
    id : int
    title: str
    author: str
    category: str  # Changed to reflect the actual category name
    category_id : int
    year: int
    publisher: str
    thumbnail: Optional[Any]  # Make thumbnail optional

    class Config:
        from_attributes = True


class DeleteById(BaseModel):
    id: str


class UserPromptRequest(BaseModel):
    prompt: str
    streaming: bool


class BotMetaCreate(BaseModel):
    metadata_id: List[int]  # List of integers for metadata_id


class BotCreateRequest(BaseModel):
    bot_name: str


class BotResponse(BaseModel):
    role: str = "assistant"
    content: str
    metadata: List
    scores: List


class BotResponseStreaming(BaseModel):
    role: str = "assistant"
    content: Optional[str] = None
    completed_content: Optional[str] = None
    reference: Optional[str] = None
    metadata: Optional[Dict] = None
    score: Optional[float] = None

class TestStreaming(BaseModel):
    role: str = "assistant"
    content: str


class ChatMessage(BaseModel):
    """Chat message."""

    role: MessageRole = MessageRole.ASSISTANT
    content: Optional[Any] = ""
    metadata: Optional[List[Any]] = None
    timestamp : Optional[datetime] = None
    payment: Optional[str] = Field(default=None)

    def __str__(self) -> str:
        return f"{self.role.value}: {self.content}"
    
class ChatHistory(BaseModel):
    messages: List[ChatMessage]
    

class CategoryCreate(BaseModel):
    category_name: str