djomo's picture
Upload 2 files
a454558 verified
raw
history blame
No virus
1.75 kB
from typing import Dict, List, Any
from ctransformers import AutoModelForCausalLM
class EndpointHandler():
def __init__(self, path=""):
model_id = "djomo/MISTRALllux1000-7b-v5-GGUF"
model_file="mistralllux1000-7b-v5.gguf.q5_k_m.bin"
config = {'context_length' : 3048,'max_new_tokens': 856, 'repetition_penalty': 1.1,'temperature': 0.1, 'stream': True}
llm = AutoModelForCausalLM.from_pretrained(
model_id,
model_file=model_file,
model_type="mistral",
gpu_layers=130,#50 #110
**config
)
self.pipeline = llm
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
"""
Args:
data (:obj:):
includes the input data and the parameters for the inference.
Return:
A :obj:`list`:. The object returned should be a list of one list like [[{"label": 0.9939950108528137}]] containing :
- "label": A string representing what the label/class is. There can be multiple labels.
- "score": A score between 0 and 1 describing how confident the model is for this label/class.
"""
inputs = data.pop("inputs", data)
parameters = data.pop("parameters", None)
# pass inputs with all kwargs in data
if parameters is not None:
prediction = self.pipeline(inputs, stream=False)
else:
prediction = self.pipeline(inputs, stream=False)
# postprocess the prediction
return prediction