File size: 3,088 Bytes
24dcddf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34cd91e
ab6f843
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24dcddf
 
 
 
 
 
 
 
 
34cd91e
 
24dcddf
 
 
 
 
 
 
 
34cd91e
 
24dcddf
 
 
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
from typing import Optional
from pydantic import BaseModel, Field


class ChatBody(BaseModel):
    query: str = Field(..., title="User's query messages")
    history: Optional[list] = Field(None, title="Chat history")
    language: Optional[str] = Field("en", title="Language")
    topic: Optional[str] = Field("education", title="Topic")

    model_config = {
        "json_schema_extra": {
            "example": {
                "query": "Hệ thống có những tính năng gì",
                "history": [
                    {"content": "Bạn là ai vậy", "type": "human"},
                    {
                        "content": "Tôi là AI hỗ trợ cho hệ thống LearnMigo",
                        "type": "ai",
                    },
                ],
                "language": "Vietnamese",
                "topic": "education",
            }
        }
    }


class PrimaryChatBody(ChatBody):
    pass


class TutorChatBody(ChatBody):
    filter: Optional[dict] = Field(None, title="Filter")
    model_config = {
        "json_schema_extra": {
            "example": {
                "query": "Vai trò của tri thức lịch sử là gì",
                "history": [
                    {"content": "Môn này là gì", "type": "human"},
                    {
                        "content": "Lịch sử về Châu Á",
                        "type": "ai",
                    },
                ],
                "language": "Vietnamese",
                "topic": "education",
                "filter": {"lesson_id": "L01"},
            }
        }
    }


class HighlightExplainBody(BaseModel):
    domain: str = Field(..., title="Domain")
    question: str = Field(..., title="User's query messages")
    highlight_terms: str = Field(..., title="Highlight terms")
    before_highlight_paragraph: str = Field(..., title="Before highlight paragraph")
    after_highlight_paragraph: str = Field(..., title="After highlight paragraph")
    language: str = Field("Vietnamese", title="Language")
    model_config = {
        "json_schema_extra": {
            "example": {
                "language": "Vietnamese",
                "domain": "Machine Learning",
                "question": "What does overfitting mean and why is it a problem?",
                "highlight_terms": "overfitting",
                "before_highlight_paragraph": "Overfitting happens when a machine learning model performs well on the training data but poorly on unseen data. This is because the model has learned not just the underlying patterns but also the noise in the training dataset. In contrast, a well-generalized model captures patterns that apply to new data as well.",
                "after_highlight_paragraph": "Overfitting happens when a machine learning model performs well on the training data but poorly on unseen data. This is because the model has learned not just the underlying patterns but also the noise in the training dataset. In contrast, a well-generalized model captures patterns that apply to new data as well.",
            }
        }
    }