File size: 1,333 Bytes
a9af6e5
 
 
 
 
 
 
 
 
 
 
 
21edb15
 
 
 
 
a9af6e5
 
 
21edb15
 
 
a9af6e5
 
 
 
 
 
 
 
 
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
from pydantic import BaseModel, Field
from typing import List, Dict, Literal, Optional, Union

class MessageContent(BaseModel):
    type: str = Field(..., description="Content type: 'text' or 'image_url'")
    text: Optional[str] = Field(None, description="Text content")
    image_url: Optional[Dict[str, str]] = Field(None, description="Image URL object with 'url' key")

class ChatMessage(BaseModel):
    role: str = Field(..., description="Role of the message sender (system, user, assistant)")
    content: Union[str, List[MessageContent]] = Field(..., description="Message content - string for simple text or list for mixed content")

# New model to receive language and subject
class PromptSettings(BaseModel):
    language: str = "English"
    subject: str = "General"
    words_limit: int = 100

class ChatRequest(BaseModel):
    messages: List[ChatMessage] = Field(..., description="List of messages in the conversation")
    # This field will now carry the prompt settings from the frontend
    prompt_settings: PromptSettings = Field(default_factory=PromptSettings)
    command: Optional[Literal["search"]] = None

class ChatResponse(BaseModel):
    content: str
    error: Optional[str] = None

class StreamResponse(BaseModel):
    content: Optional[str] = None
    finished: bool = False
    error: Optional[str] = None