File size: 1,045 Bytes
b821e25 b7c0a56 b821e25 106ae08 b821e25 106ae08 4911b19 106ae08 4911b19 0997d08 106ae08 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from typing import Dict, List, Any
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
class EndpointHandler():
def __init__(self, path=""):
# Load model directly
model = AutoModelForCausalLM.from_pretrained(
"jdgalvan/Phi-3-mini-128k-instruct",
device_map="cuda",
torch_dtype="auto",
trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained("jdgalvan/Phi-3-mini-128k-instruct")
self.pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
)
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
inputs = data.pop("inputs", data)
parameters = data.pop("parameters", None)
# pass inputs with all kwargs in data
if parameters is not None:
prediction = self.pipe(inputs, **parameters)
else:
prediction = self.pipe(inputs)
return prediction
|