zemuwen commited on
Commit
088c9cc
·
verified ·
1 Parent(s): 172c1a7

Update handler.py

Browse files
Files changed (1) hide show
  1. 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("text-classification", model=path)
7
 
8
- def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
9
- # 处理输入数据并返回预测结果
10
  inputs = data.get("inputs", "")
11
- prediction = self.pipeline(inputs)
12
- return prediction
 
 
 
 
 
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]}