Update handler.py
Browse files- handler.py +11 -6
handler.py
CHANGED
@@ -1,12 +1,17 @@
|
|
1 |
from typing import Dict, List, Any
|
2 |
from transformers import pipeline
|
|
|
3 |
class EndpointHandler():
|
4 |
def __init__(self, path=""):
|
5 |
-
#
|
6 |
-
self.pipeline = pipeline("
|
7 |
|
8 |
-
def __call__(self, data: Dict[str, Any]) ->
|
9 |
-
#
|
10 |
inputs = data.get("inputs", "")
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
1 |
from typing import Dict, List, Any
|
2 |
from transformers import pipeline
|
3 |
+
|
4 |
class EndpointHandler():
|
5 |
def __init__(self, path=""):
|
6 |
+
# 初始化对话模型
|
7 |
+
self.pipeline = pipeline("conversational", model=path)
|
8 |
|
9 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
10 |
+
# 从请求数据中获取输入文本
|
11 |
inputs = data.get("inputs", "")
|
12 |
+
|
13 |
+
# 使用对话模型生成响应
|
14 |
+
conversation = self.pipeline(inputs)
|
15 |
+
|
16 |
+
# 返回模型的响应
|
17 |
+
return {"response": conversation.generated_responses[0]}
|