46 lines
933 B
Python
46 lines
933 B
Python
from __future__ import annotations
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ChatMessage(BaseModel):
|
|
role: Literal["system", "user", "assistant", "tool"]
|
|
content: str
|
|
|
|
|
|
class ChatCompletionsRequest(BaseModel):
|
|
model: str
|
|
messages: list[ChatMessage]
|
|
stream: bool = False
|
|
temperature: float | None = None
|
|
top_p: float | None = None
|
|
|
|
|
|
class ModelData(BaseModel):
|
|
id: str
|
|
name: str | None = None
|
|
object: str = "model"
|
|
created: int = 0
|
|
owned_by: str = "lingma"
|
|
|
|
|
|
class ModelsResponse(BaseModel):
|
|
object: str = "list"
|
|
data: list[ModelData]
|
|
|
|
|
|
class ChatCompletionChoice(BaseModel):
|
|
index: int = 0
|
|
finish_reason: str | None = "stop"
|
|
message: dict = Field(default_factory=dict)
|
|
|
|
|
|
class ChatCompletionResponse(BaseModel):
|
|
id: str
|
|
object: str = "chat.completion"
|
|
created: int
|
|
model: str
|
|
choices: list[ChatCompletionChoice]
|