Update handler.py
Browse files- handler.py +7 -7
handler.py
CHANGED
@@ -2,18 +2,18 @@ from typing import Dict, List, Any
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
class EndpointHandler():
|
5 |
-
|
6 |
-
#
|
7 |
self.pipeline = pipeline("question-answering", model=path)
|
8 |
|
9 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
10 |
-
#
|
11 |
-
|
|
|
12 |
|
13 |
-
#
|
14 |
-
results = self.pipeline(
|
15 |
|
16 |
# 返回模型的响应
|
17 |
return results
|
18 |
|
19 |
-
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
class EndpointHandler():
|
5 |
+
def __init__(self, path="zemuwen/14B_lora_ze"):
|
6 |
+
# 初始化方法,加载问答模型
|
7 |
self.pipeline = pipeline("question-answering", model=path)
|
8 |
|
9 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
10 |
+
# 确保输入数据包含 "question" 和 "context"
|
11 |
+
question = data.get("question", "")
|
12 |
+
context = data.get("context", "")
|
13 |
|
14 |
+
# 使用问答模型生成响应
|
15 |
+
results = self.pipeline(question=question, context=context)
|
16 |
|
17 |
# 返回模型的响应
|
18 |
return results
|
19 |
|
|