Andrew Luo commited on
Commit
345a2f0
1 Parent(s): 4bce99a

custom handler

Browse files
Files changed (2) hide show
  1. handler.py +22 -0
  2. requirements.txt +2 -0
handler.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from InstructorEmbedding import INSTRUCTOR
3
+
4
+ class EndpointHandler():
5
+ def __init__(self, path=""):
6
+ model = INSTRUCTOR('hkunlp/instructor-large')
7
+ self.model = model
8
+
9
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
10
+ """
11
+ data args:
12
+ inputs (:obj: `str`)
13
+ date (:obj: `str`)
14
+ Return:
15
+ A :obj:`list` | `dict`: will be serialized and returned
16
+ """
17
+ # get inputs
18
+ instruction = data.pop("instruction",data)
19
+ text = data.pop("text", data)
20
+
21
+ embeddings = self.model.encode([[instruction,text]])
22
+ return embeddings[0].tolist()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ InstructorEmbedding
2
+ sentence-transformers