mirror of
https://github.com/mcloh/decision-models-benchmark.git
synced 2026-11-05 22:04:12 +00:00
setup models
This commit is contained in:
50
dmb/adapter.py
Normal file
50
dmb/adapter.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Interface comum dos adaptadores JEV locais (tarefas 42–47)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class Adapter(ABC):
|
||||
"""Um candidato servido atrás de POST /v1/systemone.
|
||||
|
||||
`decide` recebe o estado já serializado (texto) e as perguntas no formato JEV e
|
||||
devolve as respostas JEV de cada pergunta, mais o total de tokens de entrada.
|
||||
"""
|
||||
|
||||
name: str
|
||||
adapter_version = "0.1.0"
|
||||
probabilities_source = "native"
|
||||
|
||||
def __init__(self, model_dir: str | Path, revision: str, device: str = "auto",
|
||||
context_limit: int | None = None):
|
||||
self.model_dir = Path(model_dir)
|
||||
self.revision = revision
|
||||
self.device = device
|
||||
self._context_limit = context_limit
|
||||
|
||||
@property
|
||||
def model_id(self) -> str:
|
||||
return f"{self.name}@{self.revision[:12]}"
|
||||
|
||||
@property
|
||||
def context_limit(self) -> int:
|
||||
return self._context_limit or self.native_context_limit()
|
||||
|
||||
@abstractmethod
|
||||
def load(self) -> None: ...
|
||||
|
||||
@abstractmethod
|
||||
def native_context_limit(self) -> int: ...
|
||||
|
||||
@abstractmethod
|
||||
def count_tokens(self, text: str) -> int: ...
|
||||
|
||||
@abstractmethod
|
||||
def decide(self, state: str, questions: dict) -> tuple[dict, int]: ...
|
||||
|
||||
def describe(self) -> dict:
|
||||
return {"name": self.name, "model_id": self.model_id, "revision": self.revision,
|
||||
"adapter_version": self.adapter_version, "device": self.device,
|
||||
"context_limit": self.context_limit,
|
||||
"probabilities_source": self.probabilities_source}
|
||||
Reference in New Issue
Block a user