AnP/Python/Models/AIResponseModel.py

32 lines
919 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Any, Self
from time import time as timestamp
class AIResponseModel:
def __init__(self:Self) -> None:
self.start:float = timestamp()
self.model:str = ""
self.response:str = ""
self.total:str = ""
self.context:str|list[str] = ""
self.done:bool = False
self.end:float|None = None
self.chunks:int = 0
self.ok:bool = False
self.http_code:int = 0
self.http_message:str = ""
def update(self:Self, data:dict[str, Any|None]) -> None:
self.model = data.get("model", self.model)
self.response = data.get("response", "")
self.total += self.response
self.done = data.get("done", self.done)
self.chunks += 1
if self.done:
self.end = timestamp()
self.context = data.get("context", self.context)