2024-04-07 06:45:43 +00:00
|
|
|
from typing import Any, Optional
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
2024-03-01 06:47:36 +00:00
|
|
|
# make it singleton
|
|
|
|
class NumericIDGenerator:
|
|
|
|
_instance = None
|
|
|
|
|
|
|
|
def __new__(cls):
|
|
|
|
if cls._instance is None:
|
|
|
|
cls._instance = super(NumericIDGenerator, cls).__new__(cls)
|
|
|
|
cls._instance.current_id = 0
|
|
|
|
return cls._instance
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
self.current_id += 1
|
|
|
|
return self.current_id
|
|
|
|
|
|
|
|
|
|
|
|
id_generator = NumericIDGenerator()
|
2024-04-07 06:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ChatMessage(BaseModel):
|
|
|
|
role: str
|
|
|
|
content: Any
|
|
|
|
|
|
|
|
|
|
|
|
class DeltaMessage(BaseModel):
|
|
|
|
role: Optional[str] = None
|
|
|
|
content: Optional[Any] = None
|
|
|
|
|
|
|
|
|
|
|
|
class ChatCompletionResponseStreamChoice(BaseModel):
|
|
|
|
index: int
|
|
|
|
message: DeltaMessage
|