HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/agenticSeek/llm_server/sources/generator.py
import threading
import logging
from abc import abstractmethod
from .cache import Cache

class GenerationState:
    def __init__(self):
        self.lock = threading.Lock()
        self.last_complete_sentence = ""
        self.current_buffer = ""
        self.is_generating = False
    
    def status(self) -> dict:
        return {
            "sentence": self.current_buffer,
            "is_complete": not self.is_generating,
            "last_complete_sentence": self.last_complete_sentence,
            "is_generating": self.is_generating,
        }

class GeneratorLLM():
    def __init__(self):
        self.model = None
        self.state = GenerationState()
        self.logger = logging.getLogger(__name__)
        handler = logging.StreamHandler()
        handler.setLevel(logging.INFO)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
        self.logger.setLevel(logging.INFO)
        cache = Cache()
    
    def set_model(self, model: str) -> None:
        self.logger.info(f"Model set to {model}")
        self.model = model
    
    def start(self, history: list) -> bool:
        if self.model is None:
            raise Exception("Model not set")
        with self.state.lock:
            if self.state.is_generating:
                return False
            self.state.is_generating = True
            self.logger.info("Starting generation")
            threading.Thread(target=self.generate, args=(history,)).start()
        return True
    
    def get_status(self) -> dict:
        with self.state.lock:
            return self.state.status()

    @abstractmethod
    def generate(self, history: list) -> None:
        """
        Generate text using the model.
        args:
            history: list of strings
        returns:
            None
        """
        pass

if __name__ == "__main__":
    generator = GeneratorLLM()
    generator.get_status()