t12e commited on
Commit
98c2017
1 Parent(s): 38a6652

add custom handler again

Browse files
Files changed (1) hide show
  1. handler.py +13 -0
handler.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from InstructorEmbedding import INSTRUCTOR
3
+
4
+ class EndpointHandler():
5
+ def __init__(self, path=""):
6
+ self.model = INSTRUCTOR(path)
7
+
8
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
9
+ instruction = data.get("instruction", "")
10
+ document = data.get("document", "")
11
+ embedding = self.model.encode([[instruction, document]]).flatten()
12
+
13
+ return [{"embedding": embedding}]