dlowl commited on
Commit
0fabff5
1 Parent(s): bebe962

Load dolly-v2 model with remote code trusted and full text returned (so it's usable with langchain)

Browse files
Files changed (1) hide show
  1. handler.py +30 -0
handler.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from typing import Dict, Any, List
3
+
4
+ from transformers import pipeline
5
+
6
+
7
+ class EndpointHandler:
8
+ def __init__(
9
+ self,
10
+ path: str,
11
+ ) -> None:
12
+ self.pipeline = pipeline(model=path, torch_dtype=torch.bfloat16, trust_remote_code=True, return_full_text=True)
13
+
14
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
15
+ """
16
+ data args:
17
+ inputs (:obj: `str`)
18
+ Return:
19
+ A :obj:`list` | `dict`: will be serialized and returned
20
+ """
21
+ inputs = data.pop("inputs", data)
22
+ parameters = data.pop("parameters", None)
23
+
24
+ # pass inputs with all kwargs in data
25
+ if parameters is not None:
26
+ prediction = self.pipeline(inputs, **parameters)
27
+ else:
28
+ prediction = self.pipeline(inputs)
29
+ # postprocess the prediction
30
+ return prediction