33 lines
982 B
Python
33 lines
982 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, conversation:str) -> None:
|
|
self.conversation:str = conversation
|
|
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) |