Skip to content

Template

ChatCompletionChoice

Bases: BaseModel

A single completion choice from the model.

Attributes:

Name Type Description
index int

The index of this choice in the list of choices.

message ChatCompletionMessage

The generated message for this choice.

finish_reason str

The reason why the model stopped generating.

Source code in pita/api/api_template.py
80
81
82
83
84
85
86
87
88
89
90
91
class ChatCompletionChoice(BaseModel):
    """
    A single completion choice from the model.

    Attributes:
        index: The index of this choice in the list of choices.
        message: The generated message for this choice.
        finish_reason: The reason why the model stopped generating.
    """
    index: int
    message: ChatCompletionMessage
    finish_reason: str = Field(..., alias="finish_reason")

ChatCompletionMessage

Bases: BaseModel

A single message in a chat conversation.

Attributes:

Name Type Description
role ChatMessageRole

The role of the message sender (system, user, or assistant).

content str

The text content of the message.

name Optional[str]

Optional name of the message author.

Source code in pita/api/api_template.py
33
34
35
36
37
38
39
40
41
42
43
44
class ChatCompletionMessage(BaseModel):
    """
    A single message in a chat conversation.

    Attributes:
        role: The role of the message sender (system, user, or assistant).
        content: The text content of the message.
        name: Optional name of the message author.
    """
    role: ChatMessageRole
    content: str
    name: Optional[str] = Field(None, alias="name")

ChatCompletionRequest

Bases: BaseModel

Request model for chat completion API endpoint.

This model defines all parameters that can be sent when requesting a chat completion, following the OpenAI-compatible API format.

Attributes:

Name Type Description
model str

Name of the model to use for completion.

messages List[ChatCompletionMessage]

List of messages in chat format (conversation history).

max_tokens Optional[int]

Maximum number of new tokens to generate.

temperature Optional[float]

Sampling temperature. Higher values make output more random.

top_p Optional[float]

Nucleus sampling parameter.

n Optional[int]

Number of completions to generate for each prompt.

stream Optional[bool]

Whether to stream responses incrementally.

stop Optional[List[str]]

List of sequences where the API will stop generating.

presence_penalty Optional[float]

Penalty for tokens based on their presence in the text so far.

frequency_penalty Optional[float]

Penalty for tokens based on their frequency in the text so far.

logit_bias Optional[Dict[str, int]]

Map of token IDs to bias values.

user Optional[str]

Optional unique identifier for the end-user.

Source code in pita/api/api_template.py
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
class ChatCompletionRequest(BaseModel):
    """
    Request model for chat completion API endpoint.

    This model defines all parameters that can be sent when requesting a chat completion,
    following the OpenAI-compatible API format.

    Attributes:
        model: Name of the model to use for completion.
        messages: List of messages in chat format (conversation history).
        max_tokens: Maximum number of new tokens to generate.
        temperature: Sampling temperature. Higher values make output more random.
        top_p: Nucleus sampling parameter.
        n: Number of completions to generate for each prompt.
        stream: Whether to stream responses incrementally.
        stop: List of sequences where the API will stop generating.
        presence_penalty: Penalty for tokens based on their presence in the text so far.
        frequency_penalty: Penalty for tokens based on their frequency in the text so far.
        logit_bias: Map of token IDs to bias values.
        user: Optional unique identifier for the end-user.
    """
    model: str
    messages: List[ChatCompletionMessage]
    max_tokens: Optional[int] = Field(None, alias="max_tokens")
    temperature: Optional[float] = Field(None, alias="temperature")
    top_p: Optional[float] = Field(None, alias="top_p")
    n: Optional[int] = Field(None, alias="n")
    stream: Optional[bool] = Field(None, alias="stream")
    stop: Optional[List[str]] = Field(None, alias="stop")
    presence_penalty: Optional[float] = Field(None, alias="presence_penalty")
    frequency_penalty: Optional[float] = Field(None, alias="frequency_penalty")
    logit_bias: Optional[Dict[str, int]] = Field(None, alias="logit_bias")
    user: Optional[str] = Field(None, alias="user")

ChatCompletionResponse

Bases: BaseModel

Response model for chat completion API endpoint.

This model defines the structure of the response returned by the chat completion endpoint, following the OpenAI-compatible API format.

Attributes:

Name Type Description
id str

Unique identifier for this completion.

object str

Object type (always "chat.completion" for non-streaming).

created int

Unix timestamp of when the completion was created.

model str

The model used for this completion.

choices List[ChatCompletionChoice]

List of completion choices (typically one unless n > 1 in request).

usage Usage

Token usage statistics for this request.

Source code in pita/api/api_template.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class ChatCompletionResponse(BaseModel):
    """
    Response model for chat completion API endpoint.

    This model defines the structure of the response returned by the chat completion endpoint,
    following the OpenAI-compatible API format.

    Attributes:
        id: Unique identifier for this completion.
        object: Object type (always "chat.completion" for non-streaming).
        created: Unix timestamp of when the completion was created.
        model: The model used for this completion.
        choices: List of completion choices (typically one unless n > 1 in request).
        usage: Token usage statistics for this request.
    """
    id: str = Field(..., alias="id")
    object: str = Field(..., alias="object")
    created: int = Field(..., alias="created")
    model: str = Field(..., alias="model")
    choices: List[ChatCompletionChoice]
    usage: Usage

ChatMessageRole

Bases: str, Enum

Enumeration of possible roles for chat messages.

Values

System: System message role for instructions. User: User message role for user inputs. Assistant: Assistant message role for AI responses.

Source code in pita/api/api_template.py
20
21
22
23
24
25
26
27
28
29
30
31
class ChatMessageRole(str, Enum):
    """
    Enumeration of possible roles for chat messages.

    Values:
        System: System message role for instructions.
        User: User message role for user inputs.
        Assistant: Assistant message role for AI responses.
    """
    System = "system"
    User = "user"
    Assistant = "assistant"

Usage

Bases: BaseModel

Token usage statistics for API requests and responses.

Attributes:

Name Type Description
prompt_tokens int

Number of tokens in the prompt/input.

completion_tokens int

Number of tokens in the completion/output.

total_tokens int

Total number of tokens (prompt + completion).

Source code in pita/api/api_template.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Usage(BaseModel):
    """
    Token usage statistics for API requests and responses.

    Attributes:
        prompt_tokens: Number of tokens in the prompt/input.
        completion_tokens: Number of tokens in the completion/output.
        total_tokens: Total number of tokens (prompt + completion).
    """
    prompt_tokens: int
    completion_tokens: int
    total_tokens: int