42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Any, Self, Sequence
|
|
from Interfaces.Application.AnPInterface import AnPInterface
|
|
from Utils.Checks import Check
|
|
|
|
class AIInterpretersAbstract:
|
|
|
|
def __init__(self:Self, anp:AnPInterface, inputs:str|dict[str, Any|None]|Sequence[Any|None]) -> None:
|
|
|
|
if Check.is_string(inputs):
|
|
inputs = {"url" : inputs.strip()}
|
|
|
|
self.anp:AnPInterface = anp
|
|
self.url:str = self.anp.settings.get(("ai_interpreter_url", "ai_url", "url"), inputs, "")
|
|
self.maximum_tokens_per_session:int = self.anp.settings.get((
|
|
"ai_interpreter_maximum_tokens_per_session", "ai_maximum_tokens_per_session", "maximum_tokens_per_session"
|
|
), inputs, 2048)
|
|
self.sessions:dict[int, list[int]] = {}
|
|
self.sessions_i:int = 0
|
|
|
|
def start(self:Self) -> None:
|
|
pass
|
|
|
|
def close(self:Self) -> None:
|
|
self.sessions = {}
|
|
|
|
def get_session(self:Self, id:int|None = None) -> tuple[int, list[int]]:
|
|
|
|
if id is None or id not in self.sessions:
|
|
id = self.sessions_i
|
|
self.sessions_i += 1
|
|
self.sessions[id] = []
|
|
|
|
return id, self.sessions[id]
|
|
|
|
def close_session(self:Self, id:int) -> bool:
|
|
if id in self.sessions:
|
|
del self.sessions[id]
|
|
return True
|
|
return False |