Upload 2 files
Browse files- handler.py +39 -0
- requirements.txt +1 -0
handler.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
from ctransformers import AutoModelForCausalLM
|
3 |
+
|
4 |
+
|
5 |
+
class EndpointHandler():
|
6 |
+
def __init__(self, path=""):
|
7 |
+
model_id = "djomo/MISTRALllux1000-7b-v5-GGUF"
|
8 |
+
model_file="mistralllux1000-7b-v5.gguf.q5_k_m.bin"
|
9 |
+
config = {'context_length' : 3048,'max_new_tokens': 856, 'repetition_penalty': 1.1,'temperature': 0.1, 'stream': True}
|
10 |
+
llm = AutoModelForCausalLM.from_pretrained(
|
11 |
+
model_id,
|
12 |
+
model_file=model_file,
|
13 |
+
model_type="mistral",
|
14 |
+
gpu_layers=130,#50 #110
|
15 |
+
**config
|
16 |
+
)
|
17 |
+
self.pipeline = llm
|
18 |
+
|
19 |
+
|
20 |
+
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
21 |
+
"""
|
22 |
+
Args:
|
23 |
+
data (:obj:):
|
24 |
+
includes the input data and the parameters for the inference.
|
25 |
+
Return:
|
26 |
+
A :obj:`list`:. The object returned should be a list of one list like [[{"label": 0.9939950108528137}]] containing :
|
27 |
+
- "label": A string representing what the label/class is. There can be multiple labels.
|
28 |
+
- "score": A score between 0 and 1 describing how confident the model is for this label/class.
|
29 |
+
"""
|
30 |
+
inputs = data.pop("inputs", data)
|
31 |
+
parameters = data.pop("parameters", None)
|
32 |
+
|
33 |
+
# pass inputs with all kwargs in data
|
34 |
+
if parameters is not None:
|
35 |
+
prediction = self.pipeline(inputs, stream=False)
|
36 |
+
else:
|
37 |
+
prediction = self.pipeline(inputs, stream=False)
|
38 |
+
# postprocess the prediction
|
39 |
+
return prediction
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ctransformers==0.2.27
|